akhauriyash/Code-Regression huggingface dataset:
A = []
b = []

# 送信用の入力処理
n, m = map(int, input().split())
for i in range(n):
    A.append([int(i) for i in input().split()])
for i in range(m):
    b.append(int(input()))

# # テスト用にファイルから入力する処理
# with open('input_itp1_6_d_1.txt', mode='r', encoding='utf8') as f:
#     n, m = map(int, next(f).split())
#     try:
#         for i in range(n):
#                 A.append([int(i) for i in next(f).split()])
#         for i in range(m):
#             b.append(int(next(f)))
#     except StopIteration:
#         raise ValueError('入力データがおかしい')

c = []
for row in range(len(A)):
    tmp = 0
    for col in range(len(A[row])):
        tmp += A[row][col] * b[col]
    c.append(tmp)
for i in range(len(c)):
    print(c[i])


Measured memory_bytes: 6016
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

//「オイラーのふるい」。pnには素数の数が、primesには順番に素数が、
//eulnumsにはその整数を割り切る最小の素数が入る。
//ある数からeulnumsを割っていくとその数の素因数分解が可能。
int pn = 0;
int primes[1600000];
int eulnums[1600000];

void eulerprime(int n) {
    fill(eulnums, eulnums + n + 1, 0);
    for (int i = 2; i <= n; i++) {
        if (eulnums[i] == 0) {
            eulnums[i] = i;
            primes[pn] = i;
            pn++;
        }

        for (int j = 0; i * primes[j] <= n; j++) {
            eulnums[i * primes[j]] = primes[j];
            if (i % primes[j] == 0) {
                break;
            }
        }
    }
}

bool bo[1000010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N];
    REP(i, 0, N) {
        cin >> A[i];
    }
    ll setg = A[0];
    REP(i, 0, N) {
        setg = gcd(setg, A[i]);
    }
    if (setg > 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    eulerprime(1000010);
    bool ok = true;
    REP(i, 0, N) {
        while (A[i] != 1) {
            ll p = eulnums[A[i]];
            if (bo[p]) {
                ok = false;
                break;
            }
            while (A[i] % p == 0) {
                A[i] /= p;
            }
            bo[p] = true;
        }
        if (!ok) {
            break;
        }
    }
    yesno(ok, "pairwise coprime", "setwise coprime");
}


Measured memory_bytes: 15612
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////


struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

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

	string ans = "";
	for (auto s : S) {
		char ns = (s + N) <= 90 ? (s + N) : (s + N) - 26;
		ans += ns;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

R,C,K = LI()
r,c,v = LIR(K,3)

def index(i,j,k):
    return k*C*R + i*C + j

a = [[0]*C for _ in range(R)]
for i in range(K):
    a[r[i]-1][c[i]-1] = v[i]

dp = [0]*(4*C*R)
dp[index(0,0,1)] = a[0][0]

for i in range(R):
    for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4)

ans = 0
for k in range(4):
    ans = max(ans,dp[index(R-1,C-1,k)])

print(ans)

Measured memory_bytes: 466676
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        if(s[0] == 'A')
            ac++;
        else if(s[0] == 'W')
            wa++;
        else if(s[0] == 'T')
            tle++;
        else if(s[0] == 'R')
            re++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vll vector<long long> 
#define str string 
#define ch char
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair

int dp[100000];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin>>n>>k;
    int ar[n];
    int mx = 0;
    for(int i = 0; i<n; i++){
        cin>>ar[i];
        dp[ar[i]] = 1;
        mx = max(mx, ar[i]);
    }
    for(int i=1; i<=k; i++){
        if(dp[i] == 1) continue;
        for(int j=0; j<n; j++){
            if(i-ar[j]>=1&&dp[i-ar[j]] == 0){
                dp[i] = 1;
            }
        }
    }
    if(dp[k]==1) cout<<"First";
    else cout<<"Second";
}



Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < b; ++i)

