akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	ll A[200200];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	
	ll max = 0;
	ll ans = 0;
	for(int i = 0; i < N; i++){
		if(max > A[i]){
			ans += max - A[i];
		}else{
			max = A[i];
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 5208
import java.util.Scanner;

class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args)
	{
		double x1,x2,x3,y1,y2,y3,a1,a2,b1,b2,c1,c2,xp,yp,r;
		int n = sc.nextInt();
		
		for(int i=0;i<n;i++)
		{
			x1 = sc.nextDouble();
			y1 = sc.nextDouble();
			x2 = sc.nextDouble();
			y2 = sc.nextDouble();
			x3 = sc.nextDouble();
			y3 = sc.nextDouble();
			
			a1 = 2*(x2-x1);
			a2 = 2*(x3-x1);
			b1 = 2*(y2-y1);
			b2 = 2*(y3-y1);
			c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
			c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;
			
			xp = (b1*c2 - b2*c1)/(a1*b2 - a2*b1);
			yp = (c1*a2 - c2*a1)/(a1*b2 - a2*b1);
			
			r = Math.hypot(xp-x1, yp-y1);
			
			System.out.printf("%.3f %.3f %.3f\n", xp,yp,r);
		}
	}
}

Measured memory_bytes: 11000
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,a,b;
    cin>>a>>b;
   if(b%a)
    cout<<b-a<<endl;
   else cout<<a+b<<endl;

    return 0;
}





Measured memory_bytes: 3652
a = int(input())
b = []
b.append(a)
n = 1
c = 0
while(not c in b):
        if b[n-1]%2 == 0:
                b.append(b[n-1]/2)
        else:
                b.append(3*b[n-1]+1)
        if b[n]%2 == 0:
                c = b[n]/2
        else:
                c = 3*b[n]+1
        n += 1
