akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

inline bool valid(int x, int y, int W, int H){
    return x >= 0 && y >= 0 && x < W && y < H;
}

int encode(int x[4], int y[4]){
    int s = 0;
    for(int i = 0; i < 4; i++){
        s = (s << 8) | (x[i] << 4) | y[i];
    }
    return s;
}
void decode(int s, int x[4], int y[4]){
    for(int i = 3; i >= 0; i--){
        x[i] = (s >> 4) & 0xf;
        y[i] = s & 0xf;
        s >>= 8;
    }
}

int main(){
    int W, H;
    while(cin >> W >> H && W){
        char grid[30][30];
        REP(i, H) cin >> grid[i];
        int sx[4], sy[4];
        int rid = 1;
        REP(y, H) REP(x, W) if(grid[y][x] == '@'){ sx[0] = x, sy[0] = y; grid[y][x] = '.';
            REP(y, H) REP(x, W) if(grid[y][x] == '*'){ sx[rid] = x; sy[rid] = y; rid++; grid[y][x] = '.'; }
        }
        int start = encode(sx, sy);
        queue<int> que;
        map<int, int> dist;
        que.push(start);
        dist[start] = 0;
        while(!que.empty()){
            int s = que.front(); que.pop();
            int x[4], y[4];
            decode(s, x, y);
            bool goal = true;
            for(int i = 1; i < 4; i++) if(grid[y[i]][x[i]] != '_') goal = false;
            /*
            REP(i, 4) grid[y[i]][x[i]] = '1' + i;
            REP(y, H) cout << grid[y] << endl;
            cout << endl;
            REP(i, 4) grid[y[i]][x[i]] = '.';
            */
            if(goal){
                cout << dist[s] << endl;
                break;
            }
            const int dx[4] = {1, 0, -1, 0};
            const int dy[4] = {0, 1, 0, -1};
            REP(r, 4){
                int nx[4], ny[4];
                memcpy(nx, x, sizeof(x));
                memcpy(ny, y, sizeof(y));
                bool ok = true;
                for(int i = 0; i < 4; i++) if(nx[i] == nx[0] && ny[i] == ny[0]){ // i = 0 -> true
                    nx[i] += dx[r];
                    ny[i] += dy[r];
                    if(!valid(nx[i], ny[i], W, H) || grid[ny[i]][nx[i]] == '#') ok = false;
                }
                for(int i = 0; i < 4; i++) for(int j = i + 1; j < 4; j++) if(nx[i] == nx[j] && ny[i] == ny[j]) ok = false;
                int ns = encode(nx, ny);
                if(ok && !dist.count(ns)){
                    que.push(ns);
                    dist[ns] = dist[s] + 1;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 60220
n = int(input())
l = []
for i in range(n):
    x = input()
    if x[0] == "0":
        a, b = map(int, x.split())
        l.append(b)
    elif x[0] == "1":
        a, b = map(int, x.split())
        print(l[b])
    elif x[0] == "2":
        del l[-1]



Measured memory_bytes: 13360
import java.util.Scanner;

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

		if(A == 1)A = 14;
		if(B == 1)B= 14;
		if(A == B)
			System.out.println("Draw");
		else if(A > B)
			System.out.println("Alice");
		else
			System.out.println("Bob");
	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,a,ans=0,i,pos1,pos2;
	vector<long long> num;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		num.push_back(a);
	}
	sort(num.begin(),num.end());
	for(i=0;i<num.size();)
	{
		pos1=lower_bound(num.begin(),num.end(),num[i])-num.begin();
		pos2=upper_bound(num.begin(),num.end(),num[i])-num.begin();
		if((pos2-pos1)%2==1)
		{
			ans++;
		}
		i=pos2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 105;
const int MAXW = 100005;

ll N, W, w[MAXN], v[MAXN], dp[MAXN][MAXW], ninf = -1e18;

ll rec(ll ind, ll rem)
{
	if(rem < 0) return ninf;
	if(ind == N) return 0;
	if(dp[ind][rem] != -1) return dp[ind][rem];
	return dp[ind][rem] = max(v[ind] + rec(ind + 1, rem - w[ind]), rec(ind + 1, rem));
}

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

 	cin >> N >> W;
 	for(int i=0;i<N;i++) cin >> w[i] >> v[i];
 	memset(dp, -1, sizeof(dp));
 	cout << rec(0, W) << endl;
    return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
bool pp(string s)
{
    string t=s;
    reverse(s.begin(),s.end());
    return s==t;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      ll n,a,b;
      cin>>n>>a>>b;
    ll ans=(n/(a+b))*a;
    n=n%(a+b);
    if(n<=a)ans+=n;
    else ans+=a;
    cout<<ans<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(len(aa)-1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(len(aa)-2)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()


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

int main()
{
  char C[6];
  for (auto & c : C)
    cin >> c;
  cout << (((C[0] == C[5]) && (C[1] == C[4]) && (C[2] == C[3])) ? "YES" : "NO");
  return 0;
}


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

#define ll long long
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define vi vector<int>
#define vii vector<vi>

const int mod=1e9+7;
const ll MX=1<<30;

int n,a;
vii g(100005);

int dfs(int now){
    vi v;
    for(auto nx: g[now]){
        v.pb(dfs(nx));
    }
    if(v.empty()){
        return 1;
    }
    sort(v.begin(),v.end());
    ll cost=0;
    int l=g[now].size()-1;
    rep(i,g[now].size()){
        cost=max(cost,v[i]+l-i);
    }
    return cost+1;
}

signed main()
{
    cin >> n;
    rep(i,n-1){
        cin >> a;
        g[a-1].pb(i+1);
    }
    cout << dfs(0)-1 << endl;
}


Measured memory_bytes: 15104
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
pub const M: i32 = 1000000007;
fn main() {
    let ans = solve();
    println!("{}",ans );
}
fn solve() -> i32{
    let s = read::<String>();
    s.chars().fold((0,' '),|x,y| if y != x.1{
        (x.0+1,y)
    }else{
        (x.0,y)
    }).0 -1
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

struct Edge {
  int to;
  i64 cost;

  Edge(int _to, i64 _cost) : to(_to), cost(_cost) {}
};

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

  i64 a, b, c;
  cin >> a >> b >> c;

  i64 ans = a;
  c -= a;
  ans += min(b, c) + b;
  c -= b;
  if(c > 0) ans++;
  cout << ans << endl;
}


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

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    int k = b - a;

    if(k % 2 == 0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=998244353

n,k=map(int,input().split())
arr=[list(map(int,input().split()))+[i] for i in range(k)]
dp=[0]*(n+1)
dp[1]=1
sums=[0]*k
for i in range(2,n+1):
  for l,r,j in arr:
    if l>i:
      continue
    elif l<=i<=r:
      sums[j]+=dp[i-l]
    else:
      sums[j]-=dp[i-r-1]
      sums[j]+=dp[i-l]
    sums[j]%=mod
  for j in range(k):
    dp[i]+=sums[j]
print(dp[n]%mod)

Measured memory_bytes: 79688
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	for (int x=1; x<=9; ++x) for (int y=1; y<=9; ++y) {
		if (x * y == N) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if ((a % 2 == 0) && (a % 3 != 0) && (a % 5 != 0)) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;

int main(){
    iosetup;
    int N, T; cin >> N >> T;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];

    int MIN = 1e9;
    map<int,int> m;
    rep(i, 0, N){
        chmin(MIN, A[i]);
        m[A[i]-MIN]++;
    }
    auto e = *m.rbegin();
    cout << e.second << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int h, w; cin >> h >> w;
   V<V<char>> a(h, V<char>(w));
   for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
         cin >> a[i][j];
      }
   }

   V<V<char>> s(h, V<char>(w));
   for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
         if (i == 0) {
            s[i][j] = 'R';
            continue;
         }
         if (i == h-1) {
            s[i][j] = 'B';
            continue;
         }
         s[i][j] = (j % 2 == 0 ? 'R' : 'B');
      }
   }

   for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
         cout << (a[i][j] == '#' || s[i][j] == 'R' ? '#' : '.');
      }
      cout << endl;
   }
   cout << endl;
   for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
         cout << (a[i][j] == '#' || s[i][j] == 'B' ? '#' : '.');
      }
      cout << endl;
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,l[1000000],i,j,k,c=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> l[i];
    }
    sort(l,l+n,greater<int>());
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(l[i]<l[j]+l[k] && l[i]!=l[j] && l[i]!=l[k] && l[j] != l[k])
                {
                    c++;
                }
            }
        }
    }
    cout << c << endl;
    return 0;

}


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

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

    if (S == "AAA" || S == "BBB") { 
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
struct SegmentTree{
private:
    int N;
    vector<T> node;
    function<T(T, T)> F;
    T E;
public:
    void init(int n, function<T(T, T)> f, T e, T def){
        F = f;
        E = e;
        N = 1;
        while(N < n) N = (N<<1);
        node.assign(2*N-1, e);
        for(int i=0; i<n; i++) node[N-1+i] = def;
        for(int i=N-2; i>=0; i--) node[i] = F(node[(i<<1)+1], node[(i<<1)+2]);
    }
    T& operator [](int a){
        return node[N-1+a];
    }
    void update(int a, T x){
        a += N-1;
        node[a] = x;
        while(a > 0){
            a = (a-1)>>1;
            node[a] = F(node[(a<<1)+1], node[(a<<1)+2]);
        }
    }
    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return E;
        if(a <= l && r <= b) return node[k];
        return F(query(a, b, (k<<1)+1, l, (l+r)>>1), query(a, b, (k<<1)+2, (l+r)>>1, r));
    }
};

