akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
   ios_base::sync_with_stdio(false);
   int X, Y, Z;
   cin >> X >> Y >> Z;
   int N = X + Y + Z;
   vector<ll> A(N), B(N);
   ll add = 0;
   for (int i = 0; i < N; ++i) {
      ll C;
      cin >> A[i] >> B[i] >> C;
      A[i] -= C;
      B[i] -= C;
      add += C;
   }
   vector<int> ord(N);
   iota(ord.begin(), ord.end(), 0);
   sort(ord.begin(), ord.end(), [&](int x, int y) {
      return A[x] - B[x] > A[y] - B[y];
   });
   vector<ll> pref(N);
   vector<ll> suff(N);
   ll cur = 0;
   priority_queue<ll, vector<ll>, greater<ll>> q;
   for (int i = 0; i < N; ++i) {
      cur += A[ord[i]];
      q.emplace(A[ord[i]]);
      if (i >= X) {
         cur -= q.top();
         q.pop();
      }
      pref[i] = cur;
   }
   while (q.size()) {
      cur -= q.top(); q.pop();
   }
   for (int i = N - 1; i >= 0; --i) {
      cur += B[ord[i]];
      q.emplace(B[ord[i]]);
      if (i < N - Y) {
         cur -= q.top();
         q.pop();
      }
      suff[i] = cur;
   }
   ll ans = -1e18;
   for (int i = X - 1; i < N - Y; ++i) {
      ans = max(ans, pref[i] + suff[i + 1]);
   }
   cout << ans + add << "\n";
   return 0;
}