int main()
{
    char c;
    cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') 
        cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
k = int(input())
a =input()

al = list(a)
alr = list(reversed(al))

from collections import Counter
count = Counter(al)
r = count["R"]
w = count["W"]

if r*w ==0:
    print(0)
    exit()

rf = al.index("R")
wf = al.index("W")

rfr =alr.index("R")
wfr =alr.index("W")

#白に変える,最初の白より左の赤は除外
ans1 = r -wf
#赤に変える,最後の赤より右の白は除外
ans2 = w -rfr

#入れ替える,最初から赤の個数番目のうち赤を除外
alrr = al[:r]
countr = Counter(alrr)
rr = countr["R"]
ans3 = r - rr

print(min(ans1,ans2,ans3))

Measured memory_bytes: 13884
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  ll n, a,b,c,d,e;
  cin >> n>>a>>b>>c>>d>>e;
  ll m = min(a, min(b, min(c, min(d, e))));
  if (n % m == 0) {
    n /= m;
  }
  else {
    n /= m;
    n++;
  }
  printf("%lld\n", n + 4);
} 


Measured memory_bytes: 256
/*input
3
2 2 20
2 1 30
3 1 40
*/
#include<bits/stdc++.h>
using namespace std;
struct block
{
	int W,S;
	long int Val;
	block(int W=0,int S=0,long int V=0) : W(W),S(S),Val(V)  {};

	bool operator< (const block &oth)
	{
		return W+S<oth.W+oth.S;
	}

};

const int WMax = 2e4+5,NMax = 1e3+5;
long int dp[NMax][WMax];

int main()
{
	int n;cin>>n;
	vector<block> blocks(n);
	for(int i=0;i<n;i++) cin>>blocks[i].W>>blocks[i].S>>blocks[i].Val;
	sort(blocks.begin(), blocks.end());

	memset(dp,0l,sizeof dp);
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<WMax;j++)
		{
			if(i!=0)
			{
				dp[i][j] = dp[i-1][j];
				if(j>=blocks[i].W && j-blocks[i].W<=blocks[i].S) dp[i][j]=max(dp[i][j],dp[i-1][j-blocks[i].W] + blocks[i].Val);
			} 
			else if(j==blocks[i].W) dp[i][j]=max(dp[i][j],blocks[i].Val);
		}
	}
	cout<<"\n";
	long int ans=0;
	for(int j=0;j<WMax;j++) ans=max(ans,dp[n-1][j]);
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 160724
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define mo  924844033
using namespace std;
typedef long long ll;
int n,k;
ll dp[2][2009][2][2],bin[2009];
int main()
{
  scanf("%d%d",&n,&k);
  dp[0][0][1][0]=1ll;
  int las=0,now=0;
  bin[0]=1;
  for (int i=1;i<=n;i++) bin[i]=(bin[i-1]*(ll)i)%mo;
  for (int t=1;t<=k;t++)
  {
    for (int i=t;i<=n;i+=k)
    {   
      las=now;now=now^1;
      for (int j=0;j<=n;j++)
      for (int x=0;x<=1;x++)
      for (int y=0;y<=1;y++)
      dp[now][j][x][y]=0;
    
      for (int j=0;j<=n;j++)
      for (int x=0;x<=1;x++)
      for (int y=0;y<=1;y++)
  	  {
  	    if (dp[las][j][x][y]==0) continue;
	    ll val=dp[las][j][x][y];
	    if (i+k>n)
	    {
	       dp[now][j][1][0]=(dp[now][j][1][0]+val)%mo;
		   if (x==0) dp[now][j+1][1][0]=(dp[now][j+1][1][0]+val)%mo;  
		}
		else 
		{
	      dp[now][j][y][0]=(dp[now][j][y][0]+val)%mo; 
	      if (x==0) dp[now][j+1][y][0]=(dp[now][j+1][y][0]+val)%mo;
	      dp[now][j+1][y][1]=(dp[now][j+1][y][1]+val)%mo;
	    }
      }
    }
  }
  ll ans=0;
  for (int i=0;i<=n;i++)
  {
  	ll sum=0;
  	for (int x=0;x<=1;x++)
  	for (int y=0;y<=1;y++)
  	sum=(sum+dp[now][i][x][y])%mo;
  	sum=(bin[n-i]*sum)%mo;
  	if (i%2==0) ans=(ans+sum)%mo;
  	else ans=(ans-sum)%mo;
  }
  ans=(ans+mo)%mo;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

int
main()
{
  string s; cin >> s;
  int N = s.size();
  map<ll, ll> mods;
  mods[0] += 1;
  ll digit = 1;
  ll current = 0;
  for(int i = N - 1; i >= 0; --i){
    current = (current + (s[i] - '0') * digit) % 2019;
    digit *= 10; digit %= 2019;
    mods[current] += 1;
  }

  ll ans = 0;
  for(auto x: mods){
    ans += (x.second * (x.second - 1)) / 2;
  }

  cout << ans << endl;

}


Measured memory_bytes: 3756
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	vector<long long int>v(M);
	for (auto &i : v)cin >> i;
	for (int i = 0; i < N; i++) {
		vector<long long int>w(M);
		for (auto &j : w)cin >> j;
		long long int box = K;
		for (int j = 0; j < M; j++)box += v[j] * w[j];
		L += box > 0;
	}
	cout << L << endl;
	return 0;
}

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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	
	int n,d,x;
	cin >>n >>d >>x;
	VI a(n);
	rep(i,n) cin >>a[i];
	int ans=0;
	rep(i,d){
		rep(j,n){
			if(i%a[j]==0) ans++;
		
		}
	
	}
	
	cout << ans + x<<"\n";
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
char in[100000000];
int main(void) {
  int n;
  unsigned long long m;
  char bfr[200], aft[200];
  int flag = 0;

  while(1) {
    cin >> n;
    if(n == 0) break;
    for(int i = 0 ; i < n ; i++) {
      cin >> bfr[i] >> aft[i];
    }
    cin >> m;
    for(int i = 0 ; i < m ; i++) {
      cin >> in[i];
    }
    
    for(int i = 0 ; i < m ; i++) {
      for(int j = 0 ; j < n ; j++) {
	if(in[i] == bfr[j] && flag == 0) {
	  in[i] = aft[j];
	  flag = 1;
	}
      }
      flag = 0;
    }
    
    for(int i = 0 ; i < m ; i++) {
      cout << in[i];
    }
    cout << endl;
    for(int i = 0 ; i < 200 ; i++) {
      bfr[i] = 0;
      aft[i] = 0;
    }   
  }
  return 0;
}