int N;
vector<string> S;
vector<pair<int, string>> S2;
int cnt[26] ={};

SegmentTree<int> st[26];
priority_queue<pair<int, pair<int, int>>> pq;

signed main(){
    cin >> N;
    rep(i, N){
        string s;
        cin >> s;
        if(s.size() == 1){
            cnt[s[0]-'a']++;
        }
        else{
            reverse(all(s));
            S.pb(s);
            S2.pb({ s.size(),s });
        }
    }
    sort(all(S));
    sort(all(S2));
    reverse(all(S2));
    N = S.size();
    
    ll ans = 0;
    rep(i, N){
        bool tmp[26] ={};
        rep(j, S[i].size()){
            tmp[S[i][j]-'a'] = true;
        }
        rep(j, 26){
            if(tmp[j]) ans += cnt[j];
        }
    }
    
    rep(i, 26) st[i].init(N, [](int a, int b){ return a+b; }, 0, 0);
    rep(i, N){
        while(pq.size() > 0 && pq.top().first >= S2[i].first-1){
            st[pq.top().second.first].update(pq.top().second.second, 1);
            pq.pop();
        }

        string tmp = S2[i].second.substr(0, S2[i].first-1);
        int l = lower_bound(all(S), tmp) - S.begin();
        tmp.back()++;
        int r = lower_bound(all(S), tmp) - S.begin();
        ans += st[S2[i].second.back()-'a'].query(l, r);

        int idx[26];
        memset(idx, -1, sizeof(idx));
        rep(j, S2[i].first){
            idx[S2[i].second[j]-'a'] = j;
        }
        rep(j, 26){
            pq.push({ idx[j],{j,lower_bound(all(S), S2[i].second)-S.begin()} });
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 175044
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
string S;
  cin >>S;
  int count=0;
  rep(i,3) {
if(S.at(i)=='o') {
  count++;
}
  }
  int z=700+count*100;
  cout <<z<< endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  for(int i=0;i<3;i++)
    if(a.at(i)=='1')
      a.at(i)='9';
    else
      a.at(i)='1';
  cout<<a<<endl;
}



Measured memory_bytes: 256
N, M, Q = gets.chomp.split.map(&:to_i)
ABCD = []
Q.times do
  ABCD.push(gets.chomp.split.map(&:to_i))
end

$ans = 0
def dfs(ar)
  if ar.size == N
    now = 0
    ABCD.each do |a, b, c, d|
      if ar[b-1] - ar[a-1] == c
        now += d
      end
    end
    $ans = [$ans, now].max
    return
  end

  if ar.empty?
    1.upto(M) do |i|
      arr = ar.dup.push(i)
      dfs(arr)
    end
  else
    ar.last.upto(M) do |i|
      arr = ar.dup.push(i)
      dfs(arr)
    end
  end
end

dfs([])
p $ans


Measured memory_bytes: 15552
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int n, S;
    int r[10000];
    while(std::cin >> n >> S, n){
        REP(i, n){
            std::cin >> r[i];
        }
        std::sort(r, r+n);
        int res = 0;
        for(int i=0;i+1<n;i++){
            auto it = std::upper_bound(r+i+1, r+n, S-r[i]);
            res += std::distance(it, r+n);
        }
        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <random>
#include <limits>
#include <string>
#include <sstream>
#include <iomanip>

#include <cassert>
#include <cmath>
#include <ctime>

#pragma comment(linker, "/STACK:200000000")

using namespace std;

mt19937 mt (736);

void solve (istream &cin = std::cin, ostream &cout = std::cout)
{
	int a, b, x;

	cin >> a >> b >> x;

	cout << (a <= x && x <= a + b ? "YES" : "NO") << endl;
}

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

#ifdef LOCAL
    solve ();

    cout << "clock: " << clock () << endl;
#else
    solve ();
#endif // LOCAL

    return 0;
}


Measured memory_bytes: 256
def output(pos)
  for i in 0..3 do
    for j in 0..2 do
      for k in 0..9 do
        printf " %d", pos[i][j][k]
      end
      printf "\n"
    end
    printf "####################\n" if i < 3
  end
end
# initializing of room
pos = Array.new(4){Array.new(3){Array.new(10,0)}}

n = gets.to_i
n.times do
  arr = gets.split(" ").map(&:to_i)
  pos[arr[0]-1][arr[1]-1][arr[2]-1] += arr[3]
end
output(pos)

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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n;
	map<pair<lli,lli>,lli> d;
	map<lli,vector<lli>> m;

	cin>>n;
	for(lli i=0;i<n-1;i++){
		lli u,b,w;
		cin>>u>>b>>w;
				u--,b--;
		d[make_pair(u,b)] = w;
		d[make_pair(b,u)] = w;
		m[u].push_back(b);
		m[b].push_back(u);
	}

	lli ds[100010];
	for(lli i=0;i<100010;i++)ds[i]=-1;

	ds[0]=0;
	/*始点0から幅優先探索する*/
	queue<lli> q;
	q.push(0);
	while(q.size()!=0){
		lli now = q.front();
		q.pop();
		lli nowDs = ds[now];
		for(lli i=0;i<m[now].size();i++){
			lli e = m[now].at(i);
			if(DEBUG)cout<<"e="<<e<<endl;
			if(ds[e] == -1){
				ds[e] = nowDs + d[make_pair(now,e)];
				q.push(e);
			}
		}
	}
	
	
	for(lli i=0;i<n;i++){
		if(ds[i]%2==0)cout<<0<<endl;
		else cout<<1<<endl;
	}


	return 0;
}

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

int main() {
  string s;
  cin >>s;
  int sa=INT_MAX;
  for(int i=0;i<s.size()-2;i++){
    int a,b,c;
    a=(s[i+0]-'0')*100;
    b=(s[i+1]-'0')*10;
    c=s[i+2]-'0';
    sa=min(abs(a+b+c-753),sa);
    //cout<<a+b+c<<endl;
  }
  cout<<sa<<endl;
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    long long sum = 0;
    for(int i = 0; i <= n; i++) {
        bool div3 = i % 3 == 0;
        bool div5 = i % 5 == 0;
        if(!div3 && !div5) {
            sum += i;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#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 x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
}

Measured memory_bytes: 3628
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
int anyDigitSum(int n) {
	int res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}

void Solve() {

	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a, a + 4);
	int b[] = { 1,4,7,9 };
	for (int i = 0; i < 4; i++)
	{
		if (a[i] != b[i]) {
			cout << "NO" << endl;
			return;
		}
	}

	cout << "YES";
	cout << endl;
}
int main() {
	Solve();
	return 0;
}



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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<string> split_naive(const string &s, char delim) {
    vector<string> elems;
    string item;
    for(char ch : s) {
        if(ch == delim) {
            if(!item.empty()) elems.push_back(item);
            item.clear();
        } else {
            item += ch;
        }
    }
    if(!item.empty()) elems.push_back(item);
    return elems;
}

int N;
map<pair<int, string>, ll> cnt;
string option = "TAGC";

bool ok(const string s) {
    if(s.find("AGC") != string::npos) return false;
    vector<char> target;
    REP(i, s.length()) target.emplace_back(s[i]);
    REP(i, 3) {
        swap(target[i], target[i + 1]);
        string temp = "";
        REP(j, 4) temp += target[j];
        if(temp.find("AGC") != string::npos)
            return false;
        else
            swap(target[i], target[i + 1]);
    }
    return true;
}

ll countDP(string last, ll idx) {
    if(cnt[{idx, last}] != 0) return cnt[{idx, last}];
    if(idx == N) {
        // cout << last << "\n";
        return 1;
    }
    ll res = 0;
    FOREACH(c, option) {
        if(ok(last + c)) {
            string next = last.substr(1, 2) + c;
            (res += countDP(next, idx + 1) % MOD) %= MOD;
        }
    }
    cnt[{idx, last}] = res;
    return res;
}

int main() {
    cin >> N;
    cout << countDP("TTT", 0) << "\n";
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

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

const ll mod = 998244353;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll f(ll n, ll x){
    if(n == 0){
        return 1;
    }
    else if(x <= 0){
        return 0;
    }
    else if(n < 0){
        return 0;
    }
    else{
        return comb(n + x - 1, n);
    }

}


ll pow2[10000];

int main() {
    ll K, N;
    cin >> K >> N;
    make_fact(10000);
    make_invfact(10000);

    pow2[0] = 1;
    for(int i = 1; i <= 2 * N + 10; i++){
        pow2[i] = mul(pow2[i-1], 2);
    }

    for(ll k = 2; k <= 2 * K; k++){
        ll res = 0;
        if(k % 2 == 1){
            ll l = k / 2 - max(0LL, k - K - 1);
            for(ll x = 0; x <= l; x++){
                ll tmp = mul(mul(comb(l, x), pow2[x]), f(N-x, K - 2 * l + x));
                res = add(res, tmp);
            }

        }
        else{
            ll l = k / 2 - max(0LL, k - K - 1);
            for(ll x = 0; x <= l-1; x++){
                ll tmp1 = mul(mul(comb(l-1, x), pow2[x]), f(N-1-x, K-2*l+1+x));
                ll tmp2 = mul(mul(comb(l-1, x), pow2[x]), f(N-x, K-2*l+1+x));
                res = add(res, tmp1);
                res = add(res, tmp2);
            }
        }
        cout << res << endl;
    }

    return 0;
}

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

const int MAX = 1000000;
int tri[200];
int dp[MAX], o_dp[MAX];

int main()
{
	for (int i = 0; i < 200; i++) {
		tri[i] = i*(i + 1)*(i + 2) / 6;
	}

	dp[0] = 0;
	o_dp[0] = 0;

	for (int i = 1; i < MAX; i++) {
		dp[i] = i;
		o_dp[i] = i;

		for (int j = 1; i - tri[j] >= 0; j++) {
			dp[i] = min(dp[i], dp[i - tri[j]] + 1);

			if (tri[j] % 2 == 1) {
				o_dp[i] = min(o_dp[i], o_dp[i - tri[j]] + 1);
			}
		}
	}

	while (true) {
		int n;
		cin >> n;

		if (n == 0) {
			break;
		}

		cout << dp[n] << " " << o_dp[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 10920
s = list(str(input()))

n = len(s)
N = int((n-1)/2)
M = int((n+3)/2)

l = []
m = []

for i in range(N):
    l.append(s[i])
    
for i in range (M-1,n):
    m.append(s[i])
    
a = ''.join(l)
l.reverse()
A = ''.join(l)

b = ''.join(m)
m.reverse()
B = ''.join(m)

t = s
t.reverse()
x = ''.join(s)
y = ''.join(t)

if (a==A and b==B and a == b):
    print('Yes')
else:
    print('No')

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

struct Dish {
    long a, b, sum;
    Dish(long a, long b) : a(a), b(b), sum(a + b) {}
    bool operator<(const Dish& x) {
        return sum < x.sum;
    }
};

int main() {
    int n;
    cin >> n;
    vector<Dish> dishes;
    for (int i = 0; i < n; i++) {
        long a, b;
        cin >> a >> b;
        dishes.push_back(Dish(a, b));
    }
    long ans = 0;
    sort(dishes.begin(), dishes.end());
    for (int i = 0; i < n; i++) {
        ans += ((i & 1) == 0) ? dishes[n - i - 1].a : -dishes[n - i - 1].b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,s=0,a;
  cin>>n;
  long h[100001]={0};
  for(int i=0;i<n;i++){
    cin>>a;
    h[a]++;
    s+=a;
  }
  int k,i,j;
  cin>>k;
  while(k--){
    cin>>i>>j;
   // h[j]++;
    if(h[i]!=0){
        s+=(h[i]*j-h[i]*i);
        h[j]+=h[i];
        h[i]=0;
    }
    cout<<s<<endl;
    
  }
  return 0;
}


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

typedef long long ll;

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int m = 0;
    cin >> m;
    int ans = 0;

    if(m >= 400 && m < 600) ans = 8;
    if(m >= 600 && m < 800) ans = 7;
    if(m >= 800 && m < 1000) ans = 6;
    if(m >= 1000 && m < 1200) ans = 5;
    if(m >= 1200 && m < 1400) ans = 4;
    if(m >= 1400 && m < 1600) ans = 3;
    if(m >= 1600 && m < 1800) ans = 2;
    if(m >= 1800 && m < 2000) ans = 1;


    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define LL long long 
#define N 100005     
#define setIO(s) freopen(s".in","r",stdin)     
using namespace std;
const LL mod=1000000007; 
LL a[N],n,inv[N],sum[N]; 
LL fac(int p) 
{
    LL ans=1ll; 
    for(int i=2;i<=n;++i) ans=ans*1ll*i%mod; 
    return ans; 
}
int main() 
{
    // setIO("input"); 
    int i,j; 
    scanf("%d",&n);
    for(i=1;i<=n;++i) scanf("%lld",&a[i]);  
    sum[1]=inv[1]=1ll; 
    for(i=2;i<=n;++i) 
    {
        inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod; 
        sum[i]=(sum[i-1]+inv[i])%mod;   
    }
    LL ans=0ll; 
    for(i=1;i<=n;++i) 
    {
        ans=(ans+a[i]*((sum[i]-sum[0]+sum[n-i+1]-sum[1]+mod)%mod)%mod)%mod; 
    }
    printf("%lld\n",ans*fac(n)%mod);   
    return 0; 
}

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

int main() {
    long long n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2;
    }
    else{
        cout << min(a-1,n-b)+1+(b-a-1)/2;
    }
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int res;
    for(res = 1; res <= 100000; res++){
        if((int)(res * 0.08) == a && (int)(res * 0.1) == b) break;
    }
    
    if(res == 100001) res = -1;
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
counter = 0
list = ['3','5','7']
ok = []
for a in list:
    for b in list:
        for c in list:
            ok.append(a+b+c)
            for d in list:
                ok.append(a+b+c+d)
                for e in list:
                    ok.append(a+b+c+d+e)
                    for f in list:
                        ok.append(a+b+c+d+e+f)
                        for g in list:
                            ok.append(a+b+c+d+e+f+g)
                            for h in list:
                                ok.append(a+b+c+d+e+f+g+h)
                                for i in list:
                                    ok.append(a+b+c+d+e+f+g+h+i)
                                    for j in list:
                                        ok.append(a+b+c+d+e+f+g+h+i+j)

sub = []
for _ in ok:
    x3 = _.count('3')
    x5 = _.count('5')
    x7 = _.count('7')
    if x3>0 and x5>0 and x7>0:
        sub.append(_)
fin = [int(_) for _ in sub]
fin.sort()
for _ in fin:
    if _ > N:
        print(fin.index(_))
        break


Measured memory_bytes: 13360
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	n := oneInt()
	as := scanNums(n)

	ans := calc(as)

	fmt.Println(ans)
}

func calc(as []int) int64 {
	var minusCount int
	var answer int64

	minAbs := abs(as[0])
	for _, ai := range as {
		if ai < 0 {
			minusCount++
		}
		answer += int64(abs(ai))
		minAbs = min(minAbs, abs(ai))
	}
	if minusCount%2 == 0 {
		return answer
	} else {
		answer += int64(minAbs * -2)
	}
	return answer
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}

func nextWord(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanNums(n int) (nums []int) {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		s := nextWord(sc)
		num, _ := strconv.Atoi(s)
		nums = append(nums, num)
	}
	return nums
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 5888
#include <stdio.h>
#include <math.h>

int main(void){

  int a,b,c,k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  int max = a;
  if (b > max) {
    max = b;
  }
  if (c > max) {
    max = c;
  }
  long answer = a+b+c-max+max*pow(2,k);
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
from collections import deque
n = int(input())
a = [int(input()) for _ in range(n)]

a.sort()
a = deque(a)

b = deque([a.pop()])

ans = 0
for _ in range(n - 1):
    x = max(
        abs(a[0] - b[0]),
        abs(a[0] - b[-1]),
        abs(a[-1] - b[0]),
        abs(a[-1] - b[-1]),
    )
    if x == abs(a[0] - b[0]):
        b.appendleft(a.popleft())
    elif x == abs(a[0] - b[-1]):
        b.append(a.popleft())
    elif x == abs(a[-1] - b[0]):
        b.appendleft(a.pop())
    else:  # x == abs(a[-1] - b[-1]):
        b.append(a.pop())
    ans += x

print(ans)


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

int main() {
char F[3];
char A[3];
for(int i=0;i<3;i++)
cin>>F[i];
for(int i=0;i<3;i++)
cin>>A[i];
int count = 0;
for(int i=0;i<3;i++) {
  if(A[i] == F[i])
  count++;
}
cout<<count<<endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,m,k;

double arr[N];

void solve()
{
    int n;
    cin>>n>>k;
    forn(i,1,n)
    {	
    	int a;
    	cin>>a;
    	arr[i] = (a*a+a)/2;
    	arr[i]/=a;
    }

    double ans = 0,sum = 0;

    forn(i,1,k)
    {

    	sum+=arr[i];
    }

    ans = sum;
    forn(i,k+1,n)
    {
    	sum-=arr[i-k];
    	sum+=arr[i];
    	ans = max(ans,sum);
    }
    //ans=k;
    cout<<setprecision(10)<<ans;



}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

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

using namespace std ;

#define N 100010
#define inf 0x3f3f3f3f
#define ll long long

int n , t ;
int a[ N ] ;

int main() {
	scanf( "%d%d" , &n , &t ) ;
	for( int i = 1 ; i <= n ; i ++ ) scanf( "%d" ,&a[ i ] ) ;
	int ans = 0 , mx = 0 ;
	int tot = 0 ;
	for( int i = n ; i  ; i -- ) {
		mx = max( a[ i ] , mx ) ;
		ans = max( mx - a[ i ] , ans ) ;
	}
	mx = 0 ;
	for( int i = n ; i ; i -- ) {
		mx = max(  a[ i ] , mx ) ;
		if( mx - a[ i ] == ans ) tot ++ ;
	}
	printf( "%d\n" , tot ) ;
	return 0 ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ul>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
struct graph
{
    vi v;
};
graph G[MAX_];
bool vis[MAX_];
void  dfs(int start)
{
    vis[start] = 1;
    for(int i =0;i<G[start].v.size();i++)
    {
        int u = G[start].v[i];
        if(vis[u] == false)
        {
            dfs(u);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;  cin>>n>>m;
    memset(vis,false,sizeof(vis));
    for(int i =0;i<m;i++)
    {
        int x,y,z;   cin>>x>>y>>z;
        G[x].v.pb(y);
        G[y].v.pb(x);
    }
    int ans =0;
    for(int i =1;i<=n;i++)
    {
        if(vis[i] == false)
            dfs(i),ans++;
    }
    cout << ans;

       
    return 0;
}
    


Measured memory_bytes: 11392