print(n+1)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n, k;
scanf("%d%d", &n, &k);
for(int i = 0; i < k; ++i) {
int a, b;
scanf("%d%d", &a, &b);
a = min(a, n + 1 - a);
b = min(b, n + 1 - b);
int x = min(a, b);
printf("%d\n", (x - 1) % 3 + 1);
}
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else
	{
		cout<<"No"<<endl;
		return 0;
	}
	return 0;
 } 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x;
    while(true){
	cin>>x;
	int sum=0;
	if(x=="0")
	    break;
	rep(i,x.size()){
	    int a=x[i]-'0';
	    sum+=a;
	}
	cout<<sum<<'\n';
    }
	return(0);
}



Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX
using namespace std;

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(ll (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;

/* 2017/01/29 問題 ----- ABC036 D /Link http://abc036.contest.atcoder.jp/tasks/abc036_d */
/* -----解説等-----
問題: N 個の島があります。 島には 1 から N までの番号がついています。
また、N−1 個の橋があります。 i 番目の橋は ai 番の島と bi 番の島をつないでいます。
どの島からどの島へも橋をいくつか経由して到達できることがわかっています。

すぬけ君は、それぞれの島を白または黒に塗ることにしました。
ただし、両端の島が黒で塗られているような橋があってはいけません。
色の塗り方が何通りあるか、10^9+7 で割った余りを求めてください。


*/

int N;
ll dp[100010][2];
vector<int>x[100010];
ll ans = 0;
enum { White, Black };

ll dfs(int v, int p, int c) {

	if (dp[v][c] >= 0)return dp[v][c];
	if (x[v].size() == 1 && x[v][0] == p)return 1;

	dp[v][c] = 1;
	FOR(i, 0, x[v].size()) {
		int w = x[v][i];

		if (w == p)continue;
		ll a = 0;
		a = (a + dfs(w, v, White)) % MOD;
		if (c != Black) {
			a = (a + dfs(w, v, Black)) % MOD;
		}
		dp[v][c] = (dp[v][c] * a) % MOD;
	}

	return dp[v][c];
}

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

	cin >> N;
	int s, t;
	FOR(i, 0, N - 1) {
		cin >> s >> t;
		s--; t--;
		x[s].push_back(t);
		x[t].push_back(s);
	}

	FOR(i, 0, 100010)FOR(j, 0, 2)dp[i][j] = -1;

	ans = (dfs(0, -1, White) + dfs(0, -1, Black)) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>  
 
using namespace std;
 
//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
 
const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
 
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int a, b;
    cin >> a >> b;
    if(a <= b) cout << 0 << endl;
    else cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
 
class Program
{
  static void Main(string[] args)
  {
    string c = Console.ReadLine();
    
    if(c == "a" || c == "i" || c == "u" || c == "e" || c == "o")
    {
      Console.WriteLine("vowel");
    }
    else
    {
      Console.WriteLine("consonant");
    }
  }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <utility>
#include <map>
#include <unordered_map>
#include <string>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
#define vmax(c) *max_element(all(c))
#define vmin(c) *min_element(all(c))
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

template<typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2>& map)
{
    for (typename std::map<T1, T2>::const_iterator it = map.begin();
         it != map.end();
         ++it)
    {
        out << (*it);
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 2次元配列を作る
// vector<vi> my_vector(n, vi(m, 0));

// 多次元配列の dump
// for (auto v : my_vector) {
//     cout << v;
// }

ll N;

auto solve() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << ((H - h) * (W - w));
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // cout << solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int p[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&p[i]);
    }

    int wrong = 0;
    for(int i = 0;i < n;i++){
        if(p[i] != i + 1){
            wrong ++;
        }
    }
    if(wrong <= 2 && wrong % 2 == 0){
        printf("YES");
    } else {
        printf("NO");
    }
}

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

int main() {
  string s;
  cin >> s;
  int diff = 0;
  int i;
  for (i = 0; i < s.length() - 1; i++) {
    if (s.at(i) != s.at(i + 1)) {
      diff++;
    }
  }
  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N, i; cin>>N>>i;
  cout << N-i+1	<< endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	vpll a(n);
	rep(i,n){
		ll x,y;
		cin >> x >> y;
		a[i]=m_p(x,y);
	}
	sort(all(a));
	map<pair<ll,ll>,ll> m;
	rep(i,n-1){
		for(ll j=i+1;j<n;j++){
			ll dx=a[j].first-a[i].first;
			ll dy=a[j].second-a[i].second;
			m[m_p(dx,dy)]++;
		}
	}
	ll ans=0;
	for(auto&& e:m) chmax(ans,e.second);
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();
    /*
    */

    @SuppressWarnings("unchecked")
    Set<Integer>[] g = new Set[N + 1];
    int[] fc = new int[N + 1];
    for (int i = 0; i < M; i++) {
      int a = A[i];
      int b = B[i];
      if (g[a] == null && g[b] == null) {
        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        g[a] = set;
        g[b] = set;
      } else if (g[a] == null) {
        Set<Integer> set = g[b];
        set.add(a);
        g[a] = set;
      } else if (g[b] == null) {
        Set<Integer> set = g[a];
        set.add(b);
        g[b] = set;
      } else if (g[a] != g[b]) {
        Set<Integer> setL = g[a];
        Set<Integer> setS = g[b];
        if (setL.size() < setS.size()) {
          Set<Integer> temp = setL;
          setL = setS;
          setS = temp;
        }
        setL.addAll(setS);
        for (int c : setS) g[c] = setL;
      }
      fc[a]++;
      fc[b]++;
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = C[i];
      int d = D[i];
      if (g[c] == g[d]) {
        bc[c]++;
        bc[d]++;
      }
    }
    /*
    sc.close();
    */

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      if (g[i] != null)
        ans[i] = g[i].size() - 1 - fc[i] - bc[i];

//    StringBuilder buf = new StringBuilder();
    for (int i = 1; i < N + 1; i++) {
      System.out.print(ans[i]);
      System.out.print(" ");
    }
    System.out.println();
//      buf.append(ans[i]).append(' ');
//    System.out.println(buf);
  }
}

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

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

  vector<int> h(N);
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
  }

  int count = 0;
  for(int i = 0; i < N; i++){
    if(h.at(i) >= K){
      count++;
    }
  }

  cout << count << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

const int maxn = 3005;
ll dp[maxn][maxn];