Measured memory_bytes: 964
K = int(input())

runrun = []
run = list(range(0,10))
runrun.extend(run)

for i in range(10):
    k = 10**i
    trun = []
    for r in run:
        t = r//k
        trun.append(t*10*k + r)
        if t > 0:
            trun.append((t-1)*10*k + r)
        if t < 9:
            trun.append((t+1)*10*k + r)
    runrun.extend(trun)
    run = trun

runrun = list(set(runrun))
runrun.sort()
print(runrun[K])


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    vector<int> a(9);
    for(int i=0;i<9;i++) {
        cin >> a.at(i);
    }

    vector<int> r(9);

    int n;
    cin >> n;

    int c;
    for(int i=0;i<n;i++) {
        cin >> c;
        for(int j=0;j<9;j++) {
            if(a.at(j)==c) r.at(j) = 1;
        }
    }

    if(r.at(0)*r.at(1)*r.at(2)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(3)*r.at(4)*r.at(5)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(6)*r.at(7)*r.at(8)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(0)*r.at(3)*r.at(6)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(1)*r.at(4)*r.at(7)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(2)*r.at(5)*r.at(8)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(0)*r.at(4)*r.at(8)) {
        cout << "Yes" << endl;
        return 0;
    }
    if(r.at(2)*r.at(4)*r.at(6)) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
  int N, T; cin >> N >> T;
  vector<int> c(N);
  vector<int> t(N);
  for(int i = 0; i < N; i++){
    cin >> c[i] >> t[i];
  }

  vector<int> a;
  for(int i = 0; i < N; ++i){
    if(t[i] <= T){
      a.push_back(c[i]);
    }
  }
  if(a.size() == 0){
    cout << "TLE" << endl;
  }
  else {
    cout << *min_element(a.begin(), a.end()) << endl;
  }
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main() {
    int n, f[100][10], p[100][11];
    
    cin >> n;
    REP(i, n){
        REP(j, 10){
            cin >> f[i][j];
        }
    }
    REP(i, n){
        REP(j, 11){
            cin >> p[i][j];
        }
    }
    
    ll ans = -INF;
    for(int i = 1; i < 1024; i++){
        int bp = 9;
        int pp[100];
        REP(j, n){
            pp[j] = 0;
        }
        for(int t = i; t > 0; t = (t >> 1) & 0x7fffffff){
            if(t & 1){
                REP(j, n){
                    if(f[j][bp]){
                        pp[j]++;
                    }
                }
            }
            bp--;
        }
        ll sum = 0;
        REP(j, n){
            sum += p[j][pp[j]];
        }
        ans = max(ans, sum);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define UNI(a)      a.resize(unique(all(a), a.begin()) - a.begin())
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1) {
            rem = (rem * a) % m;
        }
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 100000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;

int n;
int a[MAX][3];

int dp[MAX][3];

int main() {
    n = in();
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 3; j++) {
            a[i][j] = in();
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 3; j++) {
            dp[i][j] = 0;
            for(int k = 0; k < 3; k++) {
                if(k != j) {
                    dp[i][j] = max(dp[i][j], a[i][j] + dp[i - 1][k]);
                }
            }
        }
    }
    out(*max_element(dp[n], dp[n] + 3)), nl;
    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC178C
{
    class Program
    {
        static long mod = 0;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            mod = (long)Math.Pow(10, 9) + 7;
            long ans = Njou(N, 10);
            long no0 = Njou(N, 9);
            long no9 = Njou(N, 9);;
            long no09 = Njou(N, 8);
            ans += mod - no0;
            ans %= mod;
            ans += mod - no9;
            ans %= mod;
            ans += no09;
            ans %= mod;
            Console.WriteLine(ans);


        }
        static long Njou(int N,long a)
        {
            string S = Convert.ToString(N, 2);
            int l = S.Length;
            long ans = 1;
            for(int i = l - 1; i >= 0; i--)
            {
                if (S[i].ToString() == "1")
                {
                    ans *= a;
                    ans %= mod;
                }
                a *= a;
                a %= mod;
            }
            return ans;
        }
    }
}


