akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll a,b,c,k;
    ll ans=0;
    cin >> a >> b >> c >> k;
    if(k-a>=0){
        ans += a;
    }
    else ans += k;
    k -= a;
    k -= b;
    if(k<0){
        cout << ans << endl;
        return 0;
    }
    if(k-c>=0){
        ans += -c;
    }
    else{
        ans += -k;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >= h && b[i] >= w) {
        ans++;
      }
    }
    System.out.println(ans);
  }

}


Measured memory_bytes: 25320
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> q;
    rep(i,n){
        int a;
        cin>>a;
        q.push(a);
    }
    rep(i,m){
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    ll ans=0;
    rep(i,n){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 892
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<int> A(3 * n, 0);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> A[i];
        --A[i];
    }

    const int INF = 1 << 20;
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, -INF));
    
    auto update = [&](int i, int j, int x) {
        dp[i][j] = dp[j][i] = max(x, max(dp[j][i], dp[i][j]));
        dp[i][n] = dp[n][i] = max(x, max(dp[i][n], dp[n][i]));
        dp[j][n] = dp[n][j] = max(x, max(dp[j][n], dp[n][j]));
        dp[n][n] = max(dp[n][n], x);
    };

    update(A[0], A[1], 0);

    int base = 0;
    for (int i = 2; i + 3 <= 3 * n; i += 3) {
        vector<int> B{A[i], A[i + 1], A[i + 2]};
        vector<vector<int>> DP{dp[A[i]], dp[A[i + 1]], dp[A[i + 2]]};
        auto dpn = dp[n];

        if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
            ++base;
            for (int i = 0; i <= n; ++i) {
                for (int j = 0; j < 3; ++j) {
                    DP[j][i] -= 1;
                }
                dpn[i] -= 1;
            }
        }

        for (int _ = 0; _ < 3; ++_) {
            {
                //[i, j, a, b, c] - [j, a, b] = [i, c]
                for (int i = 0; i <= n; ++i) {
                    int mx = dpn[i];
                    if (B[0] == B[1]) {
                        mx = max(mx, DP[0][i] + 1);
                    } 
                    update(i, B[2], mx);
                }
            }

            {
                //[i, j, a, b, c] - [i, j, a] = [b, c]
                int mx = dpn[n];
                mx = max(mx, DP[0][B[0]] + 1);
                update(B[1], B[2], mx);
            }
            rotate(B.begin(), B.begin() + 1, B.end());
            rotate(DP.begin(), DP.begin() + 1, DP.end());
        }
    }

    int res = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            int ans = dp[i][j];
            if (i == j && A.back() == i) {
                ++ans;
            }
            res = max(res, ans);
        }
    }

    res += base;

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 19040
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	string s;
	cin >> s;
	if (s == "ABC")cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    long long n;
    int c,c2;
    cin>>n;
    string outp;
    rep(i,n)outp.push_back('a');
    while(outp<"abcdefghijk"){
        c=1;
        rep(i,n-1){
            c2=0;
            rep(j,i+1){
                if(outp[i+1]-outp[j]<2)c2=1;
            }
            c*=c2;
        }
        if(c)cout<<outp<<endl;
        //判定と出力
        outp[n-1]++;
        rep(i,n-1){
            if(outp[n-1-i]-'a'>n-1-i){
                outp[n-1-i]='a';
                outp[n-2-i]++;
            }
        }
        //カウンタ
    }
	return 0;
}


Measured memory_bytes: 1536
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe
import Debug.Trace

