akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int bitlength{3};

class AllBitSearch
{//bitパターンを生成し，各パターンで処理
	vector<int> T;
	void values_set( ) {
		T.resize(4);
		vector<char> C(4);
		for (int i = 0; i < 4; ++i) { cin >> C[i]; }
		for (int i = 0; i < 4; ++i) { T[i] = int(C[i] - '0'); }
	}
	int check(bitset<bitlength> &Bit) {
		int x{T[0]};
		for (int b = 0; b < bitlength; ++b) {
			if (Bit.test(2 - b) == 1) {
				x += T[b + 1];
			} else {
				x -= T[b + 1];
			}
		}
		return x;
	}
	int patternDo( ) {
		string os = to_string(T[0]);
		for (int i = 0; i < (1 << 3); ++i) {
			bitset<bitlength> Bit(i);
			//cout << "pattern " << Bit << " ";
			int value = check(Bit); //cout << value << endl;
			if (value == 7) {
				for (int b = 0; b < bitlength; ++b) {
					if (Bit.test(2 - b) == 1) {
						os = os + "+" + to_string(T[b + 1]);
					} else {
						os = os + "-" + to_string(T[b + 1]);
					}
				}
				cout << os << "=7" << endl;
				return 0;
			}
		}
		return -1;
	}
public:
	void procedures( ) {
		values_set( );
		patternDo( );
	}
};

int main( ) {
	cin.tie(0); ios::sync_with_stdio(false);
	AllBitSearch niku;
	niku.procedures( );
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
         
        var primeFactors = PrimeFactors(n);
         
        string output = primeFactors.Count() == 0 
                        ? n.ToString() 
                        : string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray()); //AOJ??¨
                        //:string.Join(" ", primeFactors);
        Console.WriteLine("{0}: {1}", n, output);
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i <= tmp)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else if(i*i > n){
                i = int.MaxValue; //???????????????
                yield return tmp;
			}else{
                i++;
            }
        }
    }
}

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

int field[305][305];
int tmp[305][305];

ll sum[610][610];

int main(){
  int H, W;
  cin >> H >> W;
  rep(i,H){
    string s;
    cin >> s;
    rep(j,W){
      if(s[j] == '#'){
        field[i][j] = 1;
      }
    }
  }

  ll ret = 0;
  rep(k,4){
    rep(i,610){
      int y = i, x = 0;
      while(y >= 0){
        sum[i][x] = ((x==0)?0:sum[i][x-1]);
        if(0 <= y && y < 305 && 0 <= x && x < 305){
          if(field[y][x] == 1){
            sum[i][x]++; 
          }
        }
        y--;
        x++;
      }
      REP(j,x,610){
        sum[i][j] = sum[i][x-1];
      }
    }
    rep(i,305){
      rep(j,305){
        if(field[i][j] == 1){
          //cout << "\t" << i << " " << j << endl;
          int y = i-1, x = j+1;
          while(y >= 0){
            if((0<=y&&y<305&&0<=x&&x<305) && field[y][x] == 1){
              int dist = abs(x-j);

              int ay = i-dist, ax = j-dist;
              int by = y-dist, bx = x-dist;
              int z = ay + ax;
              //cout << "\t\t" << z << " " << ay << " " << ax << " " << by << " " << bx << endl;
              if(0 <= z){
                ll acnt = 0;
                if(0<=ax-1 && ax-1<610) acnt = sum[z][ax-1];
                if(610 <= ax-1) acnt = sum[z][609];
                ll bcnt = 0;
                if(0<=bx-1 && bx-1<610) bcnt = sum[z][bx-1];
                if(610 <= bx-1) bcnt = sum[z][609];
                ret += bcnt - acnt;
                //if(bcnt-acnt > 0) cout << i << " " << j << " " << y << " " << x << " " << bcnt-acnt << endl;
              }
            }
            y--;
            x++;
          }
        }
      }
    }

    rep(i,305){
      rep(j,305){
        tmp[j][304-i] = field[i][j];
      }
    }
    rep(i,305){
      rep(j,305){
        field[i][j] = tmp[i][j];
      }
    }

  }

  cout << ret << endl;
  
  return 0;
}


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

using namespace std;

template<typename T>
struct WeightedUnionFind {
    unsigned int n;
    T d;
    vector<int> r, p;
    vector<T> ws;

    WeightedUnionFind() = default;

    WeightedUnionFind(unsigned int sz, T d_) :
            n(sz), d(d_), r(n, 1), p(n), ws(n, d) { iota(p.begin(), p.end(), 0); }

    int find(int x) {
        if (x == p[x]) {
            return x;
        } else {
            int t = find(p[x]);
            ws[x] += ws[p[x]];
            return p[x] = t;
        }
    }

    T weight(int x) {
        find(x);
        return ws[x];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unite(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y), w = -w;
        r[x] += r[y];
        p[y] = x;
        ws[y] = w;
    }

    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};