Measured memory_bytes: 4984
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n;
    while(cin>>n){
        int arr[n];
        f0(n)cin>>arr[i];
        int tot=1000;
        int mini=10000,maxi=0;
        for(int i=0;i<n;i++){
            if(i==0){
                mini=min(arr[i],mini);
                maxi=max(arr[i],maxi);
                continue;
            }

            if(arr[i]<maxi){
                int x=tot/mini;
                tot-=(x*mini);
                tot+=(x*maxi);
                mini=10000;
                maxi=0;
            }
            maxi=max(maxi,arr[i]);
            mini=min(mini,arr[i]);
            //cout << mini << " "<< maxi << endl;
            if(i==n-1 && arr[i]>=maxi){
                int x=tot/mini;
                tot-=(x*mini);
                tot+=(x*maxi);
            }
        }
        cout << tot << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3636
N = int(input())
H_lst = list(map(int, input().split()))

ans = 0
count = 0
for i in range(1, N):
    if H_lst[i-1] >= H_lst[i]:
        count += 1
    else:
        if count > ans:
            ans = count
        count = 0
    

if count > ans:
    ans = count

print(ans)

Measured memory_bytes: 14224
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

string O,E;

int main(){
    cin>>O>>E;
    rep(i,E.length()){
        cout << O[i] << E[i];
    }
    if(O.length()!=E.length()){
        cout<<O[O.length()-1];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n,i;
  cin >> n;
  while(n){
    i = n%10;
    n/=10;
    if (i==7){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


int N;
string S;

int solve(){
    //まずEとWの累積和を得る
    int allE=0,allW=0;
    rep(i,S.size()){
        if(S[i]=='E') ++allE;
        else ++allW;
    }
    
    int res = S.size();
    int curE=0,curW=0;
    //iより右でEの人とiより左でWの人が向きを変えることになる
    //iは一番左から右にずれていくので最初はallE=curE。i自身がEだと観測するごとにcurEを増やしていく。
    rep(i,S.size()){
        int migiE = allE - curE;
        if(S[i]=='E') --migiE;
        res = min(res,curW+migiE); 

        if(S[i]=='E') ++curE;
        else ++curW;
    }
    return res;
}

int main(){
    while(cin >> N >> S){
        cout << solve() << endl;
    }
    

}

Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main()
{
    int T,N,a=0,b=0,c=0,d=0;
    int t[1000000];
    cin>>N>>T;
    for (int i=0; i<N; i++)
    {
        cin>>t[i];
    }
    for (int i=0; i<N; i++)
    {
        d=t[i]-t[i-1];
        if (d>=T||t[i]==0)
        {
            a=a+T;
        }
        else if (d<T)
        {
           b=T-d;
            c=T-b;
            a=a+c;
        }
    }
    cout<<a<<endl;
            
            
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll h; cin>>h;
	ll n; cin>>n;
	ll num=0;
	REP(i,n) {
		ll tmp;
		cin>>tmp;
		num+=tmp;
	}
	if(num>=h){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int x = scanner.nextInt();
        final boolean[][] table = new boolean[6][x + 1];
        for (int i = 0; i < 6; i++) {
            final int price = 100 + i;
            if (x % price == 0) {
                System.out.println(1);
                return;
            }

            for (int j = 1; j * price <= x; j++) {
                table[i][j * price] = true;
            }

            if (i == 0) {
                continue;
            }

            for (int j = 1; j <= x; j++) {
                table[i][j] |= table[i - 1][j];
            }

            for (int j = price + 1; j <= x; j++) {
                table[i][j] |= table[i - 1][j - price] || table[i][j - price];
            }
        }

        System.out.println(table[5][x] ? 1 : 0);
    }
}


Measured memory_bytes: 23252
#include <stdio.h>

int main(void)
{
	int n, pm, pe, pj;
	int i;
	char rank[100000];
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			return (0);
		}
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &pm, &pe, &pj);
			if (pm == 100 || pe == 100 || pj == 100){
				printf("A\n");	
			}
			else if ((pm + pe) / 2 >= 90){
				printf("A\n");
			}
			else if ((pm + pe + pj) / 3 >= 80){
				printf("A\n");	
			}
			else if ((pm + pe + pj) / 3 >= 70){
				printf("B\n");
			}
			else if ((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)){
				printf("B\n");
			}
			else {
				printf("C\n");
			}
		}
	}
	return (0);
}

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

vector<vector<int>> g;
vector<int> memo;

int f(int v){
  if(memo[v] != -1) return memo[v];
  int res = 0;
  for(int nv : g[v]){
    res = max(res,f(nv)+1);
  }
  return memo[v] = res;
}

int main(){
  int n,m;
  cin>>n>>m;
  g.resize(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--; y--;
    g[x].pb(y);
  } 
  memo.assign(n,-1);

  int ans = 0;
  rep(i,n){
    ans = max(ans,f(i));
  }
  cout << ans << endl;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int s;
    set<int> m;
    cin >> s;

    int idx = 1;
    while (1)
    {
        if (m.find(s) != m.end())
        {
            break;
        }
        else
        {
            m.insert(s);
            if (s % 2 == 0)
            {

                s /= 2;
            }
            else
            {
                s = s * 3 + 1;
            }
        }
        idx++;
    }
    cout << idx << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

int main(){
    int m=10000000,M=-10000000;
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        m=min(m,a); M=max(M,a);
    }
    cout<<M-m<<endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string.h>
#include <string>
#include <stdio.h>
#include <queue>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<long long> a;
    long long tmp;
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &tmp);
        a.push(tmp);
    }
    
    for (int i = 0; i < m; ++i)
    {
        long long newPrice = a.top() >> 1;
        a.pop();
        a.push(newPrice);
    }
    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int D; cin >> D;
  vector<int> c(26); rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D); rep(i,D) cin >> t[i];
  ll ans = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    ans += s[i][t[i]-1];
    lst[t[i]-1] = i;
    rep(j,26){
      ans -= c[j]*(i-lst[j]);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.io.IOException;

public class Main {
    static class Task implements Comparable<Task> {
        int a, b;

        Task(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Task t) {
            return b - t.b;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        PriorityQueue<Task> pq = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
            String[] in = br.readLine().split(" ");
            int a = Integer.parseInt(in[0]);
            int b = Integer.parseInt(in[1]);
            pq.add(new Task(a, b));
        }
        long time = 0;
        boolean flag = true;
        while(!pq.isEmpty()) {
            Task t = pq.poll();
            if(time + t.a > t.b) {
                flag = false;
                break;
            }
            time += t.a;
        }

        System.out.println(flag? "Yes" : "No");
    }
}

Measured memory_bytes: 65972
#include <cstdio>
#include <iostream>
#include <complex>

using namespace std;

double cross(complex<double> A, complex<double> B)
{
  return A.real() * B.imag() - A.imag() * B.real();
}

int main()
{
  complex<double> p[4];
  double x, y;
  while (scanf("%lf,%lf", &x, &y) == 2) {
    p[0] = complex<double>(x, y);
    for (int i = 1; i < 4; i++) {
      scanf(",%lf,%lf", &x, &y);
      p[i] = complex<double>(x, y);
    }
    
    if (cross(p[2] - p[0], p[1] - p[2]) * cross(p[2] - p[0], p[3] - p[2]) < 0 &&
	cross(p[3] - p[1], p[0] - p[3]) * cross(p[3] - p[1], p[2] - p[3]) < 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,60) {
		ll x = 0;
		rep(j,n) if(a[j]>>i & 1) x++;
		ll now = x*(n-x)%mod;
		rep(j,i) now = now*2%mod;
		ans += now;
		ans %= mod;
	}
	cout << ans << endl;
}



Measured memory_bytes: 5640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> used(m, 1);
  vector<vector<int>> in(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> in[i][j];
      in[i][j]--;
    }
  }
  int ans = 1 << 30;
  for (int d = 0; d < m; d++) {
    vector<int> cnt(m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (used[in[i][j]]) {
          cnt[in[i][j]]++;
          break;
        }
      }
    }
    int s = 0, t = 0;
    for (int i = 0; i < m; i++) {
      if (cnt[i] > t) {
        s = i;
        t = cnt[i];
      }
    }
    used[s] = 0;
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long N, D, A;
vector<long long> X, H;
using bomb = pair<long long, long long>;

long long solve() {
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return X[i] < X[j];});
    long long res = 0;
    queue<bomb> que;
    long long damage = 0;
    for (auto i : ids) {
        while (!que.empty() && que.front().first < X[i]) {
            damage -= que.front().second;
            que.pop();
        }
        H[i] -= damage;
        if (H[i] > 0) {
            res += H[i];
            que.push({X[i] + D, H[i]});
            damage += H[i];
        }
    }
    return res;
}