solve :: Int -> Int -> B.ByteString -> Int
solve n k ss = maximum
  [ accums
    VU.! ((i + k') `min` (gn - 1))
    -    (if i - k' - 1 >= 0 then accums VU.! (i - k' - 1) else 0)
  | i <- [0 .. gn - 1]
  , let k' =
          if is0AtNthGroup i then ((k - 1) `div` 2) * 2 + 1 else (k `div` 2) * 2
  ]
 where
  (_, istream, gn) = fix
    ( \f (bs, acc, g) -> if B.length bs == 0
      then (bs, acc, g)
      else if B.last bs == '0'
        then
          let (other, zeros) = B.spanEnd (== '0') bs
          in  f (other, B.length zeros : acc, g + 1)
        else
          let (other, ones) = B.spanEnd (== '1') bs
          in  f (other, B.length ones : acc, g + 1)
    )
    (ss, [], 0)

  accums :: VU.Vector Int
  accums = unsafePerformIO $ VU.unsafeFreeze $ (\(x, _, _) -> x) $ foldl'
    ( \(acc, i, prev) k ->
      let cur = prev + k
      in  cur
            `seq` ( unsafePerformIO $ (VM.write acc i cur >> return acc)
                  , i + 1
                  , cur
                  )
    )
    (unsafePerformIO $ VM.new gn, 0, 0)
    istream

  is0AtNthGroup n = if B.head ss == '0' then even n else odd n

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nk <- V.unfoldrN 2 readInt <$> B.getLine
  ss <- B.getLine
  print $ solve (nk V.! 0) (nk V.! 1) ss


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

int main() {
  int N, A, n, a;
  cin >> N >> A;
  n = N % 500;
  //a = A % 500;
  if(n <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  //cout << 7 % 3 << endl; // 1
  //cout << 4 % 5 << endl; // 4
}


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

using namespace std;

int ans  = 2000;
vector<int > av;
void dfs(int s, int r, vector<int> adj[], int vis[], vector<int> ans1, int c){
	// cout<<s<<","<<c<<" ";
	if (vis[s]){
		if (c < ans && s==r){
			// cout<<" entered ";
			ans = c;
			av = ans1;
			// cout<<"\n"<<ans<<" - "<<s<<"\n";
		}
		return;
	}
	
	vis[s] = 1;
	int v;
	c++;
	ans1.push_back(s);
	for (int i=0;i<adj[s].size();i++){
		v = adj[s][i];
		dfs(v, r, adj, vis, ans1, c);
	}
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    vector<int> adj[n+1];
    int a, b;
    for (int i=0;i<m;i++){
    	cin>>a>>b;
    	adj[a].push_back(b);
    }
    for (int i=1;i<=n;i++){
    	int vis[n+1] = {0};
    	vector<int > ans1;
    	dfs(i, i, adj, vis, ans1, 0);
    	// cout<<" - "<<ans<<"\n";
    	// cout<<"\n";
    }
    if (ans == 2000)
    	cout<<"-1\n";
    else{
    	cout<<ans<<"\n";
    	for (int i=0;i<av.size();i++)
	    	cout<<av[i]<<"\n";
	}
}


Measured memory_bytes: 6784
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a;
    cin >> b;
    if((a*b)%2==0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

i64 eval_number(const string& expr,int& i){
    i64 res=0;
    while(i<expr.size() and isdigit(expr[i])){
        res*=10;
        res+=expr[i]-'0';
        ++i;
    }
    return res;
}

i64 eval_term(const string&,int&);
i64 eval_expr(const string&,int&);

i64 eval_term(const string& term,int& i){
    if(isdigit(term[i])) return eval_number(term,i);
    
    assert(term[i]=='S');
    ++i;

    while(term[i]==' ') ++i;
    
    assert(term[i]=='<');
    ++i;
    
    while(term[i]==' ') ++i;
    
    i64 x=eval_expr(term,i);
    
    while(term[i]==' ') ++i;
    
    assert(term[i]=='>');
    ++i;
    
    return x*x%1000000007;
}

i64 eval_expr(const string& expr,int& i){
    i64 x=eval_term(expr,i);
    for(;;){
        if(i==expr.size()) break;
        int j=i;

        while(j<expr.size() and expr[j]==' ') ++j;
        if(j==expr.size() or expr[j]!='>') return x;
        
        ++j;
        
        if(j==expr.size() or expr[j]!='>') return x;
        ++j;

        while(j<expr.size() and expr[j]==' ') ++j;
        
        if(j==expr.size() or (expr[j]!='S' and !isdigit(expr[j]))) return x;
        
        i=j;
        i64 y=eval_term(expr,i);
        rep(i,0,y){
            if(x==0) break;
            x>>=1;
        }
    }
    return x;
}

void solve(string expr){
    int i=0;
    cout << eval_expr(expr,i) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    for(;;){
        string expr;
        getline(cin,expr);
        if(expr=="#") break;
        solve(expr);
    }
    return 0;
}

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

template<int N>
struct union_find {
    int par[N];
    union_find() {
        fill(par, par+N, -1);
    }
    
    int find(int x) {
        return par[x] < 0 ? x : (par[x] = find(par[x]));
    }
    
    bool unite(int x_, int y_) {
        int x = find(x_), y = find(y_);
        if (x == y) return false;
        
        if (par[x] < par[y]) {
            par[y] = x;
        } else {
            if (par[x] == par[y]) {
                --par[y];
            }
            par[x] = y;
        }
        return true;
    }
    
    bool same(int x, int y) { return find(x) == find(y); }
};

constexpr int LIMIT = 100005;

union_find<LIMIT> uf;
int N, M, P[LIMIT];

int main() {

    
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        --P[i];
    }
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        --x; --y;
        uf.unite(x, y);
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(i, P[i])) {
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env ruby

N = gets.chomp.to_i

count = 0
N.times do |i|
  d1, d2 = gets.chomp.split.map(&:to_i)

  if d1 == d2
    count += 1
  else
    count = 0
  end

  if count >= 3
    puts 'Yes'
    exit
  end
end

puts 'No'


Measured memory_bytes: 14328
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

bool comp(pair<int, int> p1, pair<int, int> p2) {
    return p1.second < p2.second;
}

void print_pair_vec(const vector<pair<int, int>> &v) {
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
        cout << "(" << itr->first << ", " << itr->second << ")" << endl;
    }
}

int main() {
    vector<pair<int, int>> v;

    int N; cin >> N;
    for(int i = 0; i < N; ++i) {
        int x, l; cin >> x >> l;
        v.push_back(make_pair(x-l, x+l));
    }

    sort(v.begin(), v.end(), comp);

    // print_pair_vec(v);

    int current = INT_MIN;
    int c = 0;
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
        // cout << "current = " << current << endl;
        int f = itr->first;
        int s = itr->second;
        // cout << "f, s = " << f << ", " << s << endl;

        // 選択する場合
        if(f >= current) {
            current = s;
            ++c;

        // 選択しない場合
        }
    }

    cout << c << endl;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll compare_asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll compare_desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}
/*void qsort(配列のアドレス,配列のサイズ,sizeof(配列の型),比較関数(昇順or降順)) */

int main(){
    int n;
    int cnt=0,ans=0,max=-1;
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        int tmp=i;
        cnt=0;
        while(tmp%2==0){
            tmp/=2;
            cnt++;
        }
        //printf("i:%d cnt:%d\n",i,cnt);
        if(max<cnt){
            max=cnt;
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

void printArray(const vector<int>& A) {
    for (auto i = 0; i < A.size(); i++) {
        cout << (i ? " " : "") << A[i];
    }
    cout << endl;
}

void insertionSort(vector<int>& A) {
    for (auto i = 1; i < A.size(); i++) {
        int v = A[i];
        int j = i-1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        printArray(A);
    }
}

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

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

    printArray(ary);
    insertionSort(ary);

    return 0;
}

Measured memory_bytes: 1200
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int sti(string s) {
	int base = 1;
	int num = 0;
	for(int i=s.size()-1; i>=0; i--) {
		num += (s[i]-'0')*base;
		base*=10;
	}
	return num;
}

int main() {
	IOS
	string s;
	cin >> s;
	int year, mm, dd;
	string ss = "";
	int cnt = 0;
	for(int i=0; i<s.size(); i++) {
		if(s[i]=='/') {
			if(cnt==0) {
				year = sti(ss);
				ss = "";
				cnt++;
			}
			if(cnt==1) {
				mm = sti(ss);
				ss = "";
			}
		}
		else ss += s[i];
	}
	dd = sti(ss);
	if(year < 2019) {
		cout << "Heisei";
		exit(0);
	}
	else if(year > 2019) {
		cout << "TBD";
		exit(0);
	}
	if(mm < 4) {
		cout << "Heisei";
		exit(0);
	}
	else if(mm > 4) {
		cout << "TBD";
		exit(0);
	}
	if(dd<=30) {
		cout << "Heisei";
	}
	else cout << "TBD";
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8

def printls(ls):
    print(' '.join(map(str,ls)))
    
def main():
    trash = input()
    ls = list(map(int, input().split(' ')))

    for i in range(1, len(ls)):
        printls(ls)
        v = ls[i]
        for j in reversed(range(0, i)):
            if ls[j] > v:
                ls[j], ls[j+1] = ls[j+1], ls[j]

    printls(ls)
    
if __name__ == '__main__':
    main()

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


int main() {
	long long int n, k, m;
    cin >> n >> k;
  	long long int a[n];
  	long long int dp[n];
  	for (long long int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = 1e10;
    }
    m = 1e10;
  
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);
  
	for (long long int i = 2; i < n; i++) {
      	
        for (long long int j = 1; j <= k; j++) {
 			if(i-j < 0) break;     
        	
          	m = min(m, dp[i-j] + abs(a[i-j]-a[i]));  
    	}
      	dp[i] = min(dp[i], m);
      	m = 1e10;
    }
  
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from heapq import heappop,heappush
    n,m=map(int,input().split())
    A=[[] for _ in range(m)]
    for _ in range(n):
        a,b=map(int,input().split())
        if(a>m): continue
        a-=1
        heappush(A[a],(-b,a))
    Q=[]
    res=0
    for i in range(m):
        if(A[i]):
            x=heappop(A[i])
            heappush(Q,x)
        if(Q):
            b,a=heappop(Q)
            res-=b
            if(A[a]):
                x=heappop(A[a])
                heappush(Q,x)
    print(res)
resolve()

Measured memory_bytes: 110768
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)

#define int ll

int n,a[314514];
int l[314514];
int r[314514];

signed main(){
    scanf("%lld",&n);
    REP(i,3*n) scanf("%lld",&a[i]);

    int left = 0;
    PQ<int,vector<int>,greater<int> > que;
    REP(i,n){
        que.push(a[i]);
        left += a[i];
        l[i] = left;
    }
    FOR(i,n,n*2){
        que.push(a[i]);
        left += a[i];
        int q = que.top(); que.pop();
        left -= q;
        l[i] = left;
    }

    int right = 0;
    PQ<int> qqq;
    for(int i=3*n-1;i>=2*n;i--){
        qqq.push(a[i]);
        right += a[i];
        r[i] = right;
    }
    for(int i=2*n-1;i>=n;i--){
        qqq.push(a[i]);
        right += a[i];
        int q = qqq.top(); qqq.pop();
        right -= q;
        r[i] = right;
    }

    int k = -INF;
    FOR(i,n,2*n+1){
        k = max(k,l[i-1]-r[i]);
    }

    printf("%lld\n",k);
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
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); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int n, a, b;
    cin >> n >> a >> b;

    vector<int> x(n);

    rep(i,n){
        cin >> x[i];
    }

    int res = 0;

    rep(i,n-1){
        res += min((x[i+1] - x[i]) * a, b);
    }

    cout << res << '\n';

    return (0);
}

Measured memory_bytes: 3904
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const S = input[1][0];

  let answer = 0;

  for (let i = 2; i < N; i++) {
    const X = S.slice(0, i);
    const Y = S.slice(i);

    let count = 0;

    new Set(X.split("")).forEach((char) => {
      if (Y.includes(char)) {
        count += 1;
      }
    });

    answer = Math.max(count, answer);
  }

  return answer;
};