void solve() {
	ll n, s = 0;
	cin >> n;
	vl a(n);
	rep(i, n) {
		cin >> a[i];
		s += a[i];
	}

	FOR(len, 1, n)
		FOR(i, 0, n - len) {
			int j = i + len - 1;
			if (len == 1) dp[i][j] = a[i];
			else if (len == 2) dp[i][j] = max(a[i], a[j]);
			else {
				dp[i][j] = max(a[i] + min(dp[i+1][j-1], dp[i+2][j]), 
								a[j] + min(dp[i][j-2], dp[i+1][j-1]));
			}
		}

	cout << 2 * dp[0][n-1] - s << endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 70016
#include <iostream>
#include <bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define debug(a) cout<<a<<'\n'
typedef pair<int,int> pii;
typedef long long ll;
#define PB push_back
#define II second
#define I first
#define MP make_pair
int main() {
	//code
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
        cin>>a[i][j];
    int dp[n][3];
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            dp[i][j]=0;
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	vector<int> coin(N + 1, N * 2);
	coin[0] = 0;

	int nums[] = { 6, 9 };

	for (int n = 1; n <= N; n++)
	{
		for (int i = 0; i < 2; i++)
		{
			int x = nums[i];

			int power = 1;
			while (power <= n)
			{
				coin[n] = min(coin[n], coin[n - power] + 1);

				power *= x;
			}
		}
	}

	cout << coin[N] << endl;

	return 0;
}

Measured memory_bytes: 640
from operator import itemgetter

def BellmanFord(edges,num_v,source):
  #グラフの初期化
  inf=float('inf')
  dist=[inf for i in range(num_v)]
  dist[source-1]=0

  #辺の緩和
  for i in range(num_v+1):
    for edge in edges:
      if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
        dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
        if i==num_v and edge[1]==num_v: return -1

  return dist


#%%
N,M = [int(x) for x in input().split()]
edges = []
for _ in range(M):
    l = [int(x) for x in input().split()]
    l[2]*=-1
    edges.append(l)
#%%
route = BellmanFord(edges,N,1)
if(route == -1):
    print('inf')
else:
    print(-int(route[N-1]))


Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    string input;
    is >> input;
    int max_pluses_count = sz(input) - 1;
    ui64 answer = 0;
    rep(i, 0, 1 << max_pluses_count) {
        ui64 num = input[0] - '0';
        rep(j, 0, max_pluses_count) {
            if (i & (1 << j)) {
                answer += num;
                num = 0;
            }
            num = (num * 10) + (input[j + 1] - '0');
        }
        answer += num;
    }
    os << answer;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

        string target = "ABC";
        int idx = 0;
        int ans = 0;

        for (int i=0; i<s.size(); i++) {
                if (s[i] == 'A') {
                        idx = 1;
                        continue;
                }
                if (s[i] == target[idx]) {
                        if (idx == 2) {
                                idx = 0;
                                ans++;
                                continue;
                        }
                        idx++;
                } else {
                        idx = 0;
                }
        }

        printf("%d\n", ans);
}


Measured memory_bytes: 888
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

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

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

int main(){
  double W, H, x, y; cin >> W >> H >> x >> y;
  printf("%.6f %d\n", W*H/2.0, (x+x==W&&y+y==H));
  return 0;
}


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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int l, r, d;
    int ans = 0;
    cin >> l >> r >> d;
    rep(i, 200) {
        if (i * d >= l && i * d <= r) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,f=0,o=0,one=0,e=0,flag=0,md=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
      ll x;
      cin>>x;
      if(x%4==0)
        md++;
      else if(x==1)
        one++;
      else if(x%2==0)
        e++;
      else if(x&1)
        o++;

    }
    ll y=md+1-(one+o);
    if(one+o>md+1||y<e%2)
      flag=1;
    if(flag)
      No
    else
      Yes

}
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

int main(){
	ll n,h,w;
	cin>>n>>h>>w;
	ll ans=0;
	vector<ll>a,b;
	ll aa,bb;
	for(int i=0;i<n;i++){
		cin>>aa>>bb;
		if(aa>=h&&bb>=w)ans++;
	}
	cout<<ans<<endl;
}


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