Measured memory_bytes: 27908
#include <bits/stdc++.h>
#define ALL(x) begin(x), end(x)

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = int64_t;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;
using vb = vector<bool>;
constexpr int MOD1 = 1000000007;

template <int MOD> struct modnum {
    int v;
    modnum() : v(0) {
    }
    modnum(ll _v) : v(_v % MOD) {
        if (v < 0)
            v += MOD;
    }
    explicit operator int() const {
        return v;
    }
    friend istream &operator>>(istream &i, modnum &n) {
        ll v;
        i >> v;
        n = modnum(v);
        return i;
    }
    friend ostream &operator<<(ostream &o, const modnum &n) {
        return o << n.v;
    }

    friend bool operator==(const modnum &a, const modnum &b) {
        return a.v == b.v;
    }
    friend bool operator!=(const modnum &a, const modnum &b) {
        return a.v != b.v;
    }

    modnum &operator+=(const modnum &o) {
        v += o.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    modnum &operator-=(const modnum &o) {
        v -= o.v;
        if (v < 0)
            v += MOD;
        return *this;
    }
    modnum &operator*=(const modnum &o) {
        v = int(ll(v) * ll(o.v) % MOD);
        return *this;
    }
    modnum operator-() {
        modnum res;
        if (v)
            res.v = MOD - v;
        return res;
    }
    friend modnum operator+(const modnum &a, const modnum &b) {
        return modnum(a) += b;
    }
    friend modnum operator-(const modnum &a, const modnum &b) {
        return modnum(a) -= b;
    }
    friend modnum operator*(const modnum &a, const modnum &b) {
        return modnum(a) *= b;
    }

    modnum pow(int e) const {
        if (e == 0)
            return 1;
        if (e & 1)
            return *this * this->pow(e - 1);
        return (*this * *this).pow(e / 2);
    }

    modnum inv() const {
        int g = MOD, x = 0, y = 1;
        for (int r = v; r != 0;) {
            int q = g / r;
            g %= r;
            swap(g, r);
            x -= q * y;
            swap(x, y);
        }

        assert(g == 1);
        assert(y == MOD || y == -MOD);
        return x < 0 ? x + MOD : x;
    }
    modnum &operator/=(const modnum &o) {
        return (*this) *= o.inv();
    }
    friend modnum operator/(const modnum &a, const modnum &b) {
        return modnum(a) /= modnum(b);
    }

    static modnum fact(int n) {
        static vector<modnum<MOD>> fact = {1};
        while (fact.size() <= n)
            fact.push_back(fact.back() * fact.size());
        return fact[n];
    }
    static modnum ncr(int n, int r) {
        if (r < 0 || n < r)
            return 0;
        return fact(n) / (fact(r) * fact(n - r));
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    modnum<MOD1> ans = 0, cast = 1;

    int d = s.size();
    int ctr = 0;

    for (int i = 0; i < d; i++) {
        if (s[i] == '1') {
            ans += (2 * cast).pow(ctr) * (3 * cast).pow(d - i - 1);
            ctr++;
        }
    }
    ans += (2 * cast).pow(ctr);

    cout << ans;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        if(a[i] == i+1 && a[i+1] == i+2){
            ans++;
            i++;
            continue;
        }
        if(a[i] == i+1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);

  for(int i = 0; i < 3; i++) {
    if(N % 10 == 7) {
      puts("Yes");
      break;
    }
    else {
      N /= 10;
    }
  }
  if(N % 10 != 7) {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string, int> mp;
    int ma = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
        chmax(ma, mp[s]);
    }
    for (auto it : mp) {
        if (it.second == ma) {
            cout << it.first << endl;
        }
    }
}


Measured memory_bytes: 23808
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 5;

ll n, m, p, big1, big2, cur1, cur2;
ll row[maxn], col[maxn];

struct Point {
    ll x, y;
    Point(ll x = 0, ll y = 0): x(x), y(y) {}
    bool operator < (const Point &rhs) const {
        if (x < rhs.x) return true;
        if (x > rhs.x) return false;
        if (y < rhs.y) return true;
        return false;
    }
};

set<Point> q;

int main() {
    scanf("%lld%lld%lld", &n, &m, &p);
    for (int i = 0; i < p; i++) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if (!q.count(Point(x, y))) {
            row[x]++; 
            col[y]++;
            q.insert(Point(x, y));
        }
    }

    for (int i = 1; i <= n; i++) {
        if (row[i] > big1) {
            big1 = row[i];
            cur1 = i;
        }
    }
    for (int i = 1; i <= m; i++) {
        if (col[i] > big2) {
            big2 = col[i];
            cur2 = i;
        }
    }
    bool flag = false;
    vector<ll> bigx, bigy;

    for (int i = 1; i <= n; i++) {
        if (row[i] == big1) bigx.push_back(i);
    }
    for (int i = 1; i <= m; i++) {
        if (col[i] == big2) bigy.push_back(i);
    }

    // for (auto i : bigx)
    //     printf("%lld ", i);
    // printf("\n");
    // for (auto i : bigy)
    //     printf("%lld ", i);

    for (auto i : bigx) {
        for (auto j : bigy) {
            if (!q.count(Point(i, j))) {
                flag = true;
                break;
            }
        }
        if (flag) break;
    }

    if (flag) {
        printf("%lld\n", big1 + big2);
    }
    else {
        printf("%lld\n", big1 + big2 - 1);
    }
    return 0;
}

Measured memory_bytes: 34588
//
// Created by yamunaku on 2019/07/14.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

struct edge{
    int s;
    int t;
    int id;
};

vi visited;
vi deg;
vi cd;
vector<vector<edge>> e;

bool dfs(int x, int p,int idd){
    visited[x]=1;
    for(auto nx:e[x]){
        if(!visited[nx.t]){
            if(deg[x]%2){
                deg[x]++;
                deg[nx.t]++;
                cd[nx.id]++;
            }
            dfs(nx.t, x, nx.id);
        }
    }
    if(deg[x]%2){
        if(p==-1) return false;
        deg[x]++;
        deg[p]++;
        cd[idd]++;
    }
    return true;
}


int main(){
    int n,m;
    cin >> n >> m;
    e=vector<vector<edge>>(n);
    vector<edge> ed;
    int u,v;
    visited=vi(n,0);
    deg=vi(n,0);
    rep(i,m){
        cin >> u >> v;
        u--,v--;
        e[u].push_back({u,v,i});
        e[v].push_back({v,u,i});
        ed.push_back({u,v,i});
        deg[u]++;
    }
    cd=vi(m,0);
    if(!dfs(0, -1, -1)){
        cout << -1 << endl;
        return 0;
    }
    rep(i,m){
        if(cd[i]%2){
            cout << ed[i].t+1 SP ed[i].s+1 << endl;
        }else{
            cout << ed[i].s+1 SP ed[i].t+1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 15412
#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>;
 
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 ll INF = 1LL << 60;


//------------------------------------------------
int main() {
    
    string s,t;
    cin >> s >> t;

    int sn, tn;
    sn = s.size();
    tn = t.size();
    

    // initialize DP
    int dp[sn+1][tn+1];
    rep(i,sn+1) rep(j,tn+1) dp[i][j] = 0;

    //update DP
    for(int i=1; i<=sn; ++i){
        for(int j=1; j<=tn; ++j){
            if( s[i-1]==t[j-1]) chmax(dp[i][j], dp[i-1][j-1]+1);
            chmax(dp[i][j], dp[i-1][j]);
            chmax(dp[i][j], dp[i][j-1]);
        }
    }

    string ans = "";
    int i = sn;
    int j = tn;
    while(i>0 && j > 0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else{
            ans = s[i-1] + ans;
            --i; --j;
        }
    }

    cout << ans << endl;
    /*
    rep(i,sn+1){
        rep(j,tn){
            cout << dp[i][j];
        }
        cout << dp[i][tn] << endl;
    }
    */


    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  set<int> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  cout << s.size() << endl;
  return 0;
}


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

int main() {
  ll a, b, n, sum = 0;
  cin >> a >> b >> n;
  if (b > 1) {
    ll c = b - 1;
    while (c < n) {
      sum = max(sum, a * c / b - c / b * a);
      c += b;
    }
  }
  sum = max(sum, a * n / b - n / b * a);
  cout << sum;
}

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

using namespace std;

int main(void)
{
    string N, s;
    cin >> N;

    s = N.substr(N.length() - 1,1);

    if (s == "2" || s == "4" || s == "5" || s == "7" || s == "9") {
        cout << "hon" << endl;        
    }
    else if(s == "0" || s == "1" || s == "6" || s == "8") {
        cout << "pon" << endl;
    }
    else {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  cout << N / 3 << endl;
  return 0;
}

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

using namespace std;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int st, et;
    st = max(a, c);
    et = min(b, d);
    cout << max(0, et - st) << endl;

    return 0;
}


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

using namespace std;

double conc(int a, int b)
{
	if (a + b <= 0 || b <= 0)
		return 0;

	return 100.0 * b / (a + b);
}

int main()
{
	int w1, w2, s1, s2, sugMax, sumMax;
	int ans_s = -1, ans_w = -1;

	cin >> w1 >> w2 >> s1 >> s2 >> sugMax >> sumMax;

	set<int> sugars;
	set<int> waters;
	for (int i = 0; i <= sumMax; i++)
	{
		for (int j = 0; j <= sumMax; j++)
		{
			int y = i * s1 + j * s2;

			if (y <= sumMax)
			{
				sugars.insert(y);
			}
		}
	}

	for (int i = 0; i <= sumMax; i++)
	{
		for (int j = 0; j <= sumMax; j++)
		{
			int x = 100 * i * w1 + 100 * j * w2;

			if (x <= sumMax)
			{
				waters.insert(x);
			}
		}
	}
	
	for (auto s : sugars)
	{
		for (auto w : waters)
		{
			if (s <= sugMax * w / 100 && s + w <= sumMax)
			{
				if (conc(ans_w, ans_s) <= conc(w, s))
				{
					ans_s = s;
					ans_w = w;
				}
			}
		}
	}
	
	cout << ans_s + ans_w << " " << ans_s << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k,q;
	cin>>n>>k>>q;
	vvl vv(n);
	rep(i,q){
		ll in;
		cin>>in;
		vv[in-1].push_back(i+1);
	}
	rep(i,n){
		bool ok=true;
		ll p=k,t=0;
		rep(j,vv[i].size()){
			p-=(vv[i][j]-t-1);
			if(p<=0)ok=false;
			t=vv[i][j];
		}
		p-=(q-t);
		if(p<=0)ok=false;
		t=q;
		Yn(ok);
	}

}


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

#define int long long

signed main(){
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;

	map<int, int> mp;
	int now = 0;
	int xx = 1;
	if(p != 2 && p != 5){
		for(int i = n-1;i >= 0;i--){
			now += (s[i] - '0') * xx % p;
			now %= p;
			xx *= 10;
			xx %= p;
			mp[now]++; 
		}

		int ans = mp[0];

		now = 0;
		xx = 1;
		for(int i = n-1;i >= 0;i--){
			now += (s[i] - '0') * xx % p;
			now %= p;
			xx *= 10;
			xx %= p;
			mp[now]--;
			ans += mp[now];
		}
		cout << ans << endl;
	}else{
		int ans = 0;
		for(int i = 0;i < n;i++){
			if((s[i]-'0') % p == 0){
				ans += (i+1);
			}
		}
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 1028
#include <iostream>
using namespace std;
int main(void){
    
    int a, b;
    cin >> a >> b;
    
    if(a > b){
        for(int i = 0; i < a; i++){
            cout << b;
        }cout << endl;
    }
    else{
        for(int i = 0; i < b; i++){
            cout << a;
        }cout << endl;        
        
    }
    
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

const INF: usize = 10000000000000;

fn cycle(xyu: &mut Vec<(usize, usize, char)>) {
   for (x, y, u) in xyu.iter_mut() {
      let xn = x.clone();
      let yn = y.clone();
      *x = yn;
      *y = 200000 - xn;
      *u = match u {
         'U' => 'R',
         'R' => 'D',
         'D' => 'L',
         'L' => 'U',
         _ => unreachable!(),
      };
   }
}

#[fastout]
fn main() {
   input! {
      n: usize,
      mut xyu:[( usize, usize, char); n]
   }

   let mut ans: usize = INF;
   for i in 0..4 {
      if i < 2 {
         let mut up = BTreeMap::<usize, Vec<usize>>::new();
         let mut down = BTreeMap::<usize, Vec<usize>>::new();
         for &(x, y, u) in xyu.iter() {
            match u {
               'U' => {
                  up.entry(x).and_modify(|v| v.push(y)).or_insert(vec![y]);
               }
               'D' => {
                  down.entry(x).and_modify(|v| v.push(y)).or_insert(vec![y]);
               }
               _ => (),
            }
         }
         for (&x, up) in up.iter_mut() {
            if let Some(down) = down.get_mut(&x) {
               down.sort();
               up.sort();
               let mut p = 0;
               for &y1 in up.iter() {
                  while p != down.len() && down[p] < y1 {
                     p += 1;
                  }
                  if p == down.len() {
                     break;
                  }
                  ans = min(ans, down[p] - y1)
               }
            }
         }
      }
      let mut up = BTreeMap::<usize, Vec<usize>>::new();
      let mut right = BTreeMap::<usize, Vec<usize>>::new();
      for &(x, y, u) in xyu.iter() {
         match u {
            'U' => {
               up.entry(x + y).and_modify(|v| v.push(y)).or_insert(vec![y]);
            }
            'R' => {
               right
                  .entry(x + y)
                  .and_modify(|v| v.push(y))
                  .or_insert(vec![y]);
            }
            _ => (),
         }
      }
      for (&x, up) in up.iter_mut() {
         if let Some(right) = right.get_mut(&x) {
            right.sort();
            up.sort();
            let mut p = 0;
            for &y1 in up.iter() {
               while p != right.len() && right[p] < y1 {
                  p += 1;
               }
               if p == right.len() {
                  break;
               }
               ans = min(ans, 2 * (right[p] - y1))
            }
         }
      }
      cycle(&mut xyu);
   }
   if ans == INF {
      println!("SAFE");
   } else {
      println!("{}", (ans as f64) / 2.0 * 10.0);
   }
}


Measured memory_bytes: 35268
N, M = map(int, input().split())
x, y, z = [], [], []

for i in range(N):
    xi, yi, zi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    z.append(zi)

bits = [[1,1,1], [1,1,-1], [1,-1,1], [1,-1,-1], [-1,1,1], [-1,1,-1], [-1,-1,1], [-1,-1,-1]]


results = []
for i in range(len(bits)):
    xyzsum=[0 for _ in range(N)]
    for j in range(N):
        xyzsum[j] = (x[j]*bits[i][0] + y[j]*bits[i][1] + z[j]*bits[i][2])
    xyzsum = sorted(xyzsum, reverse=True)
    results.append(sum(xyzsum[:M]))

print(max(results))

Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>
#define W_MAX 100
#define H_MAX 100
char map[H_MAX+1][W_MAX+1];
char gx,gy;
int solve(int posX,int posY)
{
	if(map[posY][posX]=='x')
		return 0;
	char c=map[posY][posX];
	map[posY][posX]='x';
	if(c=='^')
		return solve(posX,posY-1);
	else if(c=='v')
		return solve(posX,posY+1);
	else if(c=='>')
		return solve(posX+1,posY);
	else if(c=='<')
		return solve(posX-1,posY);
	else if(c=='.'){
		gx=posX;gy=posY;
		return 1;
	}
	return 1;
}
int main(void)
{
	int w,h,k;
	char str[101];
	while(true){
		scanf("%d%d",&h,&w);
		if(h==0||w==0)break;
		for(k=0;k<h;k++)
		{
			scanf("%s",&str);
			strcpy(map[k],str);
		}
		if(solve(0,0)==1)printf("%d %d\n",gx,gy);
		else printf("LOOP\n");
	}
}	

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n,k;
      cin >> n >> k;
      int x[n];
      rep(i,n)cin >> x[i];
      int ans=inf;
      int i=0;
      while(x[i]<0)i++;
      
      if(x[i]>0){
        
      rep(j,k-1){
       if(i+j<=n-1 && i-(k-1-j)>=0){
        ans=min(ans,-2*x[i-(k-1-j)]+x[i+j]); 
       }
      }
      if(i+k-1<=n-1){
       ans=min(ans,x[i+k-1]); 
      }
      if(i-k>=0){
       ans=min(ans,-x[i-k]); 
      }
      rep(j,k-1){
        if(i+j<=n-1 && i-(k-1-j)>=0){
         ans=min(ans,2*x[i+j]-x[i-(k-1-j)]); 
        }
      }
      cout << ans << endl;
      }else{
        
      rep(j,k-2){
       if(i-(k-j-2)>=0 && i+j+1<=n-1){
        ans=min(ans,-2*x[i-(k-j-2)]+x[i+j+1]); 
       }
      }
      if(i+k-1<=n-1){
       ans=min(ans,x[i+k-1]); 
      }
      if(i-k+1>=0){
       ans=min(ans,-x[i-k+1]); 
      }
      rep(j,k-2){
        if(i-(k-j-2)>=0 && i+j+1<=n-1){
         ans=min(ans,2*x[i+(k-j-2)]-x[i-(j+1)]); 
        }
      }
        cout << ans << endl;
      }
        
      return 0;}

Measured memory_bytes: 640
/**
 *    author:  tourist
 *    created: 21.09.2019 15:39:25       
**/
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
 public:
  int n;
  vector<vector<T>> mat;
  F func;
 
  SparseTable(const vector<T>& a, const F& f) : func(f) {
    n = static_cast<int>(a.size());
    int max_log = 32 - __builtin_clz(n);
    mat.resize(max_log);
    mat[0] = a;
    for (int j = 1; j < max_log; j++) {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++) {
        mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
      }
    }
  }
 
  T get(int from, int to) const {
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 32 - __builtin_clz(to - from + 1) - 1;
    return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  SparseTable<int> smin(a, [&](int i, int j) { return min(i, j); });
  SparseTable<int> smax(a, [&](int i, int j) { return max(i, j); });
  vector<int> bad(n - 1);
  for (int i = 0; i < n - 1; i++) {
    bad[i] = (a[i] > a[i + 1]);
  }
  vector<int> pref(n);
  for (int i = 0; i < n - 1; i++) {
    pref[i + 1] = pref[i] + bad[i];
  }
  int ans = 0;
  int nosort = 0;
  for (int i = 0; i <= n - k; i++) {
    if (pref[i + k - 1] - pref[i] == 0) {
      nosort = 1;
      continue;
    }
    if (i > 0 && smin.get(i - 1, i + k - 2) == a[i - 1] && smax.get(i, i + k - 1) == a[i + k - 1]) {
      continue;
    }
    ++ans;
  }
  cout << ans + nosort << '\n';
  return 0;
}


Measured memory_bytes: 28800