int main() {
    while (cin >> N >> D >> A) {
        X.resize(N); H.resize(N);
        D *= 2;
        for (int i = 0; i < N; ++i) {
            cin >> X[i] >> H[i];
            H[i] = (H[i] + A-1) / A;
        }
        cout << solve() << endl;
    }
}


Measured memory_bytes: 5760
a = list(map(int, input().split()))
A = [a]
ans = 0
while True:
    if (A[-1][0] & 1)or(A[-1][1] & 1)or(A[-1][2] & 1):
        print(ans)
        break
    tmp = [A[-1][1]//2+A[-1][2]//2, A[-1][0]//2 +
           A[-1][2]//2, A[-1][0]//2+A[-1][1]//2]
    if tmp in A:
        print(-1)
        break
    A.append(tmp)
    ans += 1


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

const int INF = 1000000100;
const int MAX_N = 1100;
const int MAX_H = 11100;
int A[MAX_N], B[MAX_N];
int H, N;
int dp[MAX_H];

int main()
{
    scanf("%d %d", &H, &N);
    for(int i = 0; i < N; ++i) scanf("%d %d", &A[i], &B[i]);
    for(int i = 1; i <= H; ++i) dp[i] = INF;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < H; ++j) {
            int k = min(H, j + A[i]);
            dp[k] = min(dp[k], dp[j] + B[i]);
        }
    }
    printf("%d\n", dp[H]);
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int N = sc.nextInt();
            ;
            if (N == 0)
                break;
            P[] p = new P[N];
            for (int i = 0; i < N; i++) {
                String s = sc.next();
                int buy = sc.nextInt();
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                int d = sc.nextInt();
                int e = sc.nextInt();
                int f = sc.nextInt();
                int sell = sc.nextInt();
                int m = sc.nextInt();
                int leaf = a + b + c;
                int fruit = d + e;
                sell *= f;
                double eff = 0;
                if (m == 1) {
                    eff = (0.0 + sell - buy) / (0.0 + leaf + fruit);
                } else {
                    eff = (sell * m - buy + 0.0) / (0.0 + leaf + fruit * m);
                }
                p[i] = new P();
                p[i].name = s;
                p[i].eff = eff;
            }
            Arrays.sort(p, new Comparator<P>() {
                @Override
                public int compare(P o1, P o2) {
                    double e = 1e-9;
                    if(Math.abs(o1.eff-o2.eff)<e){
                        return o1.name.compareTo(o2.name);
                    }
                    return -Double.compare(o1.eff, o2.eff);
                }
            });
            for (int i = 0; i < p.length; i++) {
                System.out.println(p[i].name);
            }
            System.out.println("#");
        }
    }

    static class P {
        String name;
        double eff;
    }
}

