akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve()
{
	ll n,x,m;
	cin>>n>>x>>m;
	set<ll> s;
	ll p[m] = {};
	ll cnt = 0;
	ll sum = 0;
	vector<ll> v;
	while(s.find(x%m)==s.end())
	{
		s.insert(x%m);
		sum += x%m;
		v.push_back(x%m);
		cnt++;
		x = (x*x)%m;
	}
	if(v[v.size()-1]==0)
	{
		cout<<sum<<endl;
		return;
	}
	// cout<<v.size()<<endl;
	ll ans = 0;
	int i;
	for (i = 0; i < v.size(); ++i)
	{
		if(v[i]==x)
			break;
		cnt--;
		n--;
		ans += v[i];
		sum -= v[i];
	}

	// cout<<n<<endl;
	ans += (n/cnt)*sum;
	n %= cnt;

	for (int j = 0; j < n; ++j)
	{
		ans += v[i+j];
	}
	cout<<ans<<endl;
}

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

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

int bubble_sort(vector<int> &A, int n){
  int flag = 1;
  int i = 0;
  int c = 0;
  while( flag ){
    flag = 0;
    for( int j = n-1 ; j > i ; j--){
      if( A.at(j-1) > A.at(j) ){
        swap(A.at(j-1),A.at(j));
        flag = 1;
        c++;
      }   
    }
    i++;
  }
  return c;
}

int main(){
  int n;
  cin >> n ;
  
  vector<int> A(n);
  rep(i,n){
    cin >> A.at(i);
  }

  int c = bubble_sort(A,n);

  rep(i,n){
    cout << A.at(i);
    if( i < n-1 ) cout << " " ;
  }
  cout << endl << c << endl;
}


Measured memory_bytes: 3108
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h_list=list(map(int,input().split()))
h_list.sort()
if k>=n:
    print(0)
else:
    ans=0
    for i in range(n-k):
        ans+=h_list[i]
    print(ans)


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

// 0..n까지 xor한 값을 리턴하는 함수
long long nxor(long long n) {
	// n이 음수라면 0을 리턴한다
	if (n < 0) return 0;

	if (n & 1) {
		// n이 홀수라면 (n + 1) / 2개의 1이 나온다
		long long cnt = (n + 1) / 2;
		return cnt & 1;
	}
	else {
		// n이 짝수라면 n / 2개의 1과 n이 나온다
		long long cnt = n / 2;
		return (cnt & 1) ^ n;
	}
}
int main() {
	long long A, B;
	cin >> A >> B;

	cout << (nxor(A - 1) ^ nxor(B));

	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [x, n] <- getIntList
  s <- Set.fromList <$> getIntList

  let solve :: Int -> IO Int
      solve i = if Set.member (x-i) s
                then if Set.member (x+i) s
                     then solve (i+1)
                     else return (x+i)
                else return (x-i)

  ans <- solve 0
  print ans


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

int main(){
	int n;
	cin >> n;
	while(n--){
		int r,t;
		cin >> r >> t;
		if( r % 100 == 0 and t % 30 == 0 ){
			cout << (r / 100) + (t/30) * 5 << endl;
		}else if( r % 100 == 0 ){
			cout << (r / 100) + (t/30) * 5 << " ";
			cout << (r / 100) + ((t+29)/30) * 5 << endl;
		}else if( t % 30 == 0 ){
			cout << (r / 100) + (t/30) * 5 << " ";
			cout << (r+99) / 100 + (t/30) * 5 << endl;
		}else{
			cout << (r / 100) + (t/30) * 5 << " ";
			cout << (r+99) / 100 + (t/30) * 5 << " ";
			cout << (r / 100) + ((t+29)/30) * 5 << " ";
			cout << (r+99) / 100 + ((t+29)/30) * 5 << endl;
		}
	}

}

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

template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;
    vector<int> sizes;

    Unionfind(int n) : par(n), sizes(n, 1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return sizes[root(x)];
    }

};

const int MOD = 1e9+7;

ll modpow(int x, int times) {
    ll res = 1;
    for(int i = 0; i < times; ++i) {
        res = (res * x) % MOD;
    }
    return res;
}

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

    int n;
    cin >> n;

    ll ans = modpow(10, n) - modpow(9, n) - modpow(9, n) + modpow(8, n);

    ans %= MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
from collections import deque
from copy import copy
from array import array

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

