akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r)    // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end())      // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
#define fo0 (i, n) for (i = 0; i < n; i++)
#define fo1 (i, n) for (i = 1; i <= n; i++)
#define rfo(i, n) for (i = n - 1; i >= 0; i--)
#define rfor(i, n) for (i = n; i > 0; i--)
signed main()
{
    int n;
    cin >> n;
    map<string, int> cnt;
    while (n--)
    {
        string s;
        cin >> s;
        cnt[s]++;
    }
    cout << cnt.size() << endl;
    return 0;
}

Measured memory_bytes: 19192
N = int(input())
A = list(map(int, input().split()))
B = [A[i-1] - i for i in range(1, len(A) + 1)]
B.sort()
def f(x):
    sum = 0
    for b in B:
        sum += abs(b-x)
    return sum
if len(B) % 2 == 0:
    print(f((B[len(B)//2] + B[len(B)//2 - 1])//2))
else:
    print(f(B[int(len(B)/2)]))

Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

int n,z=0,p=0,r=0,i;
cin>>n;
if(n<1000)
{
	z=1000-n;
}

else
{
	for(i=1;i<=100;i=i*10)
	{
		r=n%10;
		n=n/10;
		p=p+(r*i);
		
	}
	z=abs(1000-p);
}

if(z%1000==0)
	cout<<0;
else
cout<<z;
return 0;
 }

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<int> a;
    for (int i=0;i<n;i++){
        double input;
        cin >> input;
        a.push(input);
    }
    for (int i=0;i<m;i++){
        int nax = a.top()/2;
        a.pop();
        a.push(nax);
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=a.top();
        a.pop();
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 892
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<int> Hs(N); for (auto &Hi : Hs) cin >> Hi;
    // 後ろから見て厳密に単調減少になっていればよい:O(N)
    for (int i = N - 2; i >= 0; --i)
    {
        if (Hs[i] <= Hs[i + 1]) continue;
        else --Hs[i];
        if (Hs[i] > Hs[i + 1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 768
#include <iostream>

int main()
{
  int xxyy;
  std::cin >> xxyy;
  const int xx = xxyy / 100;
  const int yy = xxyy % 100;
  const bool xxMonth = 1<= xx && xx <= 12;
  const bool yyMonth = 1<= yy && yy <= 12;
  if( xxMonth && yyMonth ) { std::cout << "AMBIGUOUS"; }
  else if( xxMonth && ! yyMonth ) { std::cout << "MMYY"; }
  else if( ! xxMonth && yyMonth ) { std::cout << "YYMM"; }
  else { std::cout << "NA"; }
}


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

using namespace std;

int main(){

    int N;
    vector<int> L;
    int max = -1;
    int idx = 0;
    cin >> N;
    L.resize(N);
    for (int i = 0; i < N; i++){
        cin >> L[i];
        if(L[i] > max){
            max = L[i];
            idx = i;
        }
    }
    int sum = 0;
    for (int i = 0; i < N; i++){
        if(i==idx){
            continue;
        }
        sum += L[i];
    }

    if(sum > max){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int C;
char S[30000];

void Count(int N, int L, int n){
  int i, k;
  int u[10];
  if(n <= 2){
    for(i = 0;i < 10;i++) u[i] = 0;
    for(i = L;i < N;i++){
      k = S[i] - '0';
      if(u[k] == 0){
	Count(N, i + 1, n + 1);
	u[k] = 1;
      }
    }
  }else C++;
}

void Do(int N){
  C = 0;
  scanf("%s", S);
  Count(N, 0, 0);
  printf("%d\n", C);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main(void){
    string s;
    cin >>s;
    if(s.size() == 2){
        cout << s<< endl;
    }
    else{
        cout << s[2] << s[1] << s[0];
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int cnt[] = new int[128];
            for (char ch : s) {
                cnt[ch]++;
            }
            boolean yes = true;
            for (int i = (int) 'a'; i <= (int) 'z'; i++) {
                if (cnt[i] % 2 != 0) {
                    yes = false;
                    break;
                }
            }
            System.out.println(yes ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 21844
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

const int U = (1 << 10) - 1;

using pi = pair<int, int>;

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

    vector<int> v(n + 1), w(n + 1);
    rep(i, n) scanf(" %d %d", &v[i + 1], &w[i + 1]);

    vector<int> p(n + 1);
    p[1] = -1;
    for (int i = 2; i <= n; ++i) p[i] = i / 2;

    vector<int> dep(n + 1);
    dep[1] = 0;
    for (int i = 2; i <= n; ++i) dep[i] = dep[p[i]] + 1;

    vector<vector<pi>> up(U + 1);
    for (int i = 1; i <= min(U, n); ++i) {
        int x = i;
        vector<int> a;
        while (x > 0) {
            a.pb(x);
            x = p[x];
        }
        const int A = a.size();

        vector<pi> ss;
        rep(mask, 1 << A) {
            int tw = 0, tv = 0;
            rep(j, A) if (mask >> j & 1) {
                tw += w[a[j]];
                tv += v[a[j]];
            }
            ss.pb({tw, -tv});
        }
        sort(all(ss));

        up[i].pb({0, 0});
        for (const auto& pp : ss) {
            int vv = -pp.se;
            if (up[i].back().se < vv) up[i].pb({pp.fi, vv});
        }
    }

    int Q;
    scanf(" %d", &Q);
    rep(qqq, Q) {
        int x, L;
        scanf(" %d %d", &x, &L);

        int ans = 0;
        if (dep[x] <= 9) {
            auto itr = lower_bound(all(up[x]), pi(L + 1, 0));
            --itr;
            ans = itr->se;
        } else {
            vector<int> a;
            while (dep[x] > 9) {
                a.pb(x);
                x = p[x];
            }
            int A = a.size();

            rep(mask, 1 << A) {
                int tw = 0, tv = 0;
                rep(i, A) {
                    if (mask >> i & 1) {
                        tw += w[a[i]];
                        tv += v[a[i]];
                    }
                }
                if (tw > L) continue;

                auto itr = lower_bound(all(up[x]), pi(L - tw + 1, 0));
                --itr;
                ans = max(ans, tv + itr->se);
            }
        }

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

    return 0;
}


Measured memory_bytes: 13060
#include<bits/stdc++.h>
const long long mod = 1000000007;


int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++)std::cin >> a[i];
    long long res = 0;
    long long cur = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == 0){res += cur / 2; cur = 0;}
        else cur += a[i];
    }
    res += cur / 2;
    std::cout << res << std::endl;

}

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

int main(void) {
    int N;
    cin>>N;
    int combo = 0;
    int before = -1;
    bool flg = false;
    while (N > 0) {
        if (before == -1) {
            before = N % 10;
            combo++;
        } else {
            if (before == N % 10) combo++;
            else {
                combo = 1;
                before = N % 10;
            }
        }
        N /= 10;
        if (combo == 3) flg = true;
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
use List::Util qw(min);

my $n = glob <>;
my @p = glob <>;

my $sum = $n;
my $min = 9**9**9;
for ( my $i = 0 ; $i < $n ; $i++ ) {
    $min = min( $min, $p[$i] );
    if ( $min < $p[$i] ) {
        $sum--;
    }
}
print($sum);

Measured memory_bytes: 52656
function main() {
  //????????§??????????§£???
  //`input` ?????\??????????????§???????????????????????¨????????\??£??????????????§????????£???
  console.log(input[0] * input[0] * input[0]); 
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

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

int main()
{
    int N;
    cin >> N;
    int t[N],x[N],y[N];
    for(int i=0;i<N;i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    int t_pre = 0, x_pre = 0, y_pre = 0;
    for(int i=0;i<N;i++)
    {
        int dt = t[i] - t_pre;
        int dl = abs(y[i]-y_pre) + abs(x[i]-x_pre);
        bool can = (dt >= dl && dt % 2 == dl % 2);

        if(!can){
            cout << "No" << endl;
            return 0;
        }         
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>

#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int N ,T;
    cin >> N >> T;
    vector<int> c(N);
    vector<int> t(N);
    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
    }
int MAX = 1 << 30;
int ans = MAX;
for(int i = 0; i < N; i++){
    if(t[i] <= T){
        ans = min(ans, c[i]);
    }
    
}
if (ans < MAX){
    cout << ans << endl;
}
else{
    cout << "TLE" << endl;
}

}


Measured memory_bytes: 256
// #pragma GCC optimize("-O0")
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long llong;
typedef unsigned int uint;
struct Edge
{
    int u, v;
    llong w;
};

llong x[100'000];

int par[100'000], sz[100'000];
llong sum[100'000];
int e[100'000];
void MakeSet(int v)
{
    par[v] = v;
    sz[v] = 1;
    sum[v] = x[v];
    e[v] = 0;
}
int Root(int v)
{
    return (par[v] == v) ? v : (par[v] = Root(par[v]));
}
void Union(int u, int v)
{
    u = Root(u); v = Root(v);
    if (u == v) return;
    if (sz[u] > sz[v])
        swap(u, v);
    par[u] = v;
    sz[v] += sz[u];
    sum[v] += sum[u];
    e[v] += e[u];
    e[u] = 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i];
        MakeSet(i);
    }
    vector<Edge> edges;
    for (int j = 0; j < m; ++j)
    {
        Edge edge;
        cin >> edge.u >> edge.v >> edge.w;
        --edge.u; --edge.v;
        edges.push_back(edge);
    }
    sort(edges.begin(), edges.end(), [](const Edge& a, const Edge& b) {
         return a.w < b.w;
    });
    int ans = m;
    for (Edge edge: edges)
    {
        int u = edge.u, v = edge.v, w = edge.w;
        Union(u, v);
        int root = Root(v);
        ++e[root];
        if (sum[root] >= w)
        {
            ans -= e[root];
            e[root] = 0;
        }
    }
    cout << ans;
}


Measured memory_bytes: 5236
n = input()
b = list(map(int,input().split(' ')))
ans = 0
lst = []
for i in range(int(n)-1) :
    if b[i] >= b[i+1]:
        ans += 1
    else:
        lst.append(ans)
        ans = 0
lst.append(ans)
print(max(lst))


Measured memory_bytes: 20724
import sys

if __name__ == '__main__':
    N, K = map(int, input().split())
    xy_list = [list(map(int, input().split())) for i in range(N)]

    all_x = sorted(list(set([xy[0] for xy in xy_list])))
    all_y = sorted(list(set([xy[1] for xy in xy_list])))

    answer = sys.maxsize
    for i in range(len(all_x)):
        x1 = all_x[i]
        for j in range(i+1, len(all_x)):
            x2 = all_x[j]
            for k in range(len(all_y)):
                y1 = all_y[k]
                for l in range(k+1, len(all_y)):
                    y2 = all_y[l]
                    if K <= len([xy for xy in xy_list if (x1 <= xy[0] <= x2) and (y1 <= xy[1] <= y2)]) and answer > (x2-x1) * (y2-y1):
                        answer = (x2-x1) * (y2-y1)

    print(answer)



Measured memory_bytes: 55644
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
using lint = long long;

// Z * Z < Sを満たす最小のZを求める
lint sqrti(lint S) {
    lint ok = 0, ng = 1e9 + 1;
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;
        (mid * mid < S ? ok : ng) = mid;
    }
    return ok;
}

int main() {
    lint S;
    cin >> S;
    lint Z = sqrti(S);

    vector<lint> X(3), Y(3);
    X[0] = Y[0] = 0, X[2] = 1;

    if (S <= Z * (Z + 1)) {
        Y[1] = Z * (Z + 1) - S;
        X[1] = Z, Y[2] = Z + 1;
    } else {
        Y[1] = (Z + 1) * (Z + 1) - S;
        X[1] = Y[2] = Z + 1;
    }

    assert(X[1] * Y[2] - X[2] * Y[1] == S);
    for (int i = 0; i < 3; ++i) {
        assert(X[i] <= 1e9);
        assert(Y[i] <= 1e9);
        cout << X[i] << " " << Y[i] << " ";
    }
    cout << endl;
    return 0;
}


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

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<double>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //


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

    ll ans=0;
   	 string a,b;
   	 cin>>a>>b;
     rep(i,0,a.size())
     {
     	if(a[i]!=b[i])ans++;
     }
     cout<<ans;
}





Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    rep(0, i, 4)
    {
        if (S[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> MAX(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    MAX.at(A - 1) = max(MAX.at(A - 1), H.at(B - 1));
    MAX.at(B - 1) = max(MAX.at(B - 1), H.at(A - 1));
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (H.at(i) > MAX.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4020
#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 num = 1;
	for(int i = 0;i < n;i++){
		if(num*2 > num+k){
			num += k;
		}else{
			num*=2;
		}
	}
	cout << num << endl;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

using Graph = vector<vector<pint>>;

vector<int> ans;
vector<bool> seen;
void dfs(const Graph& g, int v, int sum) {
    seen[v] = true;

    ans[v] = sum % 2;

    for (auto next : g[v]) {
        if (seen[next.first])continue;
        dfs(g, next.first, sum + next.second);
    }
}

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

    Graph g(n);

    rep(i, n - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        g[u].push_back(make_pair(v, w % 2));
        g[v].push_back(make_pair(u, w % 2));
    }

    seen.assign(n, false);
    ans.assign(n, -1);
    dfs(g, 0, 0);

    rep(i, n) {
        cout << ans[i] << endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 8192
/*
ID: alec3
LANG: C++14
PROG: pprime
CLASSIFICATION: brute force
*/

#include <bits/stdc++.h>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

bool isPrime(int n){
    bool prime = true;
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;

    for (int i = 3; i < sqrt(n) + 1; i+= 2){
        if (n % i == 0){
            prime = false;
            break;
        }
    }
    return prime;
}

int main() {

	//ifstream fin("pprime.in");
	//ofstream fout("pprime.out");
    io;
    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for (int i = l; i <= r; i++){
        if (i % d == 0){
            ans ++;
        }
    }
    cout << ans << endl;




    return 0;

}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

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

    int a,b,c;
    cin >> a >> b >>c;
    int gi = min(a-b,c);
    int ans = c - gi;
    cout << ans <<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]

from collections import Counter
asz = Counter(a)

ans = 0
for i in asz :
    if i < asz[i] :
        ans += asz[i] - i
    elif i > asz[i] :
        ans += asz[i]

print(ans)


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

typedef long long ll;
const int maxn=2e5+10;
int n,a[maxn];
ll sum[maxn],ans=1e18;

inline ll calc(ll a,ll b,ll c){
	return abs(2*sum[b]-sum[a-1]-sum[c]);
}
inline void work(int a,int b,ll&x,ll&xx){
	int l=a,r=b;
	while(l<r){
		int midl=(l+l+r)/3,midr=(l+r+r+2)/3;
		if(calc(a,midl,b)<calc(a,midr,b))
			r=midr-1;
		else
			l=midl+1;
	}
	x=min(sum[b]-sum[l],sum[l]-sum[a-1]);
	xx=max(sum[b]-sum[l],sum[l]-sum[a-1]);
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=2;i+2<=n;++i){
		ll x[4]={};
		work(1,i,x[0],x[1]);
		work(i+1,n,x[2],x[3]);
		sort(x,x+4);
		ans=min(ans,x[3]-x[0]);
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

#define MOD 1000000007

vector<pii> walls;
ll ans[4000];

ll inv[200005];
ll fact[200005];
ll inv_fact[200005];

ll ways(int x, int y) {
	ll tmp = fact[x+y];
	tmp = tmp * inv_fact[x];
	tmp = tmp % MOD;
	tmp = tmp * inv_fact[y];
	tmp = tmp % MOD;
	//cout<<x<<" "<<y<<" "<<tmp<<endl;
	return tmp;
}

int main() {
	int h,w,n;
	cin>>h>>w>>n;
	walls.push_back(pii(h,w));
	
	fact[0] = 1;
	for (int i=1; i<200005; i++) {
		fact[i] = (fact[i-1] * i) % MOD;
	}
	
	inv[1] = 1;
	for(int i = 2; i < 200005; ++i)
    	inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

	inv_fact[0] = 1;
	for (int i=1; i<200005; i++) {
		inv_fact[i] = inv_fact[i-1] * inv[i] % MOD;
	}
	
	for (int i=0; i<n; i++) {
		int r,c;
		cin>>r>>c;
		walls.push_back(pii(r,c));
	}
	sort(walls.begin(), walls.end());
	
	for (int i=0; i<=n; i++) {
		int x = walls[i].first;
		int y = walls[i].second;
		ans[i] = ways(x-1,y-1);
		for (int j=0; j<i; j++) {
			int nx = walls[j].first;
			int ny = walls[j].second;
		
			if (nx > x || ny > y) continue;
			
			ll tmp = ans[j] * ways(x-nx, y-ny);
			tmp %= MOD;
			
			ans[i] = ans[i] - tmp;
			ans[i] %= MOD;
			if (ans[i] < 0) {
				ans[i] = MOD+ans[i];
			}
		}
	}
	cout<<ans[n]<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
typedef long long int ll;
using namespace std;
int main(){
	ll N,K;
	cin >>N >>K;
	ll count=0;
	ll count1=0;
	ll ans=0;
	if(K%2==0){
		count=N/K;
		count1=N/(K/2)-count;
		ans=count*count*count+count1*count1*count1;
	}else{
		count=N/K; 
		ans=count*count*count;
	}
	cout << ans  << endl;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
ul N,i,j;
int F[100][10],P[100][11];
int ans,cc,c;
inline void solve(){
  IN(N);
  REP(i,N)REP(j,10)IN(F[i][j]);
  REP(i,N)REP(j,11)IN(P[i][j]);
  ans=-(1<<30);
  for(int b=1;b<(1<<10);b++){
    cc=0;
    REP(i,N){
      c=0;
      REP(j,10){
        if((b>>j&1)&&F[i][j])c++;
      }
      cc+=P[i][c];
    }
    chmax(ans,cc);
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int day30[4] = {4,6,9,11};
 
  while(1) {
  int m,d;
  cin >> m >> d;
  if(m == 0 && d == 0) break;
  int a = 1,b = 1,count = 0;
 
  while(1) {
 
    if(a == m && b == d) break;
     
    b++;
    count++;
 
    if(a == 2 && b == 30) {
      a++;
      b = 1;
    }
    else if(b == 31) {
      for(int i=0;i<4;i++) 
    if(day30[i] == a) {
      a++;
      b = 1;
      break;
    }
    }
    if( b == 32) {
      a++;
      b = 1;
    }
  }
   
  if(count % 7 == 4 ) cout <<"Monday"<<endl;
  else if(count % 7 == 5) cout << "Tuesday"<<endl;
  else if(count % 7 == 6) cout <<"Wednesday"<< endl;
  else if(count % 7 == 0) cout <<"Thursday"<< endl;
  else if(count % 7 ==1) cout << "Friday" << endl;
  else if(count % 7 ==2)cout << "Saturday" << endl;
  else if(count % 7 ==3) cout << "Sunday" << endl;
   
  }
 
return 0;

}

Measured memory_bytes: 1156
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		long a = 0;

		boolean[] sorted = new boolean[n];
		for (int from = 0, i = 1; from + k <= n; i++) {
			if (p[i - 1] < p[i]) {
				if (i + 1 != from + k) {
					continue;
				}
				sorted[from] = true;
				from++;
				if (a == 0) a = 1;
			} else {
				from = i;
			}
		}

		NavigableSet<Integer> s = new TreeSet<>();
		for (int i = 0; i < k; i++) {
			s.add(p[i]);
		}

		if (!sorted[0]) a++;
		for (int i = 0, j = k; j < n; i++, j++) {
			if (!sorted[i + 1] && !(p[i] == s.first() && p[j] > s.last())) a++;
			s.remove(p[i]);
			s.add(p[j]);
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 92736
#include <stdio.h>
#include <stdlib.h>

#define N 200
#define INT(X) (*((const int*)(X)))

static int d[N];
static int n;

static int compare(const void *a, const void *b) {
  if (INT(a) < INT(b)) return -1;
  if (INT(b) < INT(a)) return 1;
  return 0;
}

int main(void) {
  int res;
  int i;
  
  scanf("%d", &n);
  for (i = 0; i < 2 * n; ++i)
    scanf("%d", &d[i]);
  qsort(d, 2 * n, sizeof(int), compare);
  
  res = 0;
  for (i = 0; i < 2 * n; i += 2) {
    res += d[i];
  }
  printf("%d\n", res);
  
  return (0);
}


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

int main(){
int K;
long long ans = 0;
cin >> K;
int which_max,gcd_a_b,sub_max,gcd_a_b_c;
for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
        which_max = min(a,b);
        for(int i = 1; i <= which_max ; i++){
            if(a % i == 0 && b % i == 0){
                gcd_a_b = i;
            }
        }
        for(int c = 1; c <= K; c++){
            sub_max = min (c,gcd_a_b);
            for(int j = 1; j <= sub_max ; j++){
                if(gcd_a_b % j == 0 && c % j == 0){
                    gcd_a_b_c = j;
                }
            }
            ans += gcd_a_b_c;
        }
    }
}
cout << ans << endl;
}

Measured memory_bytes: 3616
def cin():  return list(map(int,input().split()))

N, K = cin()
P = cin()
C = cin()
for i in range(N):  P[i] -= 1

ans = -(10 ** 9 + 7)

for i in range(N):
    c = []
    j = i
    
    while(P[j] != i):
        j = P[j]
        c.append(C[j])
    c.append(C[i])
    
    if sum(c) <= 0:
        acc = [0]
        for i in c:  acc.append(acc[-1] + i)
        ans = max(ans, max(acc[1:K + 1]))
        
    else:
        loop_cnt = K // len(c)
        loop_mod = K - len(c) * loop_cnt
        acc = [(loop_cnt - 1) * sum(c)]
        for i in c:  acc.append(acc[-1] + i)
        for i in range(loop_mod):  acc.append(acc[-1] + c[i])
        ans = max(ans, max(acc))
        
print(ans)     

Measured memory_bytes: 124812
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int d1 = abs(a - x);
  int d2 = abs(b - x);
  if (d1 < d2) cout << "A" << endl;
  else cout << "B" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int l,r,d;
    cin>>l>>r>>d;
    int c=0;
    for (int i=l; i<=r; i++)
    {
        if (i%d==0)
            c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3644
n, a, b, c, d = list(map(int, input().split()))
s = input()
if d > c:
    for i in range(a, d-1):
        if (s[i-1] == "#") & (s[i] == "#"):
            print("No")
            break
    else:
        print("Yes")
else:
    for i in range(a, c):
        if (s[i-1] == "#") & (s[i] == "#"):
            print("No")
            break
    else:
        for j in range(b-1, d):
            if (s[j-1] == ".") & (s[j] == ".") & (s[j+1] == "."):
                print("Yes")
                break
        else:
            print("No")

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

int main() {
  long H;
  cin >> H;
 
 int a=0;
  while(H>1){
    H/=2;
    a++;
  }
 long b=2;
  
  while(a>0){
    b*=2;
    a--;
  }
   
  
  cout<<b-1<<endl;
    
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    combination C(N);
    vec<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end());
    mint ans = 0;
    for(int i=0;i<N;i++){
        ans += C.comb(i,K-1)*A[i];
        ans -= C.comb(N-i-1,K-1)*A[i];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}


//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}

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

	int N, A, B;

	cin >> N >> A >> B;

	int x=0;
	if (A + B > N) {
		x = A + B - N;
	}

	cout << min(A, B) << " " << x << endl;

	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut l: [usize; n],
    }

    l.sort();

    let mut ans = 0;

    for i in 0..n {
        for j in 0..i {
            for k in 0..j {
                if l[k] != l[j] && l[i] != l[j] && l[k] + l[j] > l[i] {
                    ans += 1
                }
            }
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 2192
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 2:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))


Measured memory_bytes: 21996
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll INF = 1LL << 60;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++)cin >> A[i];
    ll mini,maxi;
    ll ok = INF,ng = 0;
    while(abs(ok - ng) > 1){
        ll num = (ok + ng) / 2,mid = num;
        for(int j = 0;j < N;j++){
            num = num / A[j] * A[j];
        }
        if(num >= 2)ok = mid;
        else        ng = mid;
    }
    mini = ok;

    ok = 0,ng = INF;
    while(abs(ok - ng) > 1){
        ll num = (ok + ng) / 2,mid = num;
        for(int j = 0;j < N;j++){
            num = num / A[j] * A[j];
        }
        if(num <= 2)ok = mid;
        else        ng = mid;
    }
    maxi = ok;

    if(mini > maxi)cout << -1 << endl;
    else cout << mini << " " << maxi << endl;

}

Measured memory_bytes: 640
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	ll x,y,z,ans;
	cin>>x>>y>>z;
	for(int i=x/y;i>=0;i--){
		if((y*i+z*(i+1))<=x){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
maze=[tuple(input()) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
mod=10**9+7
dp[0][0]=1
for y in range(h):
  for x in range(w):
    if maze[y][x]=='#':
      dp[y][x]=0
    else:
      if y>0:
        dp[y][x]+=dp[y-1][x]
      if x>0:
        dp[y][x]+=dp[y][x-1]
      dp[y][x]%=mod
print(dp[-1][-1])

Measured memory_bytes: 50500
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    N = 10000
    f = [0]*(N+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                s = x**2+y**2+z**2+x*y+y*z+z*x
                if s <= N:
                    f[s] += 1
    for i in range(1,n+1):
        print(f[i])
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int N;
  cin>>N;
  uint64_t ans=1;
  uint64_t x = pow(10,9)+7;
  for(int i=1;i<=N;i++){
    ans *= i;
    ans %= x;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

int main()
{
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3580
// 問題URL
// https://atcoder.jp/contests/abc147/tasks/abc147_b

import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();

        int count = 0;
        for(int i = s.length(); i > 0; i--) {
            int x = s.length() - i;
            if(s.charAt(x) == s.charAt(i-1)) continue;
            count++;
        }
        System.out.println(count / 2);
    }
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int sum = 0;
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    sum += array[i] * array[j];
                }
            }
        }
        System.out.println(sum / 2);
    }
}


Measured memory_bytes: 21844
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
long long b[1000001];
void ep(int a[]){
  int i,j;
  for(i=1;i<=1000000;++i)
    a[i]=i;
  bool b[1000001]={};

  for(i=2;i<=1000000;++i){
    if(b[i])
      continue;
    for(j=i;j<=1000000;j+=i){
      a[j]-=a[j]/i;
      b[j]=true;
    }
  }
  return;
}
int main(){
  int i;
  int a[1000001];
  ep(a);
  //long long b[1000001];
  b[1]=2;
  for(i=2;i<=1000000;++i)
    b[i]=b[i-1]+a[i];
  int n;
  scanf("%d",&n);
  for(i=0;i<n;++i){
    int p;
    scanf("%d",&p);
    printf("%lld\n",b[p]);
  }
  return 0;
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define dump(x)  cerr << #x << " = " << (x) << endl;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 



//ここから書き始める
int main(int argc, char const *argv[])
{
	int H,W;
	cin >> H >> W;
	int a[H][W];

	string m[H];
	REP(i, H)
	{
		cin >> m[i];
	}

	int row_mark[H][W];
	int column_mark[H][W];
	int mark[H][W];
	REP(i, H)
	{
		REP(j, W)
		{
			if(m[i][j] == '#') a[i][j] = 1;
			if(m[i][j] == '.') a[i][j] = 0;
			row_mark[i][j] = 0;
			column_mark[i][j] = 0;
		}
	}


	REP(i, H)
	{
		REP(j, W)
		{
			if(a[i][j] == 1)
			{
				REP(k, H) row_mark[k][j] = 1;
				REP(l, W) column_mark[i][l] = 1;
			}

		}
	}
	REP(i, H)
	{
		REP(j,W)
		{
			mark[i][j] = row_mark[i][j] * column_mark[i][j];
		}
	}

	REP(i, H)
	{
		int sum = 0;
		REP(k,W)
		{
			sum += mark[i][k];
		}
		if(sum == 0) continue;


		REP(j, W)
		{
			if(mark[i][j] == 1) cout << (a[i][j] == 1 ? "#" : ".");
		}
		cout << endl;
	}


}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	ara[0]=0;
	f(i,1,n) cin>>ara[i];
	ara[n+1]=0;

	vi v;

	//v.pb(ara[0]);
    f(i,1,n+1){
        v.pb(abs(ara[i]-ara[i-1]));
    }
    //v.pb(abs(ara[n-1]-0));

    int sum=0;

    f(i,0,n) sum+=v[i];

    f(i,1,n){
        m=sum;
        m-=(v[i-1]+v[i]);
        m+=abs(ara[i+1]-ara[i-1]);
        cout<<m<<endl;
    }

}


Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define mp make_pair
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n%2)cout<<2*n<<endl;
	else cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	cin>>s;
	stack<char> st;
	rep(i,s.size()){
		if(st.empty())st.push(s[i]);
		else{
			if(s[i]=='S')st.push(s[i]);
			else{
				if(st.empty() ||st.top()=='T')st.push('T');
				else st.pop();
			}
		}
	}
	cout<<st.size()<<endl;
	return 0;
}

Measured memory_bytes: 644
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline
from math import gcd


def main():
    K=int(input())
    ret = 0
    gc=[[-1]*K for _ in range(K)]
    for a in range(K):
        for b in range(K):
            if gc[a][b]==-1:
                gc[a][b]=gcd(a+1,b+1)
                gc[b][a]=gc[a][b]
            x=gc[a][b]
            for c in range(K):
                if gc[x-1][c]==-1:
                    gc[x-1][c]=gcd(x,c+1)
                    gc[c][x-1]=gc[x-1][c]
                ret += gc[x-1][c]
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9392
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int H, W;
int white_count,count = 0;
vector<pair<int, int>> tmp_chenge;

void one_chenge(int h,int w,vector<vector<int>> &v){
    if(h > 0){
      if(v[h - 1][w] == 0){
        v[h - 1][w] = 1;
        white_count--;
        tmp_chenge.push_back(make_pair(h -1, w));        
      }
    }
    if(h < H -1){
      if(v[h + 1][w] == 0){
        v[h + 1][w] = 1;
        white_count--;
        tmp_chenge.push_back(make_pair(h + 1, w));
      }
    }
    if(w > 0){
      if(v[h][w -1] == 0){
        v[h][w - 1] = 1;
        white_count--;
        tmp_chenge.push_back(make_pair(h, w - 1));
      }
    }
    if(w < W -1){
      if(v[h][w + 1] == 0){
        v[h][w + 1] = 1;
        white_count--;
        tmp_chenge.push_back(make_pair(h, w + 1));
      }
    }
}

int main(){
  cin >> H >> W;
  white_count = H * W;
  vector<vector<int>> v(H,vector<int>(W,0));

  //入力
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      char tmp;
      cin >> tmp;
      if(tmp == '#'){
        v[i][j] = 1;
        tmp_chenge.push_back(make_pair(i, j));
        white_count--;
      }
    }
  }
  
  //計算  
  while(white_count > 0){
    int tmp_size = tmp_chenge.size();
    for(int i = 0; i < tmp_size; i++){
      one_chenge(tmp_chenge[i].first, tmp_chenge[i].second, v);
    }
    tmp_chenge.erase(tmp_chenge.begin(), tmp_chenge.begin() + tmp_size);
    count++;
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 14188