Measured memory_bytes: 37868
#include <bits/stdc++.h>
  
using namespace std;
  
int mergeSort(int left, int right)
{
  if(left + 1 < right) {
    int mid = (left + right) >> 1;
    return (mergeSort(left, mid) + mergeSort(mid, right) + right - left);
  } else {
    return (0);
  }
}
  
int main()
{
  int N, A[500000];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) scanf("%d", &A[i]);
  sort(A, A + N);
  for(int i = 0; i < N; i++) {
    if(i > 0) putchar(' ');
    printf("%d", A[i]);
  }
  putchar('\n');
  printf("%d\n", mergeSort(0, N));
}

Measured memory_bytes: 5112
def main():
    n = int(input())
    odds = [i for i in range(1, n+1) if i % 2 != 0]
    ans = 0
    for i in odds:
        count = 0
        for j in range(1, i + 1):
            if i % j == 0:
                count += 1
        if count == 8:
            ans += 1
    print(ans)


main()

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
int odd(int x){
  if(x % 2 == 0){
    return x / 2;
  }
  else{
    return 3 * x + 1;
  }
}

int main(){
  int s;
  cin >> s;
  vector<int>a(10000);
  a.at(0) = s;
  int g;
  g = 0;
  
  bool jud = false;
  for(int i = 1; i < 10000; i++){
    for(int j = 0; j < i; j++){
    a.at(i) = odd(a.at(i-1));
    if(a.at(i) == a.at(j)){
      g = i;
      jud = true;
    }
    }
    if(jud){
        break;
      }
  }
  cout << g + 1 << endl;
}
   