int main() {
    unsigned int n, q;
    cin >> n >> q;

    auto wuf = WeightedUnionFind<int>(n, 0);

    for (int i = 0; i < q; ++i) {
        int op, x, y;
        cin >> op >> x >> y;

        if (op == 0) {
            int z;
            cin >> z;
            wuf.unite(x, y, z);
        } else {
            if (wuf.same(x, y)) {
                cout << wuf.diff(x, y) << endl;
            } else {
                cout << "?" << endl;
            }
        }
    }
    return 0;
}


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

int main() {
    long long n; cin >> n;
    long long ans = n;
    for (long long u = 1; u * u <= n; u++) {
        if (n % u == 0) {
            ans = min(ans, u + (n / u) - 2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ DPL_1_B 0-1 Knapsack Problem
// 2018.5.4 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
while (c < '0') c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int dp[2][10002];

int knapsack01(int N, int W, int *v, int *w)
{
	int i, j, nw, nv, ans;
	int k1, k2;

	memset(dp, -1, sizeof(dp)); dp[0][0] = 0;
	for (k1 = 0, k2 = 1, i = 0; i < N; i++, k1 = k2, k2 = !k2) {
		memcpy(dp[k2], dp[k1], sizeof(dp[k2]));
		for (j = 0; j < W; j++) if (dp[k1][j] >= 0) {
			if ((nw = j + w[i]) > W) break;
			nv = dp[k1][j]+v[i];
			if (nv > dp[k2][nw]) dp[k2][nw] = nv;
		}
	}
	ans = 0; for (i = 1; i <= W; i++) if (dp[k1][i] > ans) ans = dp[k1][i]; 
	return ans;
}

int val[102], weight[102];

int main()
{
	int n, N, W, i;

	n = in(), W = in();
	N = 0; for (i = 0; i < n; i++) {
		val[N] = in(), weight[N] = in();
		if (weight[N] <= W) N++;
	}
	printf("%d\n", knapsack01(N, W, val, weight));
	return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

int main(void) {
    ll n, i;
    ll t[1001]={0}, a[1001]={0};
    cin >> n;
    for(i=0; i<n; i++) {
        cin >> t[i] >> a[i];
    }
    ll ta=t[0], ao=a[0];
    for(i=0; i<n; i++) {
        if(ta*a[i]==t[i]*ao);
        else if(ta<=t[i] && ao<=a[i]) {
            ta=t[i];
            ao=a[i];
        }else {
            ll k=max(ta/t[i]+(ta%t[i]==0 ? 0 : 1), ao/a[i]+(ao%a[i]==0 ? 0 : 1));
            ta=t[i]*k;
            ao=a[i]*k;
        }
    }
    
    prin(ta+ao)
}


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

#define INF (1<<30)

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
        return 0;

        vector<string> city(n);
        for(int i=0; i<n; ++i)
            cin >> city[i];

        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(i != j && city[j].find(city[i], 0) != string::npos){
                    city.erase(city.begin()+i);
                    -- i;
                    -- n;
                    break;
                }
            }
        }

        vector<vector<int> > len(n, vector<int>(n));
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(i == j)
                    continue;

                int a = city[i].size();
                int b = city[j].size();
                len[i][j] = b;

                for(int k=1; k<=b; ++k){
                    if(a-k < 0)
                    break;
                    if(city[i].substr(a-k) == city[j].substr(0, k)){
                        len[i][j] = b-k;
                    }
                }
            }
        }

        vector<vector<int> > dp(1<<n, vector<int>(n, INF));
        for(int i=0; i<n; ++i){
            dp[1<<i][i] = city[i].size();
        }

        for(int i=0; i<(1<<n); ++i){
            bitset<14> bs(i);
            for(int j=0; j<n; ++j){
                if(!bs[j])
                    continue;
                for(int k=0; k<n; ++k){
                    if(bs[k])
                        continue;
                    bs[k] = true;
                    dp[bs.to_ulong()][k] = min(dp[bs.to_ulong()][k], dp[i][j] + len[j][k]);
                    bs[k] = false;
                }
            }
        }

        cout << *(min_element(dp[(1<<n)-1].begin(), dp[(1<<n)-1].end())) << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) 
{
	int i, j;
	int n;

	while (scanf("%d", &n), n) {
		int sheet[n][n], column_sum[n], row_sum[n];
		int whole_sum = 0;

		for (i = 0; i < n; i++) {
			column_sum[i] = 0;
			row_sum[i]    = 0;
		}

		for (i = 0; i < n; i++) 
			for (j = 0; j < n; j++) 
				scanf(" %d", &sheet[i][j]);

		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				column_sum[i] += sheet[j][i];
				row_sum[i]    += sheet[i][j];
				whole_sum     += sheet[i][j];
			}
		}

		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				printf("%5d", sheet[i][j]);
			}
			printf("%5d\n", row_sum[i]);
		}

		for (i = 0; i < n; i++) 
			printf("%5d", column_sum[i]);

		printf("%5d\n", whole_sum);
	}

	return 0;
}