N = int(input())
A = list(map(int, input().split()))

def get_prefix_gcd_list(Adeque):
    prefix_gcd = array('i', [0]*N)
    # marker
    prefix_gcd[0] = 0
    # the first itself is gcd
    prefix_gcd[1] = Adeque.popleft()
    for i in range(2,N):
        a = Adeque.popleft()
        prefix_gcd[i] = gcd(prefix_gcd[i-1], a)
        pass
    return prefix_gcd
        
    
# PREFIX_GCD[i]...i より前の要素のGCD
PREFIX_GCD = get_prefix_gcd_list(deque(copy(A)))

# PREFIX_GCD[i]...i より後の要素のGCD
POSTFIX_GCD=list(reversed(get_prefix_gcd_list(deque(reversed(A)))))

gcd_max=1

for i in range(N):
    pre = PREFIX_GCD[i]
    pos = POSTFIX_GCD[i]
    if pre == 0:
        _gcd = pos
    elif pos == 0:
        _gcd = pre
    else:
        _gcd = gcd(pre,pos)
    gcd_max = max(gcd_max, _gcd)
        
print(gcd_max)


Measured memory_bytes: 70876
#include<bits/stdc++.h>
using namespace std;
long N,x,a[2000][2000],ans;//a[魔法を唱えられる回数i][スライムの色j]は魔法をi回以下唱えたときにスライムjを得るための最小時間
int main(){
  cin>>N>>x;
  for(int i=0;i<N;ans+=a[0][i++])cin>>a[0][i];//このfor文が終了するとansはaの合計値でこれは魔法を0回唱えたときに相当する
  for(int i=1;i<N;i++){//iは魔法を唱えられる回数
    long s=i*x;//魔法を唱えるのに必要な合計時間
    for(int j=0;j<N;s+=a[i][++j%N])a[i][(j+1)%N]=min(a[i-1][(j+1)%N],a[i-1][j]);//二次元の表を書くと意味がわかりやすい
    ans=min(ans,s);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
int N, X, L[1010];
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    FOR(i, 0, N)
    {
        cin >> L[i];
    }
    int a = 0;
    int ans = 1;
    FOR(i, 0, N)
    {
        a += L[i];
        if (a <= X) {
            ans++;
        }
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int r,d,x;cin>>r>>d>>x;
  rep2(i,1,11){
    x=r*x-d;
    cout<<x<<endl;
  }
  //cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  double r;
  cin >> r;

  cout << 2 * r * M_PI << endl;;

  return 0;
}

Measured memory_bytes: 3796
/*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long
   #define w(t) int t; cin>>t; while(t--)
   #define fo(i,n) for(int i=0;i<n;i++)
   #define endl "\n" 
   #define MOD 1000000007
   void Tez(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
   }
   int main(){
      Tez();
      ll d,t,s;
      cin>>d>>t>>s;
      if(t*s>=d) cout<<"Yes";
      else cout<<"No";
      return 0;
   }



Measured memory_bytes: 3608
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    n <- getLine
    putStrLn $ if '7' `elem` n then "Yes" else "No"


Measured memory_bytes: 3696
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        K: u32,
    }
    let odd = (K+1)/2;
    let even = K/2;
    println!("{}",odd*even);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll res = (n/500)*1000;
  n -= (n/500)*500;
  res += (n/5)*5;
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int n;
  cin >> n;
  bool bit[200000][30] = {};
  int sum[30] = {};
  LOOP(i,n){
    int a;
    cin >> a;
    int cnt = 0;
    while(true){
      bit[i][cnt] = a%2;
      sum[cnt] += a%2;
      // cout << bit[i][cnt];

      a/=2;cnt++;
      if(a==0)break;
    }
    // cout << endl;
  }
  // LOOP(i,19){
  //   cerr << sum[i] << endl;
  // }

  LOOP(i,n){
    int ans = 0;
    int k = 1;
    LOOP(j,30){
      int sc = sum[j] - bit[i][j];
      ans += (sc%2) * k;
      // ans += ((sum[j]%2) ^ bit[i][j])*k;
      k *= 2;
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    int x, y;
    cin >> s >> x >> y;
    
    vector<vector<int>> v(2);

    int cnt = 0, dir = 0;
    bool init = true;
    REP(i, s.size()){
        if(s[i] == 'T'){
            if(init){
                x -= cnt;
                cnt = 0;
                init = false;
            }
            v[dir].push_back(cnt);
            cnt = 0;
            dir = !dir;
        }else{
            cnt++;
        }
    }
    if(init){
        x -= cnt;
    }else{
        v[dir].push_back(cnt);
    }

    sort(rall(v[0]));
    sort(rall(v[1]));

    int dx = abs(x), dy = abs(y);

    for(auto i : v[0]){
        dx = abs(dx - i);
    }
    for(auto i : v[1]){
        dy = abs(dy - i);
    }

    cout << (dx == 0 && dy == 0 ? "Yes" : "No") << endl;
    return 0;
}


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

#define x first
#define y second

#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cerr << #x << ": " << x << endl;
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

ll N,m[2],M[2];
pll boxes[200000];
ll r=LLONG_MAX;
ll dp[200000];

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

	cin >> N;
	m[0]=m[1]=INT_MAX;
	for (int i=0;i<N;i++) {
		cin >> boxes[i].x >> boxes[i].y;
		if (boxes[i].x>boxes[i].y) swap(boxes[i].x,boxes[i].y);
		smin(m[0],boxes[i].x);
		smax(M[0],boxes[i].x);
		smin(m[1],boxes[i].y);
		smax(M[1],boxes[i].y);
	}

	r=(M[0]-m[0])*(M[1]-m[1]);
	DEBUG(r);

	sort(boxes,boxes+N);
	fill(dp,dp+N,boxes[N-1].x);
	ll cM=boxes[0].y;
	for (int i=1;i<N;i++) {
		smax(dp[i],cM);
		smax(cM,boxes[i].y);
	}

	ll b=LLONG_MAX;
	for (int i=0;i<N;i++) smin(b,dp[i]-min(boxes[i].x,m[1]));
	DEBUG(b);
	DEBUG(M[1]-m[0]);
	DEBUG(r);
	smin(r,(M[1]-m[0])*b);
	cout << r << endl;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void)
{
  int p[5], j[5], i, min=(1<<20), t, k;
  scanf("%d %d %d",&p[0],&p[1],&p[2]);
  scanf("%d %d",&j[0],&j[1]);
  for(i = 0;i < 3;i++){
    for(k = 0;k < 2;k++){
      t   = p[i] + j[k] - 50; 
      if(min > t){min = t;}
        
    }
  }
  printf("%d\n",min);  
return 0;
 
}

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

int main() {
    //
    int n, m, x;
    long long Min = 999999999;

    cin >> n >> m >> x;
    vector<long long> kin(n);
    vector<vector<int>> data(n, vector<int>(m));

    for (int i = 0; i < n; i++) {
        cin >> kin.at(i);
        for (int j = 0; j < m; j++) cin >> data.at(i).at(j);
    }

    for (int bit = 0; bit < (1 << n); bit++) {
        long long tmpMin = 0;
        vector<int> sumRikai(m, 0);
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                tmpMin += kin.at(i);
                for (int j = 0; j < m; j++) sumRikai.at(j) += data.at(i).at(j);
            }
        }

        bool chk = true;
        for (int i = 0; i < m; i++) {
            if (sumRikai.at(i) < x) {
                chk = false;
                break;
            }
        }
        if (chk == true) Min = min(Min, tmpMin);
    }

    if (Min == 999999999) cout << -1;
    else cout <<Min;

    //
}

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;


char buf[110];
int hist[300];

int main(void) {
  scanf("%s", buf);
  for(int i = 0; buf[i]; ++i) {
    hist[(int)buf[i]]++;
  }
  REP(i, 26) {
    if(hist['a'+i] & 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll n=0;
    string sn;
    cin >> n;
    sn = to_string(n);
    ll sum=0; 
    for(int i=0;i<sn.size();i++){
        sum += (sn.at(i) -'0');
    }
    if(n%sum==0) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int x, y;

  while(true){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x < y) cout << x << " " << y << endl;
    else cout << y << " " << x << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
n,c = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
ans = 0
num = 0
nu = 0
cou = 0
co = 0
go = 0
left = []
right = []
for i in range(n):
    num += lis[i][1]
    go = lis[i][0]
    ans = max(ans,num-go)
    if cou < num-go:
        cou = num-go
        left.append([go,num])
    else:
        try:left.append(left[-1])
        except:left.append([0,0])

for i in reversed(range(n)):
    nu += lis[i][1]
    go = c-lis[i][0]
    ans = max(ans,nu-go)
    if co < nu-go:
        co = nu-go
        right.append([go,nu])
    else:
        try:right.append(right[-1])
        except:right.append([0,0])
gone = 0
gon = 0
for i in range(n-1):
    gone += lis[i][1]
    ans = max(ans,gone + right[n-i-2][1] - lis[i][0] * 2 - right[n-i-2][0])
    gon += lis[-(i+1)][1]
    ans = max(ans,gon + left[n-i-2][1] - (c-lis[-(i+1)][0]) * 2 - left[n-i-2][0])
print(ans)


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

int main(){
	int n;
	long long k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
		a[i]--;
	}

	std::vector<int> s; //回る町iを挿入していく
	std::vector<int> ido(n+1, -1); //町iまでの総移動回数
	int v = 0, cycle, length;
	//v = 1 ... start
	//cycle ... 周期,
	//length ... startから最初の周期が始まる前までの長さ
	while(ido[v] == -1){
		s.push_back(v);
		ido[v] = s.size()-1;
		v = a[v];
	}
	cycle = s.size() - ido[v];
	length = ido[v];

	if(k < length){
		std::cout << s[k] + 1 << std::endl;
	}else{
		k -= length;
		k %= cycle;
		std::cout << s[length + k] + 1 << std::endl;
	}
	return 0;
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    vi a(3);
    cin>>a;
    sort(ALL(a));
    if(a[0]==a[1]) {
        cout<<a[2]<<endl;
    } else {
        cout<<a[0]<<endl;
    }
    return 0;
}


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

signed main() {
	ll N, K;
	scanf("%lld%lld", &N, &K);
	vector<ll> A(N, 0);
	for(ll i=0; i<N; i++){
		scanf("%lld", &A[i]);
	}

	vector<ll> B(N, 0);
	for(ll i=0; i<N; i++){
		B[i]=A[i]-1;
	}

	vector<ll> T(N+1,0);
	for(ll i=0; i<N; i++){
		T[i+1]=T[i]+B[i];
	}

	ll ans = 0;
	map<ll,ll> m;
	for(ll i=0; i<N+1; i++){
		ll j=i-K;
		if(j>=0){
			ll s=T[j]%K;
			m[s]--;
		}
		ll t=T[i]%K;
		if(m[t]>0){
			ans+=m[t];
		}
		m[t]++;
	}

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


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll arr[100100],n,ans,temp1,temp2,a,b,m,p,k;
vector<ll> other,ten;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]%10==0)
            ten.pb(arr[i]);
        else
            other.pb(arr[i]);
    }
    sort(other.rbegin(),other.rend());
    sort(ten.rbegin(),ten.rend());
    for(int i=0;i<other.size();i++)
        temp1+=other[i];
    for(int i=0;i<ten.size();i++)
        temp2+=ten[i];
    if(ten.size()!=0)
    {
        if(other.size()==0)
        {
            cout<<"0"<<endl;
        }
        else if(temp1%10==0)
        {
            temp1-=other[other.size()-1];
            cout<<(temp1+temp2)<<endl;
        }
        else
        {
            cout<<(temp1+temp2)<<endl;
        }
    }
    else
    {
        if(temp1%10==0)
        {
            temp1-=other[other.size()-1];
            cout<<temp1<<endl;
        }
        else
        {
            cout<<temp1<<endl;
        }
    }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
	ll a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	ans += min(a, k);
	k -= a;
	k = max(k, 0LL);
	k -= b;
	k = max(k, 0LL);
	ans -= min(c, k);
	k -= a;
	k = max(k, 0LL);
	cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    long long t[n],a[n],s[n];
    for(int i=0; i<n; i++){
        cin >> t[i] >> a[i];
        s[i] = t[i]+a[i];
    }
    long long p,q,r;
    p=t[0];
    q=a[0];
    r=s[0];
    for(int i=1; i<n; i++){
        long long k = (p-1)/t[i] + 1;
        k = max(k,(q-1)/a[i]+1);
        k = max(k,(r-1)/s[i]+1);
        p = k*t[i];
        q = k*a[i];
        r = k*s[i];
    }
    cout << r << endl;
    return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    p[i]=i;
  }
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin >> a[i];
    swap(p[a[i]-1],p[a[i]]);
  }

  vector<int> x(m);
  for(int i=0;i<m;i++){
    x[i]=i;
  }

  int ans=1000;
  do{
    vector<int> q(n),l(n,0);
    for(int i=0;i<n;i++){
      q[i]=i;
    }
    int tmp=1;
    for(int i=0;i<m;i++){
      swap(q[a[x[i]]-1],q[a[x[i]]]);
      int t=max(l[a[x[i]]-1],l[a[x[i]]])+1;
      l[a[x[i]]-1]=l[a[x[i]]]=t;
      tmp=max(tmp,t);
    }
    for(int i=0;i<n;i++){
      if(q[i]!=p[i]){
        goto next;
      }
    }
    ans=min(ans,tmp);
    next:;
  }while(next_permutation(x.begin(),x.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<deque>
#include<cctype>
using namespace std;
int main() 
{
	char start,end;
    string s;
    cin>>s;
    start=s[0];
    end=s[s.size()-1];
    int t=s.size()-2;
    cout<<start<<t<<end;
    return 0; 
}
    

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

int main(void){
  int n;
  bool p[1000000];
  p[0] = p[1] = 0;
  p[2] = 1;
  int ans = 0;
  bool flag;
  for(int i = 0; i < 1000000; i++)
    p[i] = false;
  p[2] = true;
  for(int i = 3; i <= 1000000; i += 2){
    flag = true;
    for(int j = 3; j * j <= i; j += 2){
      if(i % j == 0){
	flag = false;
	break;
      }
    }
    if(flag)
      p[i] = true;
  }
  // cout << "end" << endl;
  while(cin >> n){
    int ans = 0;
    for(int i = 2; i <= n; i++){
      if(p[i])
	ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2132
import java.util.*;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int x= n/3600,  y= (n-x*3600)/60,  z= n%60;

		System.out.println(x +":"+ y +":"+ z);
	}
}

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

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int Y, M, D, ans;
    cin >> Y >> M >> D;
    ans = 0;
    if(Y % 3){
      if(M & 1)
	ans += 20 - D;
      else
	ans += 19 - D;
      if(10 - M & 1)
	ans += (10 - M + 1) / 2 * 19 + (10 - M - 1) / 2 * 20;
      else
	ans += (10 - M) / 2 * (19 + 20);
    }else{
      ans += 20 - D;
      ans += (10 - M) * 20;
    }
    for(int j = Y + 1; j < 1000; j++)
      if(j % 3)
	ans += 5 * (19 + 20);
      else
	ans += 10 * 20;
    cout << ans + 1 << endl;
  }
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 対象の文字列
    String S = sc.next();

    // 文字列の長さ
    int N = S.length();

    // 文字列の長さの配列を作る
    int A[] = new int[2019];
    A[0] =1;
    int dight = 1;
    long ans = 0;
    int tmp = 0;
    for(int i=N-1; i>=0 ;i--){
      int x = Character.getNumericValue(S.charAt(i));
      tmp=((x*dight)+tmp)%2019;
      ans +=A[tmp];
      A[tmp]++;
      dight = dight * 10 % 2019;
    }
    System.out.print(ans);
  }  
  
}




Measured memory_bytes: 40752
#include <iostream>
#include <map>
#include <set>
using namespace std;

const char NL = '\n';
const char SP = ' ';
#define loop(i, a, b) for (int i = a; i < b; i++)

int main () {
  ios_base::sync_with_stdio(false);
  int n, c = 0;
  cin >> n;
  map <int, int> a;
  loop (i, 0, n) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  for (auto i = a.begin(); i != a.end(); i++) {
    int thisi = 0, i1 = i->first;
    for (auto j = i; j != a.end(); j++) {
      int thisj = 0, j1 = j->first;
      for (auto k = j; k != a.end(); k++) {
        int k1 = k->first;
        if (*i != *j && *i != *k && *j != *k && i1 + j1 > k1) {
          thisj += k->second;
        }
      }
      thisi += thisj * (j->second);
    }
    c += thisi * (i->second);
  }
  cout << c << NL;
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char ss[600100];
int len;

int main(){
	scanf("%s",ss); len=strlen(ss);
	for(int i=0;i<len;i+=2)
		printf("%c",ss[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int func(int x){
  if(x%100!=0) return 0;
  return func(x/100)+1;
}

int main(){
  int n;
  cin>>n;
  ll ans=1;
  rep(i,n){
    ans=ans*(i+1)%(INF+7);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pque priority_queue
#define pi acos(-1)
#define int long long
#define N 1000000
typedef pair < int, int > ii;
typedef vector < int > vi;
const int mod = 1000000007;
int f[(1 << 13) + 10][2], test, card[13];
int kt(int mask, int last)
{
	bool check1 = true;
	bool check2 = true;
	for(int i = 0; i < 13; i ++)
		if(card[i] == 1 && (mask & (1 << i)))
			check1 = false;
	for(int i = 0; i < 13; i ++)
		if(card[i] == 2 && (mask & (1 << i)))
			check2 = false;
	if(check1)
		return 1;
	if(check2)
		return 2;
	return 0;
}
string trans(int mask)
{
	string res;
	for(int i = 0; i < 13; i ++)
	{
		if((mask & (1 << i)))
			res.pb('1');
		else
			res.pb('0');
	}
	return res;
}
int dfs(int mask, int last)
{
	//cout << trans(mask) << ' ' << last << ' ' << f[mask][last] << ' ' << test << endl;
	if(f[mask][last] > 0)
	{
		//cout << mask << ' ' << last << endl;
		return f[mask][last];
	}
	int k = kt(mask, last);
	if(k > 0)
	{
		//cout << mask << ' ' << last << endl;
		return f[mask][last] = k;
	}
	bool check1 = false;
	bool check2 = false;
	for(int i = 0; i < 13; i ++)
		if(card[i] == last && (mask & (1 << i)) && ((i > 0 && !(mask & (1 << (i - 1)))) || (i < 12 && !(mask & (1 << (i + 1))))))
		{
			check1 = true;
			if(dfs(mask - (1 << i), 3 - last) == last)
				check2 = true;
		}
	if(check1)
	{
		if(check2)
			return f[mask][last] = last;
		else
			return f[mask][last] = 3 - last;
	}
	else
	{
		return f[mask][last] = dfs(mask, 3 - last);
	}
}
signed main()
{
	//freopen("4.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin >> test;
	while(test --)
	{
		//cout << test << endl;
		for(int i = 0; i < 13; i ++)
			card[i] = 2;
		//cout << test << endl;
		int x;
		for(int i = 0; i < 6; i ++)
			cin >> x, x --, card[x] = 1;
		card[6] = 0;
		//cout << test << endl;
		for(int i = 0; i < (1 << 13); i ++)
			f[i][1] = f[i][2] = 0;
		//cout << test << endl;
		if(dfs((1 << 13) - 1 - (1 << 6), 1) == 1)
			cout << "yes\n";
		else
			cout << "no\n";
		//cout << test << endl;
	}
}




Measured memory_bytes: 3372
arr = 3.times.map{gets.chomp.split(" ").map(&:to_i)}
ans = arr.inject(:+).inject(:+)
all = arr[0][0] + arr[1][1]+ arr[2][2]
bll = arr[0][2] + arr[1][1] + arr[2][0]
if all == (ans / 3) && ans %3 == 0
    puts "Yes"
elsif bll  == (ans / 3) && ans %3 == 0
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 14332
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(len(queue)):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while L < w:
        if cake[h][w-L-1]:
            break
        L += 1
    while R+w < W-1:
        if cake[h][w+R+1]:
            break
        R += 1
    while U < h:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h-U-1][k]:
                flag = True
        if flag:
            break
        U += 1
    while D+h < H-1:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h+D+1][k] != 0:
                flag = True
                break
        if flag:
            break
        D += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    print(*i)

Measured memory_bytes: 62040
import java.util.Scanner

fun main() {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val a = IntArray(n){scn.nextInt()}
	var cnt = 0L
	val s = a.mapIndexed{i,v -> i-v}.sorted()
	val p = a.mapIndexed{i,v -> i+v}.sorted()
	var si = 0
	var pi = 0
	while(si<n && pi<n){
		if (s[si]<p[pi]) si++
		else if (s[si]>p[pi]) pi++
		else {
			var tsi = si
			var tpi = pi
			while(tsi<n && s[tsi]==s[si]) tsi++
			while(tpi<n && p[tpi]==p[pi]) tpi++
			cnt += (tsi-si).toLong()*(tpi-pi)
			si = tsi
			pi = tpi
		}
	}
	println(cnt)
}

Measured memory_bytes: 68376
import math

N,Q = map(int,input().split())

S = list(input())

l = [0 for _ in range(Q)]
r = [0 for _ in range(Q)]
i = 0
while True:
  try:
    lr=list(map(int,input().split()))
    l[i] = lr[0]
    r[i] = lr[1]
    i+=1
  except:
    break

    
#print(S)
def create_list():
  MAXI = N
  
  #ac = [1 for _ in range(MAXI+1)]
  

  sn = [0 for _ in range(MAXI+1)]
  flag = 0
  judge = ['A','C']
  for i in range(1,MAXI+1):
    #print(str(i)+'+1 when '+S[i-1])
    if(S[i-1] == judge[flag]):
        flag+=1
        if(flag == 2):
            sn[i] = sn[i-1] + 1
            flag = 0
        else:
            sn[i] = sn[i-1]
    else:
        flag = 0
        if(S[i-1] == judge[flag]):
          flag += 1
        sn[i] = sn[i-1]
     
  return sn

base = create_list()
#print(base)
for i in range(Q):
  print( base[r[i]] - base[l[i]] )#sum(rnum)-sum(lnum) )

Measured memory_bytes: 58504
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
import bisect
from collections import deque
h=deque()
for i in range(n):
    idx=bisect.bisect_left(h,a[i])
    if idx==0:
        h.appendleft(a[i])
    else:
        h[idx-1]=a[i]

print(len(h))

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

const int INF = 1012345678;

int digit_sum(int x)
{
	int sum = 0;
	while(x > 0)
	{
		sum += x % 10;
		x /= 10;
	}

	return sum;
}

int main()
{
	int n = 0;
	cin >> n;
	int ans = INF;
	for (int a = 1; a < n; a++)
	{
		int b = n - a;
		if ((a + b) == n)
		{
			ans = min(ans, digit_sum(a) + digit_sum(b));
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
ll d[300][300],v, n, c, e, u, k, sum = 0,ans;
int main(void) {
    ll a, b, c, sum = 0;
    cin >> a;
    rep(i, a) {
        cin >> b;
        sum += (b % 2);
    }
    sum %= 2;
    if (sum == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import bisect
n,k=map(int,input().split())
x=list(map(int,input().split()))
x=[-10**10]*k+x+[10**10]*k
s=bisect.bisect_left(x,0)
if x[s]==0:
    m=min(-x[s-(k-1)],x[s+(k-1)])
    for j in range(k):
        m=min(m,2*(x[s+j]-x[s-(k-1)+j])-max(-x[s-(k-1)+j],x[s+j]))
else:
    m = min(-x[s-1 - (k - 1)], x[s + (k - 1)])
    for j in range(k-1):
        m = min(m, 2 * (x[s + j] - x[s - (k - 1) + j]) - max(-x[s - (k - 1) + j], x[s + j]))
print(m)

Measured memory_bytes: 14484
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),* $(,)*) => {
        #[cfg(debug_assertions)]
        eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
    };
}

fn main() {
    input! {
        s: usize,
    }

    let mut dp = vec![0; s + 1];
    for i in 3..=s {
        dp[i] = 1;
    }
    for i in 0..=s {
        for j in 3..i {
            let k = i - j;
            dp[i] = (dp[i] + dp[k]) % M;
        }
    }
    debug!(dp);
    println!("{}", dp[s]);
}


Measured memory_bytes: 2164
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    S = kwargs["S"]
    T = kwargs["T"]
    res = 0

    for s, t in zip(S, T):
        if s != t:
            res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["S"] = cin[0]

    cin = input().split()
    kwargs["T"] = cin[0]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31316
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
const int INF = 0x7f7f7f7f;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int>mii;
typedef map<ll,ll>mll;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);

#define caseNo(x) pf("Case %d: ",++x)
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

#define nl '\n'
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

#define chkC(x,n) (x[n>>6]&(1<<((n>>1)&31)))
#define setC(x,n) (x[n>>6]|=(1<<((n>>1)&31)))

#define MX 10005
//vi prime;
//bool p[MX];
//void sieve(){ll sq=sqrt(MX);for(int i=3;i<=sq;i+=2){if(!p[i]){for(int j=i*i;j<MX;j+=i+i){p[j]=1;}}}}
//ll bigmod(ll n,ll p,ll m){if(p==0)return 1;ll x=bigmod(n,p/2,m);x=((x%m)*(x%m))%m;if(p&1)x=(x*n)%m;return x;}
//ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
//ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
//ll egcd(ll a, ll b, ll *x, ll *y){if(a==0){*x=0,*y=1;return b;}ll x1,y1;ll g=egcd(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return g;}
//ll egcd(ll a, ll b, ll *x, ll *y){if(b==0){*x=1;*y=0;return a;}ll x1,y1;ll temp=egcd(b,a%b,&x1,&y1);*x=y1;*y=x1-y1*(a/b);return temp;}

int main()
{
    int t,cnt=0;
    t=1;
    while(t--){
      int x,y;
      sii(x,y);
      cout << x+(y/2)<<endl;
    }
    return 0;
}










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

int main() {
	int n,u,v;
	scanf("%d",&n);
	if(n==2){printf("0");return 0;}
	scanf("%d%d",&u,&v);
	vector<int> adj[100005];
	int a,b;
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&a,&b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int dist[2][100005]; memset(dist,-1,sizeof(dist));
	queue<int> q;
	q.push(u);dist[0][u]=0;
	while(!q.empty()){
		int cur=q.front();q.pop();
		for(int i=0;i<(int)adj[cur].size();i++){
			if(dist[0][adj[cur][i]]==-1){
				dist[0][adj[cur][i]]=dist[0][cur]+1;
				q.push(adj[cur][i]);
			}
		}
	}
	q.push(v);dist[1][v]=0;
	while(!q.empty()){
		int cur=q.front();q.pop();
		for(int i=0;i<(int)adj[cur].size();i++){
			if(dist[1][adj[cur][i]]==-1){
				dist[1][adj[cur][i]]=dist[1][cur]+1;
				q.push(adj[cur][i]);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		//printf("%d %d\n",dist[0][i],dist[1][i]);
		if(dist[0][i]<dist[1][i]){
			ans=max(ans,dist[1][i]-1);
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 6656
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}




void oneCase () {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(n, vector<int>(n, 1e9));
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    for (int i = 0; i < m; ++i ) {
        int x, y, z;
        cin >> x >> y >> z;
        --x;
        --y;
        d[x][y] = z;
        d[y][x] = z;
        c[i] = z;
        a[i] = x;
        b[i] = y;
        d[x][x] = 0;
        d[y][y] = 0;
    }
    for (int mid = 0; mid < n; ++mid) {
        for (int l = 0; l < n; ++l) {
            for (int r = 0; r < n; ++r) {
                d[l][r] = min(d[l][r], d[l][mid] + d[mid][r]);
            }
        }
    }
    int res = m;
    for (int i = 0; i < m; ++i) {
        bool sh = false;
        for (int mid = 0; mid < n; ++mid) {
            if (c[i] == d[a[i]][mid] - d[mid][b[i]]) {
                sh = true;
                break;
            }
        }
        if (sh) {
            --res;
        }
    }
    cout << res << "\n";
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 384
// Last Change: 04/19/2020 21:10:46.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  ll cost = 0;
  for (ll i = 0; i < M; ++i) {
    ll ipt;
    cin >> ipt;
    cost += ipt;
  }

  cout << max(-1LL, N - cost) << endl;
}


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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)

#define INT(n) int n;scanf("%d",&n)

int main(){
  INT(n); INT(x);
  if (1 < x && x < 2 * n - 1){
    printf("Yes\n");
    REP(i, 2 * n - 1){
      printf("%d\n", (x + n - 1 + i) % (2 * n - 1) + 1);
    }
  }
  else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1536
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  int X;
  cin >> X;
  for(ll i=1;i<=1e3;i++){
    for(ll j=-i;j<=i;j++){
      if(pow(i,5)-pow(j,5)==X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4052
n = int(input())
a=[int(i) for i in input().split()]
sum=0
for i in range(0,n):
    sum += a[i]
x = [a[0]]*n
xy = [None]*(n-1)
for i in range(1,n):
    x[i] = x[i-1]+a[i]
for i in range(0,n-1):
    xy[i] = abs(sum - 2*x[i])
print(min(xy))


Measured memory_bytes: 27864
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,ans;
int main(){
	scanf("%lld",&n);
	printf("%lld",n*n*n);
}

Measured memory_bytes: 128