console.log(main(read()));


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

using namespace std;

struct p{
	double x;
	double y;
};

int main(){

	int N;
	cin >> N;
	vector<p>P(N);

	for (int i = 0; i < N; i++)
		cin >> P[i].x >> P[i].y;

	vector<int> v;
	for (int i = 0; i < N; i++)
		v.push_back(i);

	int count = 0;
	double sum = 0;
	do{
		count++;
		for (int i = 0; i < N-1; i++){
			sum += sqrt(pow(P[v[i]].x - P[v[i + 1]].x, 2) + pow(P[v[i]].y - P[v[i + 1]].y, 2));
		}
	} while (next_permutation(v.begin(), v.end()));

	sum /= count;

	printf("%.10f\n", sum);

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scanf("%s", &s)

	if len(s)%2 != 0 && isPal(s) && isPal(s[:len(s)/2]) && isPal(s[len(s)/2+1:]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func isPal(s string) bool {
	l, r := 0, len(s)-1
	for l <= r {
		if s[l] != s[r] {
			return false
		}
		l++
		r--
	}
	return true
}


Measured memory_bytes: 512
fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val id = readLine()!!.trim().toCharArray()
    readLine()
    val suspects = readLine()!!.trim().split(' ').map(String::toInt)
    var sum = 0
    for (i in 1 .. n){
        sum += if (id[n - i] == '*')
        {
            0
        }else if (i % 2 == 1){
            id[n - i].toString().toInt()
        }else {
            if (id[n - i].toString().toInt() * 2 >= 10){
                (id[n - i].toString().toInt() * 2).let{ it / 10 + it % 10}
            }else{
                id[n - i].toString().toInt() * 2
            }
        }
    }
    val wildcard = id.mapIndexed { index, c -> Pair(n - index, c) }.filter{it.second == '*'}.map{
        if (it.first % 2 == 1){
            suspects
        }else{
            suspects.map{
                if (it * 2 >= 10) it * 2 / 10 + it * 2 % 10
                else it * 2
            }
        }.toIntArray()
    }.toTypedArray()
    println(calPattern(wildcard, 0, sum))

}
fun calPattern(suspects:Array<IntArray>, idx:Int, sum:Int, memo:Array<IntArray> = Array(10){Array(10){-1}.toIntArray()}):Int {
    if (idx == suspects.size) return if (sum % 10 == 0) 1 else 0
    if (memo[sum % 10][idx] >= 0) return memo[sum % 10][idx]
    memo[sum % 10][idx] = 0
    for (n in suspects[idx]){
        memo[sum % 10][idx] += calPattern(suspects, idx + 1, sum + n, memo)
    }
    return memo[sum % 10][idx]
}


Measured memory_bytes: 45372
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin());  // 先頭文字削除
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int main() {
    int R;
    cin >> R;
    printf("%.10lf\n", 2 * R * M_PI);
    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;

int main(){
	ll n, k; cin >> n >> k;
	double ans = 0;
	for (int i = 1; i < n+1; ++i){
		double now_point = i;
		double count = 0;
		while (now_point < k){
			now_point *= 2;
			count++;
		}
		ans += pow((double)1 / 2, count);
	}cout << setprecision(11) << ans/n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int a,b, c;cin>>a>>b>>c;
    int ans = min(a+b, b+c);
    ans = min(ans, c+a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int MAXN = 110;
const int MAXM = 16;

int M[MAXN];
int L[MAXN];
int BIT[MAXN];
ll dp[1 << MAXM];

int main(){
  int N, S, E;
  while(cin >> N && N){
    REP(i, N){
      BIT[i] = 0;
      cin >> M[i] >> L[i];
      REP(j, M[i]){
        cin >> S >> E;
        REP2(k, 6, 22) if(S <= k && k < E) BIT[i] |= 1 << (k - 6);
      }
    }

    memset(dp, 0, sizeof(dp));
    
    REP(i, N){
      REP(mask, 1 << MAXM){
        if((BIT[i] & mask) == BIT[i]){
          int nmask = mask ^ BIT[i];
          dp[nmask] = max(dp[nmask], dp[mask] + L[i]);
        }
      }
    }
    ll res = 0;
    REP(mask, 1 << MAXM) res = max(res, dp[mask]);
    cout << res << endl;
  }
  return 0;
  
}

Measured memory_bytes: 1676
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

string s;

int main(){
  cin>>s;
  bool f = false;

  if((int)s.length() == 2){
    if(s[0] == s[1]){
      cout<<"1 2"<<endl;
    } else {
      cout<<"-1 -1"<<endl;
    }
    return 0;
  }

  for(int i=0;i<(int)s.length()-2;i++){
    if(s[i]==s[i+1]){
      cout<<(i+1)<<" "<<(i+3)<<endl;
      f = true;
      break;
    }
    if(s[i+1]==s[i+2]){
      cout<<(i+1)<<" "<<(i+3)<<endl;
      f= true;
      break;
    }
    if(s[i]==s[i+2]){
      cout<<(i+1)<<" "<<(i+3)<<endl;
      f=true;
      break;
    }
  }
  if(!f){
    cout<<"-1 -1"<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
from collections import defaultdict


def main():
    N = int(input())
    adj_nodes = defaultdict(list)
    edge_lengths = defaultdict(int)
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        u -= 1
        v -= 1
        adj_nodes[u].append(v)
        adj_nodes[v].append(u)
        edge_lengths[(u, v)] = w
        edge_lengths[(v, u)] = w
    # Calculate distances from root node
    distances = [0 for _ in range(N)]
    explored = [0 for _ in range(N)]
    start_node = 0
    frontier = [(start_node, None)]  # (node, parent node)
    while len(frontier) > 0:
        node, parent_node = frontier.pop()
        if parent_node is not None:
            distances[node] = distances[parent_node] + edge_lengths[(node, parent_node)]
        explored[node] = 1
        next_nodes = adj_nodes[node]
        for next_node in next_nodes:
            if explored[next_node] == 1:
                continue
            frontier.append((next_node, node))
    # Coloring
    #   white: distance is odd
    #   black: distance is even
    for node in range(N):
        color = 0 if distances[node] % 2 == 1 else 1
        print(color)


if __name__ == '__main__':
    main()


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

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif
/*---------------------------Defines----------------------*/
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
/*-----------------------Modular Arithmetic---------------*/
inline ll add(ll x,ll y,ll mod){x+=y; if(x>=mod) return x-mod; return x;}
inline ll sub(ll x,ll y,ll mod){x-=y; if(x<0) return x+mod; return x;}
inline ll mul(ll x,ll y,ll mod){return (x*1ll*y)%mod;}
inline ll power(ll x,ll y,ll mod){ll ans=1; while(y){if(y&1) ans=mul(ans,x,mod); x=mul(x,x,mod); y>>=1;} return ans;}
inline ll inv(ll x,ll mod){return power(x,mod-2,mod);}
/*-----------------------------Code begins----------------------------------*/

const ll INF = 1e18;

void solve(){
    ll n;cin>>n;
    ll ans=0;
    for(ll i=2;i<=sqrtl(n);i++){
        if(n%i==0){
            ll val=0;
            while(n%i==0){
                n/=i;
                val++;
            }
            val*=2;
            // n^2+n-val <= 0
            ll x=(-1.0+sqrt(1+4*val))/2.0;
            ans+=x;
        }
    }
    if(n>1) ans++;
    cout<<ans<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3704
n, m = gets.chomp.split.map(&:to_i)
ac = Hash.new(false)
wa = Hash.new(0)
m.times do |_|
  p, s = gets.chomp.split
  if s == "AC"
    ac[p.to_i] = true
  elsif s == "WA" && !ac[p.to_i]
    wa[p.to_i] += 1
  end
end

ac_num = 0
wa_num = 0
(1..n).each do |i|
  if ac[i] == true
    ac_num += 1
    wa_num += wa[i]
  end
end
puts [ac_num, wa_num].join(" ")

Measured memory_bytes: 8316
<?php
$str = fgets(STDIN);
$arr = [];
for ($i = 0; $i < strlen($str); $i++) {
	$arr[] = $str[$i];
}
$res = array_unique($arr);
//var_dump($arr, $str, $res);

if (count($res) < strlen($str)) {
	echo "no\n";
	return;
}
echo "yes\n";


Measured memory_bytes: 4728
#include <iostream>

using namespace std;

#define MAX 500000
#define SENTINEL 2e9

int L[MAX / 2 + 2], R[MAX / 2 + 2];

long long merge(int A[], int left, int mid, int right) {
	long long cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; ++i) L[i] = A[left + i];
	for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for (int k = left; k < right; ++k) {
		if (L[i] <= R[j]) A[k] = L[i++];
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

long long mergeSort(int A[], int left, int right) {
	long long res = 0;
	if (left < right - 1) {
		int mid = (left + right) / 2;
		res += mergeSort(A, left, mid);
		res += mergeSort(A, mid, right);
		res += merge(A, left, mid, right);
	}
	return res;
}

int main() {
	int n; cin >> n;
	int A[MAX];
	for (int i = 0; i < n; ++i) cin >> A[i];
	cout << mergeSort(A, 0, n) << endl;

	return 0;
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long a,p,sum,res;
  cin >> a >> p;
  sum = a*3 + p;
  res = sum / 2;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
    ll n; cin >> n;
    vector<ll>v(n);
    for (auto& it : v)
    {
        cin >> it;
    }
    sort(all(v));
    ll ans = 1;
    for (auto a : v)
    {
        if (a == 0)
        {
            cout << 0;
            return 0;
        }

        if (a > (ll)1e18 / ans)
        {
            cout << "-1\n";
            return 0;
        }
        ans *= a;
    }
    if (ans > (ll)1e18)
    {
        cout << -1;
        return 0;
    }
    cout << ans;
}
   

Measured memory_bytes: 4000
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
lint mod=1'000'000'007;
lint inverse(lint x){
    assert(x%mod);
    lint y=1,u=mod,v=0;
    while(x){lint q=u/x;u-=q*x;std::swap(u,x);v-=q*y;std::swap(v,y);}
    assert(x==0&&std::abs(u)==1&&std::abs(y)==mod&&std::abs(v)<mod);
    return v<0?v+mod:v;
}
lint normalized(lint x){if(x<=-mod||mod<=x)x%=mod;if(x<0)x+=mod;return x;}
struct mint{
    lint value;
    mint()=default;
    mint(lint x):value(normalized(x)){}
};
std::ostream&operator<<(std::ostream&os,mint x){return os<<x.value;}
mint operator+(mint x,mint y){lint z=x.value+y.value;if(mod<=z)z-=mod;return mint{z};}
mint operator-(mint x,mint y){lint z=x.value-y.value;if(z<0)z+=mod;return mint{z};}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
mint&operator+=(mint&x,mint y){return x=x+y;}
mint&operator-=(mint&x,mint y){return x=x-y;}
mint&operator*=(mint&x,mint y){return x=x*y;}
mint&operator/=(mint&x,mint y){return x=x/y;}
bool operator==(mint x,mint y){return x.value==y.value;}
bool operator!=(mint x,mint y){return x.value!=y.value;}
mint power(mint x,lint y){mint z=1;for(;y;y>>=1){if(y&1)z*=x;x*=x;}return z;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    std::vector<mint>dp(k+1);
    for(lint i=1;i<=k;i++){
        dp.at(i)=power(mint{k/i},n);
    }
    mint ans=0;
    for(lint i=k;i>=1;i--){
        for(lint j=2*i;j<=k;j+=i){
            dp.at(i)-=dp.at(j);
        }
        ans+=dp.at(i)*i;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 3992
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

int arr[100025];
int n_era = 100020;
vector <int> sosuu;

void Eratosthenes(){
	for(int i = 0; i < n_era; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(n_era); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < n_era; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < n_era; i++){
		if(arr[i]){
			sosuu.pb(i);
		}
	}
}



signed main(){
    Eratosthenes();
    int x;
    cin >> x;
    int noww = 0;
    while(1){
        if(sosuu[noww]>=x){
            cout << sosuu[noww] << endl;
            return 0;
        }
        noww ++;
    }


    return 0;
}

Measured memory_bytes: 1280
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n, k;
  readf (" %d %d", &n, &k);
  int r;
  foreach (i; 1 .. n + 1) {
    if (i + k - 1 <= n) ++r;
  }
  writeln (r);
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
#define heeer cout<<"heeeeeeeeer\n";
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 3 * 1000000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) ;
	if (b % 2 != 0)
		ans = (ans * (a )) ;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}
ll dp[30][N];
bool a[30][30];
ll n;
ll fun(ll i,ll s){
	if (i == n){
		if (s == 0)return 1;
		else return 0;
	}
	ll &ans = dp[i][s];
	if (ans == -1){
		ans = 0;
		rep(j, n){
			bool is = (1 << j)&s;
			if (is&&a[i][j])			
				ans = (ans + fun(i + 1, s ^ (1 << j)))%mod;			
		}
	}
	return ans;
}

int main()
{
	Amr_Abdelazim
		clr(dp, -1);
	cin >> n;
	rep(i, n)rep(j, n)cin >> a[i][j];
	cout << fun(0,(1 << n) - 1) << "\n";
	return 0;
}

Measured memory_bytes: 706832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    if(n < 105) pr(0);
    else if(n < 135) pr(1);
    else if(n < 165) pr(2);
    else if(n < 189) pr(3);
    else if(n < 195) pr(4);
    else pr(5);
    return 0;}

Measured memory_bytes: 3620
// by gantheory™
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, a[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];

  int total = 0;
  for (int i = 1; i <= n + 1; ++i) total += abs(a[i] - a[i - 1]);

  for (int i = 1; i <= n; ++i) {
    int nowAns = total;
    nowAns += abs(a[i + 1] - a[i - 1]);
    nowAns -= abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]);
    cout << nowAns << '\n';
  }
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,m,a[100001],b[100001];
    for(;;){
        int ans[501]={0},cou=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<m;i++){
            cin>>a[i]>>b[i];
        }
        for(int i=0;i<m;i++){
            if(a[i]==1){
                ans[b[i]]++;
                for(int j=0;j<m;j++){
                    if(b[i]==a[j])ans[b[j]]++;
                    if(b[i]==b[j]&&i!=j)ans[a[j]]++;
                }
            }
        }
        for(int i=0;i<501;i++){
            if(ans[i]!=0)cou++;
        }
        cout<<cou<<endl;
    }
}

Measured memory_bytes: 1244
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n, k;
	
	cin >> n >> k;

	int a[n];

	rep(i, n)
	{
		cin >> a[i];
	}
	int min = MOD;

	rep(i, n-k+1)
	{
		int l = i;
		int r = i + k -1;
		int lr = abs(a[l]) + abs(a[r] - a[l]);
		int rl = abs(a[r]) + abs(a[r] - a[l]);
		if (min > lr)
		{
			min = lr;
		}
		if (min > rl)
		{
			min = rl;
		}
	}

	cout << min << endl;

	
	return 0;
}


Measured memory_bytes: 640
r, c = map(int, input().split())
last = [0] * (c + 1)

for _ in range(r):
    row = list(map(int, input().split()))
    row += [sum(row)]

    print(' '.join(map(str, row)))

    for x in range(c + 1):
        last[x] += row[x]

print(' '.join(map(str, last)))

Measured memory_bytes: 7656
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::usize;

use std::f64;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn find_range(i: usize, points: &Vec<(f64, f64)>) -> Option<f64> {
    let num_points = points.len();

    let mut min: f64 = 0.0;
    let mut max = 2.0 * f64::consts::PI;

    for j in 0..num_points {
        if j == i {
            continue;
        }

        let p = points[i];
        let q = points[j];

        let mid = ((p.0 + q.0) / 2.0, (p.1 + q.1) / 2.0);
        let gradient = if p.1 == q.1 {
            f64::INFINITY
        } else {
            -(p.0 - q.0) / (p.1 - q.1)
        };

        let is_upper = p.1 - mid.1 >= gradient * (p.0 - mid.0);
        let r = gradient.atan();

        let (mut r_min, mut r_max) = if is_upper {
            (r, r + f64::consts::PI)
        } else {
            (r - f64::consts::PI, r)
        };

        if r_min < 0.0 {
            r_min += 2.0 * f64::consts::PI;
            r_max += 2.0 * f64::consts::PI;
        }

        if j == 0 || (j == 1 && i == 0) {
            // first
            min = r_min;
            max = r_max;
            continue;
        }

        // find shared
        if r_min <= min {
            if r_max >= max {
                // no update
                continue;
            } else if min <= r_max {
                max = r_max;
                continue;
            } else if max < r_min + 2.0 * f64::consts::PI {
                // no shared
                return None;
            } else {
                min = r_min;
                max -= 2.0 * f64::consts::PI;
                continue;
            }
        } else if r_min <= max {
            min = r_min;
            continue;
        } else if min > r_max - 2.0 * f64::consts::PI {
            // no shared
            return None;
        } else if max >= r_max - 2.0 * f64::consts::PI {
            max = r_max - 2.0 * f64::consts::PI;
            continue;
        } else {
            // no update
            continue;
        }
    }

    Some((max - min) / (2.0 * f64::consts::PI))
}

fn main() {
    let num_points = read::<usize>();
    let mut points = Vec::with_capacity(num_points);
    for _ in 0..num_points {
        let p = read_cols::<f64>();
        points.push((p[0], p[1]));
    }

    for i in 0..num_points {
        match find_range(i, &points) {
            Some(p) => println!("{}", p),
            None => println!("0"),
        }
    }
}


Measured memory_bytes: 4352