int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    int a[q],ans[n],score[n];

    for(int i=1;i<n+1;i++){
        ans[i]=0;
        score[i]=k;}
    for(int i=1;i<q+1;i++)
      {
       cin>>a[i];
       ans[a[i]]+=1;}
    for(int i=1;i<n+1;i++)
    {
        score[i]= score[i]-(q-ans[i]);
        if(score[i]>0)
            cout<<"Yes"<<"\n";

        else
            cout<<"No"<<"\n";
}}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>
long double pi = boost::math::constants::pi<long double>();
using namespace std;
typedef long long ll;
int N, M;
int A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
vector<int> x, y;
bool mpx[6020][6020], mpy[6020][6020];
bool mp[6020][6020];
queue<pair<int, int>> que;
int main() {
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        x.push_back(A[i]);
        x.push_back(B[i]);
        y.push_back(C[i]);
    }
    for (int i = 1; i <= M; i++) {
        cin >> D[i] >> E[i] >> F[i];
        x.push_back(D[i]);
        y.push_back(E[i]);
        y.push_back(F[i]);
    }
    x.push_back(0);
    y.push_back(0);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for (int i = 1; i <= N; i++) {
        A[i] = lower_bound(x.begin(), x.end(), A[i])-x.begin();
        B[i] = lower_bound(x.begin(), x.end(), B[i])-x.begin();
        C[i] = lower_bound(y.begin(), y.end(), C[i])-y.begin();
        for (int a = A[i]*2+1; a < B[i]*2; a++) {
            mpy[a][C[i]*2] = 1;
        }
        int x = A[i]*2, y = C[i]*2;
        if (x-1 >= 0 && mpy[x-1][y]) {
            mpy[x][y] = 1;
        }
        x = B[i]*2;
        if (mpy[x+1][y]) {
            mpy[x][y] = 1;
        }
    }
    for (int i = 1; i <= M; i++) {
        D[i] = lower_bound(x.begin(), x.end(), D[i])-x.begin();
        E[i] = lower_bound(y.begin(), y.end(), E[i])-y.begin();
        F[i] = lower_bound(y.begin(), y.end(), F[i])-y.begin();
        for (int a = E[i]*2+1; a < F[i]*2; a++) {
            mpx[D[i]*2][a] = 1;
        }
        int x = D[i]*2, y = E[i]*2;
        if (y-1 >= 0 && mpx[x][y-1]) {
            mpx[x][y] = 1;
        }
        y = F[i]*2;
        if (mpx[x][y+1]) {
            mpx[x][y] = 1;
        }
    }
    int s = lower_bound(x.begin(), x.end(), 0)-x.begin();
    int t = lower_bound(y.begin(), y.end(), 0)-y.begin();
    mp[s*2][t*2] = 1;
    que.push(make_pair(s*2,t*2));
    while (que.size()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
        for (int i = 0; i < 4; i++) {
            int nx = dx[i]+x, ny = dy[i]+y;
            if (nx >= 0 && nx < 6020 && ny >= 0 && ny < 6020) {
                if (!mpx[nx][ny] && !mpy[nx][ny] && mp[nx][ny] != 1) {
                    mp[nx][ny] = 1;
                    que.push(make_pair(nx, ny));
                }
            }
            else {
                puts("INF");
                return 0;
            }
        }
    }
    ll ans = 0;
    for (int i = 1, xl = x.size(); (i+1)/2 < xl; i+=2) {
        for (int j = 1, yl = y.size(); (j+1)/2 < yl; j+=2) {
            if (mp[i][j]) {
                ans += ((ll)x[(i+1)/2]-x[(i-1)/2])*((ll)y[(j+1)/2]-y[(j-1)/2]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 79152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int front, back;
		boolean YYMMflg = false;
		boolean MMYYflg = false;

		front = Integer.valueOf(S.substring(0, 2));
		back = Integer.valueOf(S.substring(2, 4));

		// YYMM
		if (0 <= front && front <= 99 && 1 <= back && back <= 12) {
			YYMMflg = true;
		}

		// MMYY
		if (0 <= back && back <= 99 && 1 <= front && front <= 12) {
			MMYYflg = true;
		}

		if (YYMMflg && MMYYflg) {
			System.out.println("AMBIGUOUS");
		} else if (YYMMflg) {
			System.out.println("YYMM");
		} else if (MMYYflg) {
			System.out.println("MMYY");
		} else {
			System.out.println("NA");
		}
	}
}


Measured memory_bytes: 23636
#include<stdio.h>
int main(void)
{
	int i;
	char str[21];
	char strl[4];
	for(i=0;i<20;i++){
		scanf("%c",&str[i]);
	}
	i=i++;
	str[i]=0;
	for(i=0;i<3;i++){
		strl[i]=str[i];
	}
	i=i++;
	strl[i]=0;
	printf("%s",strl);
	
	return 0;
}

Measured memory_bytes: 1668
#import time, sys#
from collections import deque

H, W, N = map(int, input().split())
field = [list(input()) for i in range(H)]
'''
20 30 9
.......X..8.XXXX.XX..XX.X.XX..
X.XX....X.XX..X.X.X....XXXX..X
..X.X..XX..X.....XX.X..X.XX...
....X.X.X.XXX.X..X..X.X..XX.X.
..XXX.XX...X.X....X.X..X..X...
..X...........X.X...X.1.XX...X
.X.X....X..XX..XX......9.X...4
..X....X........X......X......
....XXX.X...XX.X.....X.X..X.X.
..S..XXX..X....X.X.......X..X.
.5...XX..X.X..X....X...XXX....
..X...X.X....X....X..X.2X.....
XXXXXXXX.X.XX..XX..XX.......X.
.....X...........3..XX.XXX.X.X
..X.....X..X..XX.XX..X.X...XX.
...X..X.XXX.XX......X...X..XXX
.X.XX.X.........X.X...X...X..X
..X...X..X..XX..XXX..X.XX...X.
X....X.X....X...X.X..XX.XX..X.
...X6X..X........X.X.....7.X..
'''

#input = input().split('\n')#
#H, W, N = map(int, input.pop(0).split())#
#field = [line for line in input]#
node_posi = [0 for i in range(N+1)]

#s1 = time.time()#
nodes = 'S123456789'
for i in range(H):
	for j in range(W):
		if field[i][j] in nodes:
			node_posi[nodes.index(field[i][j])] = [j, i]
#e1 = time.time()#
#print("b:{}".format(e1-s1))#

cost = 0
#count = 1#
for i in range(len(node_posi)-1):
	#s2 = time.time()#
	searched = [[-1]*W for i in range(H)]
	start, goal = node_posi[i], node_posi[i+1]
	Q = deque([start])
	searched[start[1]][start[0]] = 0
	goal_flag = False
	
	while Q and not goal_flag:
		x, y = Q.popleft()
		goal_flag = False

		for q in range(4):
			nx = x + [1,0,-1,0][q]
			ny = y + [0,1,0,-1][q]
			
			if nx >= 0 and nx < W and ny >= 0 and ny < H:
				if searched[ny][nx] == -1 and field[ny][nx] != 'X':
					Q.append([nx, ny])
					searched[ny][nx] = searched[y][x] + 1
					if ([nx, ny] == goal):
						cost += searched[ny][nx]
						goal_flag = True
						break

			#s = "\n".join(["".join(map(lambda x: str(x)[:1], j)) for j in searched])#
			#sys.stdout.write("\r{}".format(s))#
			#sys.stdout.flush()#
	
	#e2 = time.time()#
	#print("{}:{}".format(count, e2-s2))#
	#count += 1#
print(cost)


Measured memory_bytes: 42372
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define sz(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(15);
    solve();
}

const int INF = 1e18, MAXN = 1e5 + 10;

void solve() {                         
	int n;
	cin >> n;
	vector<vector<double>> pt(n, vector<double>(3));
	for (int i = 0; i < n; ++i) {
	    cin >> pt[i][1] >> pt[i][2];
	    int x = pt[i][1], y = pt[i][2];
		pt[i][0] = atan2(y, x);
	}
	sort(pt.begin(), pt.end());  
		
	vector<vector<double>> tmp = pt;
	for (int i = 0; i < sz(tmp); ++i) {
	    pt.push_back(tmp[i]);
	}	

	int ans = 0;
	for (int len = 1; len <= n; ++len) {
	    for (int i = 0; i < sz(pt) - len + 1; ++i) {
	     	int l = i, r = i + len - 1;
	     	int cx = 0, cy = 0;
	     	for (int j = l; j <= r; ++j) {
	     		cx += pt[j][1], cy += pt[j][2];
	     	}	
	     	ans = max(ans, cx * cx + cy * cy); 
	    }
	}	

	cout << sqrt((double)ans) << endl;
}	


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

int dfs(long long a,int n,int n_3,int n_5,int n_7){
    if(a > n){
        return 0;
    }
    else if(n_3 >0 && n_5 >0 && n_7 > 0){
        return dfs(a*10+3,n,n_3+1,n_5,n_7) + dfs(a*10+5,n,n_3,n_5+1,n_7) + dfs(a*10+7,n,n_3,n_5,n_7+1) + 1;
    }
    else{
        return dfs(a*10+3,n,n_3+1,n_5,n_7) + dfs(a*10+5,n,n_3,n_5+1,n_7) + dfs(a*10+7,n,n_3,n_5,n_7+1);
    }
}

int main(){
    int n;
    cin >> n;
    int ans = dfs(0,n,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int H, W;
string Ss[12], Xs[12], Ys[12];

vector<vector<pii>> pairs;

void makepair(vector<pii> current, int unused, int num_unused, int o) {
    if (num_unused == 0) {
        current.push_back(pii(o, o));
        pairs.push_back(current);
        return;
    }
    if (num_unused == 2) {
        int a;
        rep(i, 12) {
            if ((unused >> i) & 1) {
                a = i;
                break;
            }
        }
        for (int i = a + 1; i < 12; ++i) {
            if ((unused >> i) & 1) {
                current.push_back(pii(a, i));
                break;
            }
        }
        if (o != -1)current.push_back(pii(o, o));
        pairs.push_back(current);
        return;
    }

    int a;
    rep(i, 12) {
        if ((unused >> i) & 1) {
            a = i;
            unused ^= 1 << a;
            break;
        }
    }
    for (int i = a + 1; i < 12; ++i) {
        if ((unused >> i) & 1) {
            current.push_back(pii(a, i));
            unused ^= 1 << i;
            makepair(current, unused, num_unused - 2, o);
            unused ^= 1 << i;
            current.pop_back();
        }
    }
}

int ch[12];

bool havePair(int k) {
    reverse(Ys[k].begin(), Ys[k].end());
    for (int i = k + 1; i < W; ++i) {
        if (Ys[k] == Ys[i]) {
            Ys[k] = "AAA";
            Ys[i] = "AAA";
            return true;
        }
    }
    return false;
}

bool isSym(int k) {
    string tmp = Ys[k];
    reverse(Ys[k].begin(), Ys[k].end());
    return tmp == Ys[k];
}

bool check(vector<pii> p) {
    rep(i, p.size()) {
        ch[i] = p[i].first;
        ch[H - 1 - i] = p[i].second;
    }
    rep(i, W) {
        rep(j, H) {
            Ys[i] += Xs[ch[j]][i];
        }
    }

    bool flag = (W % 2 == 0);
    rep(i, W) {
        if (Ys[i] != "AAA") {
            if (havePair(i))continue;
            if (flag)return false;
            if (isSym(i))flag = true;
            else return false;
        }
    }
    return true;
}

signed main() {
    cin >> H >> W;
    rep(i, H) {
        cin >> Ss[i];
        Xs[i] = Ss[i];
    }

    int unused = 0;
    rep(i, H) {
        unused <<= 1;
        unused++;
    }
    vector<pii> tmp;
    if (H % 2 == 0)
        makepair(tmp, unused, H, -1);
    else {
        rep(i, H) {
            unused ^= 1 << i;
            makepair(tmp, unused, H - 1, i);
            unused ^= 1 << i;
            tmp.clear();
        }
    }

    rep(i, pairs.size()) {
        if (check(pairs[i])) {
            cout << "YES" << endl;
            return 0;
        }
        rep(i, W)Ys[i] = "";
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 1596
#include<cstdio>

using namespace std;

int main(){
    long int n, k;
    scanf("%ld %ld", &n, &k);
    long int ans = 0;
    if (k == 0) {
        printf("%ld\n", n * n);
    } else {
        for(long int i = 1; i <= n; i++){
            if (i > k){
                if (n % i - k + 1 > 0){
                    ans += (n / i) * (i - k) + (n % i - k + 1);
                }else{
                    ans += (n / i) * (i - k);
                }
            } 
        }
        printf("%ld\n", ans);
    }
    
}

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

int main(){
  int n , k;
  cin >> n >> k;
  int ans = 0;
  while(n > k){
    n /= k;
    ans++;
    // cout << n << " ";
  }
  // cout << endl;
  if(n != k) cout << ++ans << endl;
  else cout << ans + 2 << endl;
  return 0;
}

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

#define  fast         ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define  loop(i,m,n)  for(int i=m;i<n;i++)
#define  rloop(i,m,n) for(int i=m;i>=n;i--)
#define  mod          1000000007
#define  mp(x,y)      make_pair(x,y)
#define  pb(x)        push_back(x)
#define  Pop()        pop_back()
#define  F            first 
#define  S            second
#define  B()          begin()
#define  E()          end()

typedef  vector<int>            vi;
typedef  map<int,int>           mi;
typedef  vector<pair<int,int>>  vp;
typedef  pair<int,int>          pi;
typedef  long long              ll;

int main(){
    fast
    int n;
    cin>>n;
    ll a[n];
    loop(i,0,n) cin>>a[i];
    ll res=0,m=0;
    loop(i,0,n){
        m=max(m,a[i]);
        res+=m-a[i];
    }
    cout<<res;
    
    return 0;
}

Measured memory_bytes: 5180
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn dist(p: (usize, usize), q: (usize, usize)) -> i64 {
    let (px, py) = p;
    let (qx, qy) = q;

    (px as i64 - qx as i64).abs() + (py as i64 - qy as i64).abs()
}

fn main() {
    let (H, W, D) = read!(usize, usize, usize);
    let mut A = read![[usize]; H];
    let Q = read!(usize);

    let mut rev = vec![(0, 0); H * W];
    for y in 0..H {
        for x in 0..W {
            A[y][x] -= 1;
            rev[A[y][x]] = (y, x);
        }
    }

    let mut acc = vec![0; H * W + D];
    for i in D..H * W {
        acc[i] += acc[i - D] + dist(rev[i - D], rev[i]);
    }

    debug!(rev, acc);

    for _ in 0..Q {
        let (L, R) = read!(usize, usize);
        let (L, R) = (L - 1, R - 1);

        let mut total = acc[R];
        total -= acc[L];

        println!("{}", total)
    }
}


Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
    int n;
    cin>>n;
    int a[2][n];
    rep(i,0,n)cin>>a[0][i];
    rep(i,0,n)cin>>a[1][i];
    int sum=a[0][0];
    rep(i,0,n)sum+=a[1][i];
    int mx=sum;
    rep(i,1,n){
        sum+=a[0][i]-a[1][i-1];
        if(mx<sum)mx=sum;
    }
    cout<<mx;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
inline bool number(string& s) { return '0' <= s[0] && s[0] <= '9'; }

int main() {
    string s;
    stack<int> sta;

    while (cin >> s) {
        if (number(s)) {
            int a = stoi(s);
            sta.emplace(a);
        } else {
            if (sta.size() < 2) continue;
            int a = sta.top(); sta.pop();
            int b = sta.top(); sta.pop();
            if (s == "+") sta.emplace(b + a);
            if (s == "-") sta.emplace(b - a);
            if (s == "*") sta.emplace(b * a);
        }
    }

    cout << sta.top() << endl;
    return 0;
}


Measured memory_bytes: 3220
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int n , m ;
vector <int> g[N] , tpl ;

bool vis[N] ;
int par[N] ;

void dfs (int v) {
	vis[v] = 1 ;
	for (int u : g[v])
		if (!vis[u]) dfs(u) ;
	tpl.push_back(v) ;
}

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

	cin >> n >> m ;

	for (int i = 0 , u , v ; i < n + m - 1 ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;
		g[u].push_back(v) ;
	}

	for (int i = 0 ; i < n ; i ++)
		if (!vis[i]) dfs(i) ;

	reverse(tpl.begin() , tpl.end()) ;
	
	memset(par , -1 , sizeof par) ;

	for (int v : tpl)
		for (int u : g[v]) par[u] = v ;

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


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

int main() {
  int n, ans=2000000000;
  cin >> n;
  int a, b;
  for(int i=0; i<n; i++){
    cin >> a >> b;
    if(a+b<ans)ans=a+b;
  }
  cout << ans;
  return 0;
}

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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

#define onEdge(i, j) (i == 0 || i == n-1 || j == 0 || j == n-1)
#define inBound(i, j) !(i < 0 || i > n-1 || j < 0 || j > n-1)

vector<pair<int,int>> order;
vector<vector<int>> dist;
vector<vector<bool>> seats;
vector<vector<bool>> inq;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};
int n;

void updDist(int x1, int y1){
	queue<pair<int,int>> q;
	q.push({x1, y1});
	inq[x1][y1] = 1;
	while (!q.empty()){
		auto u = q.front();
		q.pop();
		int x = u.first; int y = u.second;
		inq[x][y] = 0;
		for (int d = 0; d < 4; d++){
			int x2, y2;
			x2 = x + dx[d];
			y2 = y + dy[d];
			if (inBound(x2,y2)){
				int newDist = dist[x][y] + seats[x2][y2];
				if (newDist < dist[x2][y2]){
					dist[x2][y2] = newDist;
					if (!inq[x2][y2]){
						inq[x2][y2] = 1;
						q.push({x2, y2});
					}
				}
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>n;
	order.resize(n*n);
	seats.assign(n, vector<bool>(n, 1));
	dist.assign(n, vector<int>(n, INF));
	inq.assign(n, vector<bool>(n, 0));
	for (auto &it: order){
		int a;
		cin>>a;
		a--;
		int x = a/n;
		int y = a%n;
		it.first = x; it.second = y;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			// if (onEdge(i, j)){
			// 	dist[i][j] = 0;
			// 	updDist(i, j);
			// }
			dist[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
			// cout<<dist[i][j];
		}
		// cout<<'\n';
	}
	int ans = 0;
	for (auto u: order){
		ans += dist[u.first][u.second];
		dist[u.first][u.second]--;
		seats[u.first][u.second] = 0;
		updDist(u.first, u.second);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> vec(N, vector<int>(2));
  rep(i, N){
    cin >> vec.at(i).at(0) >> vec.at(i).at(1);
  }
  rep(i, N - 2){
    if(vec.at(i).at(0) == vec.at(i).at(1) && vec.at(i + 1).at(0) == vec.at(i + 1).at(1) && vec.at(i + 2).at(0) == vec.at(i + 2).at(1)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a(n), ca(n+1,0), b(m), cb(m+1,0);
    for(ll i=0; i<n; ++i){
        cin >> a[i];
        ca[i+1] = ca[i] + a[i];
    }
    for(ll i=0; i<m; ++i){
        cin >> b[i];
        cb[i+1] = cb[i] + b[i];
    }
    ll j = m;
    ll score = 0;
    for (ll i=0; i<n+1; ++i){
        ll score_tmp=ca[i] + cb[j];
        while( (score_tmp > k) && (j>0) ){
            --j;
            score_tmp=ca[i] + cb[j];
        }
        if (score_tmp > k) continue;
        score = max(score, i+j);
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 9220
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

wa = 0
kazu = 10**9 + 7
for i in range(60):
    b = int((a & 1).sum())
    wa = (wa + b*(n-b)*(1<<i)) % kazu
    a = a >> 1

print(wa)

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

typedef long long ll;

ll x[8],y[8];

double dist(ll i,ll j){
    double dx = x[i-1] - x[j-1];
    double dy = y[i-1] - y[j-1];
    return pow(dx*dx+dy*dy,0.5);
}

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

    ll n;
    cin >> n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin >> x[i] >> y[i];
        v[i] = i + 1;
    }
    double sum = 0.0;
    do{
        for(ll i=0;i<n-1;i++){
            sum += dist(v[i],v[i+1]);
        }
    }while(next_permutation(v.begin(),v.end()));
    ll factorial = 1;
    for(ll i=2;i<=n;i++) factorial *= i;
    printf("%.10lf\n",sum/factorial);
    return 0;
}

Measured memory_bytes: 384