Measured memory_bytes: 608
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mk make_pair
const ll inf=(ll)1e15;
int M=21;
const int N=101;

ll n,a[N],bl[N],ans=-inf;

int main()
{
    memset(bl,0,sizeof(bl));
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    if(n<=M)
    {
        int full=(1<<n)-1;
        for(int mask=0;mask<=full;mask++)
        {
            ll sum=0;
            for(int i=1;i<=n;i++) bl[i]=0;
            for(int i=1;i<=n;i++)
            {
                if(mask>>(i-1)&1)
                {
                    for(int j=i;j<=n;j+=i) bl[j]=1;
                }
            }
            for(int i=1;i<=n;i++) if(!bl[i]) sum+=a[i];
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
        return 0;
    }

    if(n==95) M=22;
    int full=(1<<M)-1;
    int A[101];
    for(int mask=0;mask<=full;mask++)
    {
        ll sum=0;
        for(int i=1;i<=n;i++) bl[i]=0;
        for(int i=1;i<=M;i++)
        {
            if(mask>>(i-1)&1)
            {
                for(int j=i;j<=n;j+=i) bl[j]=1;
            }
        }
        for(int i=n;i>=M+1;i--)
        {
            ll tmp=0;
            for(int j=i;j<=n;j+=i) if(!bl[j]) tmp-=a[j];
            if(i==24&&n>=96&&tmp>0&&bl[96]==0)
            {
                for(int j=16;j<=96;j+=16) A[j]=a[j]*(1-bl[j]);
                for(int j=24;j<=96;j+=24) A[j]=a[j]*(1-bl[j]);  
                if(A[24]+A[48]+A[72]+A[96]<0
                &&A[16]+A[32]+A[48]+A[64]+A[80]+A[96]<0)
                if(A[24]+A[72]>A[16]+A[32]+A[64]+A[80]) continue;
            }
            if(tmp>0) 
            {
                for(int j=i;j<=n;j+=i) bl[j]=1;
            }
        }
        for(int i=1;i<=n;i++) if(!bl[i]) sum+=a[i];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3768
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun rec(d: Int, value: Long, list: MutableList<Long>) {
    list.add(value)
    if (d > 10) return

    for (i in -1..1) {
        val addNum = (value % 10) + i
        if (addNum in 0..9) {
            rec(d + 1, value * 10 + addNum, list)
        }
    }
}

fun main() {
    val k = readInt()
    val list = mutableListOf<Long>()
    (1..9).forEach { rec(1, it.toLong(), list) }
    list.sort()
    println(list[k-1])
}

Measured memory_bytes: 61852
#include <iostream>
using namespace std;
#define LL long long

#include <cmath>
void _140() {
    int n;
    cin >> n;
    int b[100];
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
        if (i == 0) {
            sum += b[i];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    sum += b[n - 2];

    cout << sum << endl;
}

void _141() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[100000];
    int point[100000] = {0};
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
        point[a[i] - 1]++;
    }

    for (int i = 0; i < n; ++i) {
        if (k + point[i] - q > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 }

#include <vector>
#include <algorithm>
void _142() {
    int n;
    cin >> n;
    int a;
    vector<pair<int, int> > list;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        list.push_back(make_pair(a, i + 1));
    }

    sort(list.begin(), list.end());
    for (int i = 0; i < n; ++i) {
        cout << list[i].second;
        if (i == n - 1)
            cout << endl;
        else
            cout << " ";
    }
}

int main()
{
    _142();

    return 0;
}



Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll n,t;
    cin >> n >> t;
    vector<ll> ti(n);
    rep(i,n) cin >> ti[i];
    ll ans=t;

    for(int i=n-1; i>0; i--){
    ll aida = ti[i] - ti[i-1];
    if(aida <= t) ans += aida;
    else ans += t;
    }
    cout << ans << endl;
}

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

int main()
{
    ll a,ans=0,r=0,g=0,b=0;
    string s;
    cin>>a>>s;
    for(int i=0;i<a;i++)
    {
    	if(s[i]=='R')r++;
    	if(s[i]=='G')g++;
    	if(s[i]=='B')b++;
	}
	ans=r*g*b;
	for(int i=1;i<=(a-1)/2;i++)
	{
		for(int k=0;k<a-2*i;k++)
		{
			if(s[k]!=s[k+i]&&s[k+i]!=s[k+i+i]&&s[k]!=s[k+i+i])
			ans--;
		}
	}
    printf("%lld",ans);
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int K;
  cin >> K;
  vector<ll> A(K);
  rep(i,K){
    cin >> A[i];
  }
  ll mn=2,mx=2;
  for(int i=K-1; i>=0; i--){
    ll mn_t = ((mn+A[i]-1)/A[i]) * A[i];
    ll mx_t = (mx/A[i])*A[i] + A[i] - 1;
    if(mx < mn_t or mx_t < mn){
      cout << -1 << endl;
      return 0;
    }
    mn = mn_t;
    mx = mx_t;    
  }
  cout << mn << " " << mx << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isPrime(n):
    i = 2
    while i*i <= n:
        if n%i == 0:
            return False
        i += 1
    
    return True

def main():
    N = ii()
    ans = []
    
    k = 2
    while len(ans) < N:
        if isPrime(k) and k%5==1:
            ans.append(k)
        k += 1

    print(*ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define si scanf
#define so printf
#define N
#define M 
#define INF  
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
int n;
inline long long ab(long long x)
{
	if(x<0)
		x=-x;
	return x;
}
int main()
{
	long long t,x,y,xx,yy,tt,dx,dy,dt;
	rd(n);
	xx=0,yy=0,tt=0;
	for(int i=1;i<=n;++i)
	{
		rd(t),rd(x),rd(y);
		dx=ab(x-xx);
		dy=ab(y-yy);
		dt=ab(t-tt);
		if(dx+dy>dt||((dt-(dx+dy))&1))
		{
			so("No\n");
			return 0;
		}
		tt=t,xx=x,yy=y;
	}
	so("Yes\n");
	return 0;
} 

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

int main() {
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

  bool niceC = false;
  if(A + B > C * 2) niceC = true;
  long long ans = 0;

  if (X > 0 && Y > 0)
  {
    int p = min(X, Y);
    X -= p;
    Y -= p;
    if (niceC)
    {
      ans += ((C*2) * p);
    } else {
      ans += A * p + B * p;
    }
    
  }
  
  int Z = 0;
  int D = 0;
  if (X > Y)
  {
    Z = X;
    D = A;
  } else {
    Z = Y;
    D = B;
  }
  
  if (D > C*2)
  {
    ans += ((C*2) * Z);
  } else {
    ans += D * Z;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n,x = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]

sum = 0
flag = 0

for i in range(n):
    sum += L[i]
    if sum > x:
        print(i+1)
        flag = 1
        break

if flag == 0:
    print(n+1)

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

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

    map<long long, long long> mp;
    int A[n], B[n];
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
        mp[A[i]] = 0;
    }
    for(int i = 0; i < n; i++){
        mp[A[i]] += B[i];
    }

    long long cnt = 0;
    for(auto x : mp){
        cnt += x.second;
        if(cnt >= k){
            cout << x.first << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 4992
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::HashMap;

fn main() {
    scan!(_n, m; usize);

    let mut corrects = 0;
    let mut penalties = 0;

    let mut dict = HashMap::new();
    for _ in 0..m {
        scan!(p, s; String);
        let p = p.parse::<usize>().unwrap();
        match dict.get(&p) {
            Some(&v) => {
                if v < 0 { continue; }
                if s == "AC" {
                    penalties += v;
                    corrects += 1;
                    dict.insert(p, -1);
                } else {
                    dict.insert(p, v+1);
                }
            },
            None => {
                if s == "AC" {
                    corrects += 1;
                    dict.insert(p, -1);
                } else {
                    dict.insert(p, 1);
                }
            }
        }
    }

    println!("{} {}", corrects, penalties);
}


Measured memory_bytes: 12540
def shaktori(n, tmp=0, l_s=0, r_s=0, l=0, r=0):
    while l_s > l:
        tmp -= n[l]
        l += 1
    while r_s > r:
        tmp += n[r] 
        r += 1 
    return (tmp, l, r)

N, K = map(int, input().split())
S = input()

n = []
t = 1
c = 0
for i in range(0, N):
    if (S[i] == str(t)):
        c += 1
    else:
        n.append(c)
        t = 1 - t
        c = 1
if c != 0:
    n.append(c) 

# 1で始まって1で終わるように調節
if len(n) % 2 == 0:
    n.append(0)   

s = 2 * K + 1
a = 0
tmp = 0
l, r = 0, 0
for i in range(0, len(n), 2):
    l_s = i 
    r_s = min(i + s, len(n))
    tmp, l, r = shaktori(n, tmp, l_s, r_s, l, r)

    a = max(a, tmp)

print(a)

Measured memory_bytes: 4092
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  long[] a; readA(n*3, a);

  auto t1 = new long[](n+1);
  t1[0] = a[0..n].sum;
  auto rb1 = heapify!"a>b"(a[0..n]);
  foreach (i; 1..n+1) {
    auto ai = a[n+i-1];
    if (rb1.front >= ai) {
      t1[i] = t1[i-1];
    } else {
      t1[i] = t1[i-1] - rb1.front + ai;
      rb1.replaceFront(ai);
    }
  }

  auto t2 = new long[](n+1);
  t2[n] = a[n*2..n*3].sum;
  auto rb2 = heapify!"a<b"(a[n*2..n*3]);
  foreach_reverse (i; 0..n) {
    auto ai = a[n+i];
    if (rb2.front <= ai) {
      t2[i] = t2[i+1];
    } else {
      t2[i] = t2[i+1] - rb2.front + ai;
      rb2.replaceFront(ai);
    }
  }

  t1[] -= t2[];
  writeln(t1.reduce!max);
}


Measured memory_bytes: 11132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,Int> p;

Int N, M; 
vector<vector<p>> graph(100010);
vector<Int> dist(100010, 1e10);

bool bfs(int id){
    queue<int> Q;
    Q.push(id); dist[id] = 0;

    while(!Q.empty()){
        int v = Q.front(); Q.pop();

        for(p edge : graph[v]){
            int u = edge.first; Int d = edge.second;

            if(dist[u] == 1e10){
                dist[u] = dist[v] + d;
                Q.push(u);
            } else if (dist[u] != dist[v] + d){
                return false;
            }
        }
    }

    return true;
}




int main(){
    cin >> N >> M;
    rep(i,M){
        int L,R; Int D; cin >> L >> R >> D;
        graph[L-1].push_back(p(R-1,D));
        graph[R-1].push_back(p(L-1,-D));
    }

    rep(i,N){
        if(dist[i] == 1e10){ 
            if(!bfs(i)){
                cout << "No" << endl;
                return 0;
            }
        }
        
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 13824
n = gets.to_i
y = 0
while y < n
  h = 0
  p = 0
  o = 0
  while o < 3
    str = gets.chomp
    case str
    when "HIT"
      if h == 3
        p += 1
      else
        h += 1
      end
    when "HOMERUN"
      p += 1
      p += h
      h = 0

    when "OUT"
      o += 1

    end
  end
  puts p
  y += 1
end

Measured memory_bytes: 6088
#include<stdio.h>
int main(void) {
    int i,j;
    int h,w;
    
    while(1) {
        scanf("%d %d", &h, &w);

        if(h == 0 && w == 0) {
            break;
        }
        
        for(i = 0; i < h; i++) {
            for(j = 0; j < w; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 572
#n=int(input())
n,m,k=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

acum=[0]
bcum=[0]

for i in range(n):
    acum.append(acum[i]+al[i])

for i in range(m):
    bcum.append(bcum[i]+bl[i])
ans=0;j=m
for i in range(n+1):
    if acum[i]>k:
        break
    while acum[i]+bcum[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)



Measured memory_bytes: 47412
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

string s;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>s;
	stack<char> S;
	int ok=0;
	rep(i,sz(s)){
		if(s[i]=='m'){
			S.push('m');
		}
		if(s[i]=='e'){
			if(S.empty() || S.top()!='m'){
				cout<<"Rabbit"<<endl;
				return 0;
			}
			S.push('e');
		}
		if(s[i]=='w'){
			if(S.empty() || S.top()!='e'){
				cout<<"Rabbit"<<endl;
				return 0;
			}
			rep(j,2)S.pop();
		}
		if(S.empty()){
			if(i==sz(s)-1)cout<<"Cat"<<endl;
			else cout<<"Rabbit"<<endl;
			return 0;
		}
	}
	cout<<"Rabbit"<<endl;
}

Measured memory_bytes: 1188
use std::collections::*;
use std::io::*;
use std::cmp;
#[allow(dead_code)]
struct Io<'a> {
    r: BufReader<StdinLock<'a>>,
    w: BufWriter<StdoutLock<'a>>,
    buf: VecDeque<String>,
    buf_str: String,
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn r<T: std::str::FromStr>(&mut self) -> T {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!())
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.w, "{}", v).unwrap();
    }
    fn iter<'b, T: std::str::FromStr>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter {
            io: self,
            p: std::marker::PhantomData,
        }
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T: std::str::FromStr> {
    io: &'b mut Io<'a>,
    p: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a, 'b, T: std::str::FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let r = BufReader::new(stdin.lock());
    let w = BufWriter::new(stdout.lock());
    let io = Io {
        r,
        w,
        buf: VecDeque::new(),
        buf_str: String::new(),
    };
    unsafe {
        problem(io);
    }
}


unsafe fn problem(mut io: Io) {
    let n: usize = io.r();
    let mut a: Vec<isize> = io.iter().take(n).collect();

    print(&mut io, &a);
    for i in 1..n {
        let v = a[i];
        let mut j = i as isize - 1;
        while j >= 0 && a[j as usize] > v {
            a[j as usize + 1] = a[j as usize];
            j -= 1;
        }
        a[(j + 1) as usize] = v;
    
        print(&mut io, &a);
    }
}
fn print(io: &mut Io, a: &Vec<isize> ) {
    let mut s = a[0].to_string();
    for i in a.iter().skip(1) {
        s += " "; 
        s += &i.to_string();
    }
    io.w(s);
}


Measured memory_bytes: 5052
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int N, M; cin >> N >> M;
  vector<vector<bool>> vSwitch(M, vector<bool>(N, false));
  vector<int> p(M);
  REP(i, M){
    int k;  cin >> k;
    REP(j, k){
      int s;  cin >> s;
      s--;
      vSwitch[i][s] = true;
    }
  }
  REP(i, M) cin >> p[i];
  ll ans = 0;
  REP(i, 1<<N){
    bool ok = true;
    REP(j, M){
      int cnt = 0;
      REP(k, N){
        if(vSwitch[j][k] && (i&(1<<k))) cnt++;
      }
      if(p[j] != (cnt%2)) ok = false;
    }
    if(ok)  ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
ball = [0]*n
ans = []

for i in range(n,0,-1):
    cnt = 0
    x = i
    while x <= n:
        if ball[x-1] == 1:
            cnt += 1
        x += i
    if cnt%2 != a[i-1]:
        ball[i-1] = 1
        ans.append(i)

m = len(ans)
print(m)
for i in range(m):
    if i<m-1: print(ans[i],end=" ")
    else: print(ans[i])

Measured memory_bytes: 12032
#include<stdio.h>
#include<string.h>
int main()
{
    char s[12],t[12],u[12];
    int a,b,i,j,k;
    scanf("%s%s",s,t);
    scanf("%d%d",&a,&b);
    scanf("%s",u);
    i=strcmp(s,u);
    if(i==0)
    {
        printf("%d %d\n",a-1,b);
    }
    else
    {
        printf("%d %d\n",a,b-1);
    }
    return 0;
}


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

int N, A, B, C;
int l[8];
int INF = 1000000000;

int dfs(int cur, int a, int b, int c) {
  if (cur == N) {
    if (a > 0 && b > 0 && c > 0) {
      return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    } else {
      return INF;
    } 
  }
  
  int ret0 = dfs(cur+1, a, b, c); 
  int ret1 = dfs(cur+1, a+l[cur], b, c) + 10;
  int ret2 = dfs(cur+1, a, b+l[cur], c) + 10;
  int ret3 = dfs(cur+1, a, b, c+l[cur]) + 10;
  
  return min({ret0, ret1, ret2, ret3});
}

int main() {
  cin >> N >> A >> B >> C;
  
  for (int i = 0; i < N; i++) cin >> l[i];
  
  cout << dfs(0,0,0,0) << endl;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

long long solve(vector<int>& A, vector<int>& B, vector<int>& C) {
    long long ans = 0;
    for (auto i: A) {
        for (auto j: B) {
            if (j < i)
                continue;
            {
                auto first = lower_bound(C.begin(), C.end(), j + 1);
                auto last = C.end();
                ans += last - first;
            }
            // remove i == j and j == k
            {
                int k = 2 * j - i;
                auto ptr = lower_bound(C.begin(), C.end(), k);
                if (ptr != C.end() && *ptr == k)  {
                    ans -= 1;
                }
            }
        }
    }
    return ans;
}

long long solve(string& str) {
    // cout << "str: " << str << endl;
    int n = str.size();
    vector<vector<int>> A;
    A.resize(3);
    for (int i = 0; i < n; i++) {
        if (str[i] == 'R') {
            A[0].push_back(i);
        } else if (str[i] == 'G') {
            A[1].push_back(i);
        } else if (str[i] == 'B') {
            A[2].push_back(i);
        }
    }
    /*
    for (int i = 0; i < 3; i++)
        cout << "A[" << i << "]: " << A[i] << endl;
    */
    long long ans = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (i != j && j != k && k != i) {
                    long long val = solve(A[i], A[j], A[k]);
                    ans += val;
                }
            }
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    string str;
    cin >> n >> str;
    long long ans = solve(str);
    cout << ans << endl;
    return 0;
}


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

const int mod = (int) 1e9 + 7;

int A[200005];
long long dpPos[200005], dpCol[200005];

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

    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    dpPos[0] = 1;
    long long ans = 0;

    for(int i=1; i<=N; i++)
    {
        dpPos[i] = dpPos[i-1];

        if(A[i] != A[i+1])
        {
            dpPos[i] = (dpPos[i] + dpCol[ A[i] ]) % mod;
            dpCol[ A[i] ] = (dpCol[ A[i] ] + dpPos[i-1]) % mod;
        }
    }

    cout << dpPos[N] << "\n";
    return 0;
}


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

int main(){
    long long H;
    cin >> H;
    int count = 0;
    long long out = 0;
    while (H > 0){
        H /= 2;
        out += pow(2, count);
        count++;
    }
  	cout << out << endl;
    return 0;
}

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

void solve(){
    string a,b;
	cin>>a>>b;
    b=b.substr(0,b.size()-1);
	if(a==b)
		cout<<"Yes";
	else
		cout<<"No";
}

int main(){
	
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int c;cin>>c;
   // while(c--)	
       solve();
    return 0;
}

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

using namespace std;

using ll = long long;

bool Check(const int n, const int m, const int k) {
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if ((n - i) * j + (m - j) * i == k)
                return true;
        }
    }
    return false;
}

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

    int n, m, k;
    cin >> n >> m >> k;
    if (Check(n, m, k)) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//typedef long long ll;
int comp(const void *a,const void *b)
{
  return *(int *)a-*(int *)b; 
}
int main(void)
{
  int k,n;
  scanf("%d%d",&k,&n);
  int a[n],max;
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),comp);
  max=a[0]+k-a[n-1];
  for(int i=1;i<n;i++)
    if((a[i]-a[i-1])>max) max=a[i]-a[i-1];
  printf("%d\n",k-max);
  return 0;
}

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

int main(){
    int64_t n, pw[12];
    cin >> n;
    pw[0] = 1;
    for(int i=1;i<=11;++i) pw[i] = pw[i-1] * 26;

    for(int d=1;;++d){
        if(n <= pw[d]){
            --n;
            vector<char> ans(d+1, '\n');
            for(int i=d-1;i>=0;--i){ ans[i] = 'a' + n % 26; n /= 26; }
            for(auto c: ans) cout << c;
            return 0;
        }
        n -= pw[d];
    }
    
    return 0;
}

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

int64_t lcm(int64_t a, int64_t b) {
    return (a / __gcd(a, b) * b);
}

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

    int64_t ans = 1;
    for (auto i = 0; i < n; i++) {
        int64_t t; cin >> t;
        ans = lcm(ans, t);
    }

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

Measured memory_bytes: 3596
#UnionFind木
class UnionFind():
    def __init__(self,N,M):
        self.N = N
        self.M = M
        self.parents = [-1]*(N + M)

    def find(self,x): #根を見つける、繋ぎ直す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def unite(self,x,y): #x,yの含むグループを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x,y = y,x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self,x,y):#xとyが同じグループにいるか判定
        return self.find(x) == self.find(y)
    
    def answer(self):
        r = self.find(0)
        if all(r == self.find(i) for i in range(1,self.N)):
            return True
        else:
            return False

N,M = map(int,input().split())
uf = UnionFind(N,M)
for i in range(N):
    A = list(map(int,input().split()))
    for a in A[1:]:
        uf.unite(i,a - 1 + N)
if uf.answer():
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9532
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let mut x = vec![];
    let mut y = vec![];
    let mut p = vec![];
    for _ in 0..n {
        parse!(it, _x: i64, _y: i64, _p: i64);
        x.push(_x);
        y.push(_y);
        p.push(_p);
    }
    let mut xs = vec![vec![std::i64::MAX; n]; 1 << n];
    let mut ys = vec![vec![std::i64::MAX; n]; 1 << n];
    for i in 0..(1 << n) {
        for j in 0..n {
            xs[i][j] = x[j].abs() * p[j];
            ys[i][j] = y[j].abs() * p[j];
            for k in 0..n {
                if (i >> k) & 1 == 1 {
                    for (xs, x) in [(&mut xs, &mut x), (&mut ys, &mut y)].iter_mut() {
                        xs[i][j] = min(xs[i][j], (x[j] - x[k]).abs() * p[j]);
                    }
                }
            }
        }
    }
    let mut ret = vec![std::i64::MAX; n + 1];
    for i in 0..(1 << n) {
        let mut xi: usize = i;
        let count = i.count_ones() as usize;
        loop {
            xi &= i;
            let yi = i - xi;
            let mut p = 0;
            for k in 0..n {
                p += min(xs[xi][k], ys[yi][k]);
            }
            ret[count] = min(ret[count], p);
            if xi == 0 {
                break;
            }
            xi -= 1;
        }
    }
    for i in 0..=n {
        println!("{}", ret[i]);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 11764
fun main(args : Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toLong() }

    if (n == 1L && m == 1L) {
        println(1)
        return
    }

    if (n == 1L) {
        println(m-2L)
        return
    }

    if (m == 1L) {
        println(n-2L)
        return
    }

    println((n-2L) * (m-2L))
}



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


using namespace std;

int main()
{
    int a,b,c;

    vector<string> result;

    while(cin >> a >> b >> c){
        if(a == -1 && b == -1 && c == -1){
            break;
        }

        if(a == -1 | b == -1) result.push_back("F");
        else if(a + b >= 80) result.push_back("A");
        else if(a + b >= 65) result.push_back("B");
        else if(a + b >= 50) result.push_back("C");
        else if(a + b >= 30 && c >= 50) result.push_back("C");
        else if(a + b >= 30) result.push_back("D");
        else if(a + b < 30) result.push_back("F");
    }

    for(auto re : result){
        cout << re << endl;
    }


    return 0;
}

Measured memory_bytes: 3012
#include<stdio.h>
#define N 100000

int main(){
	int n,x,i;
	int num=0;
	int temp;
	int a[N];
	
	scanf("%d",&n);
	scanf("%d",&a[num++]);
	temp=a[0];
	
	for(i=1;i<n;i++){
		scanf("%d",&x);
		if(temp!=x){
			temp=x;
			a[num++]=x;
		}
	}
	
	for(i=0;i<num-1;i++)printf("%d ",a[i]);
	printf("%d\n",a[num-1]);
	
	return 0;
}
	


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int arr[250][250];
char s[250][250];
int di[10] = {1,0,-1,0,1,-1,-1,1};
int dj[10] = {0,1,0,-1,1,-1,1,-1};

int main(){
    int n, m;
    scanf("%d%d", &n,&m);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            scanf(" %c", &s[i][j]);
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
           if(s[i][j]=='#'){
                for(int k=0; k<8; k++){
                    int pi = i+di[k];
                    int pj = j+dj[k];
                    arr[pi][pj]++;
                }
           }
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i][j]=='#'){
                printf("#");
            }else{
                printf("%d", arr[i][j]);
            }

        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 256
#n = int(input())
#a = list(map(int, input().split()))
#d, t, s = map(int, input().split())
s = input()
t = input()
ans = 10000
count = 0
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j]:
      count += 1
  if ans > count:
    ans = count
  count = 0
print(ans)

Measured memory_bytes: 9112
N, A, B, C, D = map(int, input().split())
S = input()	# .#

if "##" in S[A-1:C]:
	print("No")
elif "##" in S[B-1:D]:
	print("No")
elif D < C:	# A jumps over B
	if not "..." in S[B-2:D+1]:
		print("No")
	else:
		print("Yes")
else:
	print("Yes")

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const int MOD = 998244353;

string S[110];
bool v[110], s[110];
int main()
{
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int i = 0; i < H; i++) {
		bool ok = true;
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') ok = false;
		}
		v[i] = ok;
	}
	for (int j = 0; j < W; j++) {
		bool ok = true;
		for (int i = 0; i < H; i++) {
			if (S[i][j] == '#') ok = false;
		}
		s[j] = ok;
	}
	for (int i = 0; i < H; i++) {
		if (!v[i]) {
			for (int j = 0; j < W; j++) {
				if (!s[j] && !v[i])cout << S[i][j];
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
long long dp[3000][3000][4]; //[x][y][]
int main(){
  int R,C,K;
  cin>>R>>C>>K;
  for(int j=0;j<R;j++){
    for(int i=0;i<C;i++){
      dp[i][j][0]=0; dp[i][j][1]=0; dp[i][j][2]=0; dp[i][j][3]=0;
    }
  }
  for(int i=0;i<K;i++){
    int r,c,v;
    cin>>r>>c>>v;
    dp[c-1][r-1][1]=v;
  }
  for(int j=0;j<R;j++){
    for(int i=0;i<C;i++){
      if(i!=0){
        if(dp[i][j][1]!=0){
          if(dp[i-1][j][3]!=0){
            dp[i][j][3]=max(dp[i-1][j][3],dp[i-1][j][2]+dp[i][j][1]);
          }
          if(dp[i-1][j][2]!=0){
            dp[i][j][2]=max(dp[i-1][j][2],dp[i-1][j][1]+dp[i][j][1]);
            if(dp[i-1][j][3]==0) dp[i][j][3]=dp[i-1][j][2]+dp[i][j][1];
          }
          if(dp[i-1][j][1]!=0&&dp[i-1][j][2]==0) dp[i][j][2]=dp[i-1][j][1]+dp[i][j][1];
          long long l=dp[i-1][j][0];
          if(j!=0){
            if(l<dp[i][j-1][0]) l=dp[i][j-1][0];
            if(l<dp[i][j-1][1]) l=dp[i][j-1][1];
            if(l<dp[i][j-1][2]) l=dp[i][j-1][2];
            if(l<dp[i][j-1][3]) l=dp[i][j-1][3];
          }
          dp[i][j][1]=max(dp[i-1][j][1],l+dp[i][j][1]);
        }
        else{
          dp[i][j][1]=dp[i-1][j][1];
          dp[i][j][2]=dp[i-1][j][2];
          dp[i][j][3]=dp[i-1][j][3];
        }
        if(j!=0){
          dp[i][j][0]=max(max(dp[i][j-1][0],dp[i][j-1][1]),max(dp[i][j-1][2],dp[i][j-1][3]));
          dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]);
        }
      }
      else if(j!=0){
        dp[i][j][0]=max(dp[i][j-1][0],dp[i][j-1][1]);
        if(dp[i][j][1]!=0) dp[i][j][1]+=dp[i][j][0];
      }
    }
  }
  cout<<max(max(dp[C-1][R-1][0],dp[C-1][R-1][1]),max(dp[C-1][R-1][2],dp[C-1][R-1][3]))<<endl;
  
  return 0;
}

Measured memory_bytes: 284336
#include <stdio.h>

// 入力受付用の変数
#define BUF 200002
char str[BUF];

// 入力された値
int N, L;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d", &N, &L);
}

void solve() {
	int abs_min = L < 0 ? -L : L;
	int sub = L;
	int sum = 0;
	for (size_t i = 1; i <= N; i++) {
		int temp = (L+i-1);
		temp = temp < 0 ? -temp : temp;
		if (abs_min > temp) {
			// printf("%d -> %d\n", abs_min, temp);
			abs_min = temp;
			sub = (L+i-1);
		}
		sum += (L+i-1);
	}

	// printf("%d %d\n", sum, sub);
	printf("%d\n", sum - sub);
}

int main(void) {
	receive_input();

	solve();

	return 0;
}


Measured memory_bytes: 128