Measured memory_bytes: 256
a,b,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=min(arr1)+min(arr2)
for _ in range(m):
  x,y,c=map(int,input().split())
  tmp=arr1[x-1]+arr2[y-1]-c
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 70508
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double money[] = new double[N];
		String unit[] = new String[N];
		double ot[] = new double[N];
		double sum = 0;
		for (int i = 0; i < money.length; i++){
			money[i] = sc.nextDouble();
			unit[i] = sc.next();
			
		}
 
		for (int j = 0; j < money.length; j++){
			if(unit[j].equals("BTC")){
				ot[j] = money[j] * 380000.0;
			}
			else if(unit[j].equals("JPY")){
				ot[j] = money[j];
			}else{
System.out.println("DEBUG");
}
		}
		for (int k = 0; k < ot.length; k++){
			sum += ot[k];
 
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 37268
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<string> title(n);
    vector<li> length(n);

    for (int i = 0; i < n; ++i) {
        cin >> title[i] >> length[i];
    }
    
    string x;
    cin >> x;
    
    li ans = 0;

    bool add = false;
    for (int i = 0; i < n; ++i) {
        if (add) {
            ans += length[i];
        }
        if (title[i] == x){
            add = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
using namespace std;

typedef long long ll;

int A,B,C;
int X[3];
int main() {
  cin >>X[0]  >> X[1] >> X[2];
  int cnt = 0;
  int len = 10;
  while(1){
    if ( X[0] == X[1] && X[1] == X[2] ) break;
    sort(X,X+3);
    //cout << X[0] << " " << X[1] << " " << X[2] << endl;
    if ( X[2] - X[0] >= 2 ){
      X[0]+=2;
      cnt++;
    }else if( X[2]-X[0] == 1 && X[2]-X[0] == 1 ) {
      X[0]++;
      X[1]++;
      cnt++;
    } else if ( X[2] -X[1] == 1 && X[1] - X[0] == 1 ) {
      X[0]++;
      X[1]++;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	var N int
	S := make(map[string]int)
	var st string

	N = nextInt()
	for i := 0; i < N; i++ {
		st = nextStr()
		_, exist := S[st]
		if exist {
			S[st]++
		} else {
			S[st] = 0
		}
	}
	slice1 := make([]string, len(S))
	slice2 := make([]int, len(S))
	index := 0
	for key, val := range S {
		slice1[index] = key
		slice2[index] = val
		index++
	}
	sort.Strings(slice1)
	sort.Ints(slice2)
	for _, key := range SortedKeys(S) {
		if S[key] == slice2[len(slice2)-1] {
			fmt.Println(key)
		}
	}

}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	i := stdin.Text()
	// if err != nil {
	// 	panic(err)
	// }
	return i
}

func SortedKeys(mapInt interface{}) []string {
    values := reflect.ValueOf(mapInt).MapKeys()
    result := make([]string, len(values))
    for i, value1 := range values {
        result[i] = value1.String()
    }
    sort.Strings(result)
    return result
}


Measured memory_bytes: 29456
import sys
sys.setrecursionlimit(10**6)
N = int(input())
*A, = map(int, input().split())
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

def calc(S):
    if not S:
        return 0
    S.sort(reverse=1)
    if S[0] > sum(S[1:]):
        return sum(S[1:])
    return sum(S)//2
ok = 1
def dfs(v, p):
    global ok
    c = A[v]
    S = []
    for w in G[v]:
        if w == p:
            continue
        S.append(dfs(w, v))
    if not S:
        return c
    d = calc(S)
    s = sum(S)
    k = s - c
    if not 0 <= k <= d:
        ok = 0
    return s - 2*k
import random
random.seed()
*r, = range(N)
random.shuffle(r)
d = {}
for i in range(2):
    dfs(r[i], -1)

if ok:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 133152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>s;
	s+='p';
	if(s[0]=='R' && s[1]=='R' && s[2]=='R')
		cout<<"3\n";
	else if(s[1]=='S' && (s[0]=='R' || s[2]=='R'))
		cout<<"1\n";
	else if(s[1]=='R' && (s[0]=='R' || s[2]=='R'))
		cout<<"2\n";
	else if(s[1]=='R' && (s[0]=='S' && s[2]=='S'))
		cout<<"1\n";
	else cout<<"0\n";
	return 0;
}

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

using namespace std;

typedef pair <int,int>	PII;
typedef vector <int>	VI;
typedef vector <PII>    VII;

const int MD=998244353;
const int INF = 1e7+9;

const int N=1e7+33;

long long p,n,k,h,w;
vector<long long> pr={2};




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

	for(int i=3;i<1e6+50;i+=2){
        bool is=1;
        for(int j=0;pr[j]<=sqrt(i);j++){
            if(i%pr[j]==0){is=0;break;}
        }
        if(is){/*cout<<i<<endl;*/pr.push_back(i);}
	}

	cin>>n>>p;
	if(n==1){cout<<p;return 0;}
	long long gg=1;
	for(int i=0;p>1 && i<pr.size();i++){
        int q=0;
        while(p%pr[i]==0){
            q++;
            p/=pr[i];
        }
        gg*=(int)pow(pr[i],(int)q/n);
	}
	cout<<gg;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#define MAX 100001
#define SENTINEL 2000000000
using namespace std;


int solved[MAX];

int fib(int n){
    for(int i = 0; i <= n; i++){
        if(i == 0) {
            solved[i] = 1;
            continue;
        };
        if(i == 1) {
            solved[i] = 1;
            continue;
        };
        solved[i] = solved[i - 1] + solved[i - 2];
    }
    return solved[n];
}

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

    int r = fib(n);
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int debt = 100000;
  for (int i = 0; i < n; i++) {
    debt *= 1.05;
    debt = (debt + 999) / 1000 * 1000;
  }
  cout << debt << endl;
  return 0;
}


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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<pll> A(n);
  for(ll i=0;i<n;i++) {
    ll a,b;
    cin >> a >> b;
    A.at(i)=pll(a,b);
  }
  sort(A.begin(),A.end());
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(A[i].second<m) {
      m-=A[i].second;
      ans+=A[i].first*A[i].second;
    }
    else {
      ans+=A[i].first*m;
      m=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int g[5][5];
int main(){
  string s;
  vector<int> v;
    cin >> s;
    for(int i=0; i<s.size(); i++){
      if(s[i]=='W')
        v.push_back(i);
    }
    ll cnt=0;
    for(int i=0; i<v.size(); i++){
      cnt += v[i]-i;
      //cout << v[i]-i << endl;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int h,w,x,y;cin>>h>>w>>x>>y;
	puts(h*x%2==1&&(x+y)%2==1?"No":"Yes");
}


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

using namespace std;
using namespace __gnu_pbds;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool a) {
    return a ? "T" : "F";
}

string to_string(const char* s) {
    return to_string((string) s);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

#define X first
#define Y second

using ll = long long;
using ld = long double;

const int N = 2010;
const int inf = 1e9 + 10;

int n;
int c[N << 1], a[N << 1];
int f[N][N], cost[2][N][N];
int ps[2][N];

void run() {
    cin >> n;
    for (int i = 1; i <= 2 * n; ++i) {
        string s;
        cin >> s >> a[i];
        c[i] = (s[0] == 'W');
    }

    for (int i = 1; i <= 2 * n; ++i) {
        ps[c[i]][a[i]] = i;
    }
    
    for (int i = 0; i < n; ++i) {
        for (int x = 1; x < i + 1; ++x) {
            if (ps[0][i + 1] < ps[0][x]) {
                ++cost[0][i][0];
            }
        }
        for (int j = 1; j <= n; ++j) {
            cost[0][i][j] = cost[0][i][j - 1] + (ps[1][j] > ps[0][i + 1]);
        }
    }
    
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) cout << cost[0][i][j] << " "; cout << endl;
    }*/

    for (int j = 0; j < n; ++j) {
        for (int x = 1; x < j + 1; ++x) {
            if (ps[1][j + 1] < ps[1][x]) {
                ++cost[1][0][j];
            }
        }
        for (int i = 1; i <= n; ++i) {
            cost[1][i][j] = cost[1][i - 1][j] + (ps[0][i] > ps[1][j + 1]);
        }
    }
    
    /*
    for (int j = 0; j < n; ++j) {
        for (int i = 0; i <= n; ++i) cout << cost[1][i][j] << " "; cout << endl;
    }*/

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            f[i][j] = inf;
        }
    }

    f[0][0] = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i)
                mini(f[i][j], f[i - 1][j] + cost[0][i - 1][j]);
            if (j)
                mini(f[i][j], f[i][j - 1] + cost[1][i][j - 1]);
        }
    }

    cout << f[n][n] << endl;
}

int main() {
    run();
    return 0;
}


Measured memory_bytes: 47616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	long long N, K;
	cin >> N >> K;
	long long ans= K * pow(K - 1, N - 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/02/09
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, k;

    scanf("%d %d", &n , &k);

    if (n & 1) {
    	n += 1;
    }

    if ((n/2) >= k) {
    	printf("YES\n");
    } else {
    	printf("NO\n");
    }
	return 0;
}


Measured memory_bytes: 128
#include<iostream>

char S[3];
char T[3];
int count=0;
int main(){
  for(int i=0;i<3;i++){
    std::cin >> S[i];
  }
  for(int i=0;i<3;i++){
    std::cin >> T[i];
  }
  for(int i=0;i<3;i++){
    if(S[i]==T[i]){
      count+=1;
    }
  }
  std::cout << count << std::endl;
}


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

typedef long long ll;

int main(){
    ll X, Y;
    cin >> X >> Y;

    ll i = X, ans = 0;
    while(1){
        if(i > Y)
            break;
        i *= 2;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string> 
using namespace std; 
int main(){ string str; 
int n; 
while(cin >> str){ if(str=="-") break; 
cin >> n; 
for(int i=0,h;i<n;i++){ cin >> h;
 string cat = str.substr(0,h); 
str.erase(0,h); str+=cat;
 } 
cout << str << endl;
 } 
} 


Measured memory_bytes: 3172
#include <iostream>

using namespace std;

int main()
{
    int num, a, i;

    cin >> num;
    for (i = 0; i < num; i++) {
        cin >> a;
        if (!(a & 1)) {
            if (a % 3 != 0 && a % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;

    return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    r = inp()
    print(r*2*math.pi)
    
if __name__ == "__main__":
    main()

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int n;
    cin >> n;

    if ( ( n % 2 ) != 0 ) {
        cout << 0 << endl;
        return 0;
    }

    long long int ans = 0;
    for ( long long int i = 10; i <= n; i *= 5 ) {
        ans += n / i;
    }


    cout << ans << endl;

    return 0;

}


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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

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

const int S[][5] = {0, 0, 0, 0, 0,
                    0, 0, 1, 0, 0, 
                    0, 1, 1, 1, 0,
                    0, 0, 1, 0, 0,
                    0, 0, 0, 0, 0};

const int M[][5] = {0, 0, 0, 0, 0,
                    0, 1, 1, 1, 0,
                    0, 1, 1, 1, 0,
                    0, 1, 1, 1, 0,
                    0, 0, 0, 0, 0};

const int L[][5] = {0, 0, 1, 0, 0,
                    0, 1, 1, 1, 0,
                    1, 1, 1, 1, 1,
                    0, 1, 1, 1, 0,
                    0, 0, 1, 0, 0};

const int (*diff[3])[5] = {S, M, L};

int m[N][N] = { 0 };

int main(void){
    char c;
    for(int x, y, t; cin >> x >> c >> y >> c >> t;){
        x -= 2; y -= 2;
     
        rep(dy, 5) rep(dx, 5)
            if(0 <= x + dx && x + dx < N &&
               0 <= y + dy && y + dy < N)
                m[y + dy][x + dx] += diff[t - 1][dy][dx];
    }
 
    cout << count(&m[0][0], &m[0][0] + N * N, 0) << endl << *max_element(&m[0][0], &m[0][0] + N * N) << endl;
    return 0;
}

Measured memory_bytes: 1160
mod=10**9+7
n,m=map(int,input().split())
A=[int(input()) for _ in range(m)]
A=set(A)
DP=[0]*(n+1)
DP[0]=1
if A:
    if 1 not in A:
        DP[1]=1
    for i in range(2,n+1):
        if i not in A:
            DP[i]=DP[i-1]+DP[i-2]
            DP[i]%=mod
    print(DP[-1])
else:
    DP[1]=1
    for i in range(2,n+1):
        DP[i]=DP[i-1]+DP[i-2]
        DP[i]%=mod
    print(DP[-1])

Measured memory_bytes: 56664
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<char> ch(n);
    int white=0, red=0;
    for(int i=0; i<n; i++){
        cin>>ch[i];
        if(ch[i] == 'R'){
            red++;
        }
        else{
            white++;
        }
    }
    int val=0;
    for(int i=n-1; i>(n-1-white); i--){
        if(ch[i]=='R'){
            val++;
        }
    }
    cout<<val<<'\n';
    return 0;
}

Measured memory_bytes: 3604
//
//  main.cpp
//  sample
//
//  Created by 陈楚凡 on 2019/5/11.
//  Copyright © 2019 陈楚凡. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

string s;
int a[2];
int k;

int main() {
  cin >> s;
  for (int t = 0; t < s.size(); t++) {
    if(k) {
      if (s[t] == '1') a[0]++;
      if (s[t] == '0') a[1]++;
      k--;
    }
    else {
      if (s[t] == '0') a[0]++;
      if (s[t] == '1') a[1]++;
      k++;
    }
  }
  cout << min(a[0], a[1]);
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
	if (x == 0) return 0;
	return counter(x >> 1) + (x & 1);
}

void solve() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		for (int j = 1; j <= A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	int ans = 0;
	for (int bits = 1; bits < (1 << N); bits++) {
		bool ok = true;
		for (int i = 1; i <= N; i++) {
			if (!(bits & (1 << (i - 1)))) continue;
			for (int j = 1; j <= A[i]; j++) {
				if (((bits >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = false;
			}
		}
		if (ok) ans = max(ans, counter(bits));
	}
	cout << ans << endl;
	return;
}

int main(void) {
	solve();


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int P[N * N];
  for (int i = 0; i < N * N; i++) cin >> P[i], P[i]--;
  auto node = [&](int i, int j) { return N * i + j; };
  auto ij = [&](int v) { return make_pair(v / N, v % N); };
  pair<int, int> dir[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int cost[N * N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cost[node(i, j)] = min({i + 1, N - i, j + 1, N - j});
    }
  }
  bool rem[N * N];
  fill(rem, rem + N * N, true);
  // debugArray(cost, N * N);
  int ans = 0;
  for (int p : P) {
    rem[p] = false;
    queue<pair<int, int>> que;
    int pc = cost[p];
    int pci, pcj;
    tie(pci, pcj) = ij(p);
    for (int d = 0; d < 4; d++) {
      int ni = pci + dir[d].first, nj = pcj + dir[d].second;
      int c = 0;
      if (!(ni < 0 || N <= ni || nj < 0 || N <= nj)) c = cost[node(ni, nj)];
      if (pc > c + rem[p]) {
        pc = c + rem[p];
      }
    }
    que.push({p, pc});
    while (!que.empty()) {
      int v, c;
      tie(v, c) = que.front();
      que.pop();
      if (cost[v] <= c) continue;
      cost[v] = c;
      int ci, cj;
      tie(ci, cj) = ij(v);
      for (int d = 0; d < 4; d++) {
        int ni = ci + dir[d].first, nj = cj + dir[d].second;
        if (ni < 0 || N <= ni || nj < 0 || N <= nj) continue;
        int next = node(ni, nj);
        if (cost[next] > cost[v] + rem[next])
          que.push({next, cost[v] + rem[next]});
      }
    }
    ans += cost[p];
    // debugArray(cost, N * N);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5868
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int k,s;
  cin>>k>>s;
  
  int cnt=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(0<=s-x-y && s-x-y<=k) cnt++;
    }
  }
  cout<<cnt<<endl;
       
  return 0;
}

Measured memory_bytes: 3640
x0,y0,x1,y1 = map(int,input().split())
x1 -= x0
y1 -= y0
ans = ''
ans += 'R' * x1
ans += 'U' * y1
ans += 'L' * x1
ans += 'D' * y1
ans += 'D'
ans += 'R' * x1
ans += 'R'
ans += 'U' * y1
ans += 'U'
ans += 'L'
ans += 'U'
ans += 'L' * x1
ans += 'L'
ans += 'D' * y1
ans += 'D'
ans += 'R'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int A = 0;
  int B = 0;
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(C.begin(), C.end(), greater<int>());
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      A += C[i];
    } else {
      B += C[i];
    }
  }
  int result = A - B;
  cout << result << endl;
}

Measured memory_bytes: 256
n = int(input())
nums = []
for i in range(1, n+1):
    if i%3 == 0:
        nums.append(i)
    elif '3' in list(str(i)):
        nums.append(i)
m = len(nums)
print('', end = ' ')
for i in range(m-1): 
    print(nums[i], end = ' ')
print(nums[m-1])



Measured memory_bytes: 6108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

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

int main() {
	string s;
	cin >> s;
	VREVERSE(s);
	string d[4] = { "dream","dreamer","erase","eraser" };
	REP(i, 4) {
		VREVERSE(d[i]);
	}
	int l = s.length();
	for (int i=0; i < l;) {
		bool can = false;
		REP(j, 4) {
			if (s.substr(i, d[j].length()) == d[j]) {
				can = true;
				i += d[j].length();
			}
		}
		if (!can) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}



Measured memory_bytes: 512
n,m = map(int,input().split())
a = [list(map(int,input().split()))for x in range(n)]
b = [list(map(int,input().split()))for x in range(m)]
for x in range(n):
    c = []
    for y in range(m):
        c.append(abs(a[x][0]-b[y][0]) + abs(a[x][1]-b[y][1]))
    print(c.index(min(c))+1)

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

int main () {
    long long n, res = 0, min = 1000000000, num = 0, temp;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        if (temp < 0) num++;
        res += abs(temp);
        if (abs(temp) < min) min = abs(temp);
    }
    if (num % 2) cout << res - 2 * min << endl;
    else cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n as
  print ans

compute :: Int -> [Int] -> Int
compute n (a:as) = loop 0 a as

loop c _ [] = c
loop c p (a:as)
  | p <= a = loop c a as
  | True = let c1 = c + p - a in seq c1 $ loop c1 p as

Measured memory_bytes: 10196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll M;
    cin >> M;
    vector<ll> d(M), c(M);
    rep(i,M) cin >> d[i] >> c[i];
    ll all_sum = 0;
    rep(i,M) all_sum += (d[i] * c[i]);
    ll ans = 0;
    rep(i,M) ans += c[i];
    ll min_ll = 0;
    ans += max(min_ll, (all_sum + 8) / 9 - 1);
    cout << ans - 1 << endl;
}

Measured memory_bytes: 6424