akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

// for(auto && i : Range(l,r))
// -> i = [l..r)
class Range {
private: struct It{ int x; int operator*(){return x;}
 bool operator!=(It& lhs){ return x<lhs.x;} void operator++(){++x;} }; It l,r;
public: Range(int n):l({0}),r({n}){} Range(int i,int n):l({i}),r({n})
 {}It& begin(){return l;} It& end(){return r;} };

void solve(istream& cin) {
    char t;
    bool a = false;
    cin >> t;
    if(t == '9') a = true;
    cin >> t;
    if(t == '9') a = true;
    cout << (a ? "Yes" : "No") << '\n';

}

int main(int argc, char *argv[]) {
    string FileName("A1"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());
    cerr << sub << endl;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int a[8] = {};
    a[A]++;
    a[B]++;
    a[C]++;

    if(a[5] == 2 && a[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
const int N = 1e6 + 10;
vector<int> cnt(N, 0);

int main() {
    IOS;

    ll n, k;
    cin >> n >> k;
    ll nn = n -  k * ceil( (long double)(n-k)/ (long double) k  );
    ll ans;
    if(nn <= k/2) {
        ans = nn;
    }
    else {
        ans = abs(nn - k);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4224
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()
}

const MOD: i64 = 1000_000_000 + 7;

fn main() {
    let n: usize = read::<usize>();
    let mut a = read_vec::<u64>();

    let mut found_map = std::collections::HashMap::new();
    let mut deprecated_pos = [0usize; 2];
    for (i, &num) in a.iter().enumerate() {
        if found_map.contains_key(&num) {
            deprecated_pos[0] = found_map[&num];
            deprecated_pos[1] = i;
        }
        found_map.insert(num, i);
    }
    let sandwiched = deprecated_pos[1] - deprecated_pos[0] - 1;
    let not_sandwiched = n + 1 - sandwiched - 2;
    let binom = ModBinominal::new(n as i64 + 1, MOD);
    let not_sandwiched_binom = ModBinominal::new(not_sandwiched as i64, MOD);

    println!("{}", n); // k = 1
    for k in 2..n + 2 {
        let ans;
        if k - 1 <= not_sandwiched {
            ans = (MOD + binom.bin[k] - not_sandwiched_binom.bin[k - 1]) % MOD;
        } else {
            ans = binom.bin[k];
        }
        println!("{}", ans);
    }
}

fn extgcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    let mut d = a;
    if b == 0 {
        *x = 1;
        *y = 0;
    } else {
        d = extgcd(b, a % b, y, x);
        *y -= (a / b) * (*x);
    }
    return d;
}

fn mod_inverse(a: i64, m: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    extgcd(a, m, &mut x, &mut y);
    (m + x % m) % m
}

struct ModFactorial {
    fact: Vec<i64>,
}

// returns n! under mod m
impl ModFactorial {
    fn new(n: i64, m: i64) -> ModFactorial {
        let mut fact = vec![1; n as usize + 1];
        for i in 2..fact.len() {
            fact[i] = (i as i64 * fact[i - 1]) % m;
        }
        ModFactorial { fact: fact }
    }
}

// returns bin[i] = nCi under mod m
struct ModBinominal {
    bin: Vec<i64>,
}

impl ModBinominal {
    fn new(n: i64, m: i64) -> ModBinominal {
        let mod_factorial = ModFactorial::new(n, m);
        let mut bin = vec![1; n as usize + 1];
        for i in 1..mod_factorial.fact.len() - 1 {
            let a2 = mod_factorial.fact[i] % m;
            let a3 = mod_factorial.fact[n as usize - i] % m;
            bin[i] = mod_factorial.fact[n as usize] * mod_inverse(a2 * a3 % m, m) % m;
        }
        ModBinominal { bin: bin }
    }
}


Measured memory_bytes: 12540
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
const int N=1e6+5;
typedef long long ll;
int n,m;
bool vis[N];
vector<int>edge[N];
queue<int>q;
map<int,int>f[N];
int dist[N];
int fa[N];
int find_father(int x){
    if(x==fa[x]) return x;
    return fa[x]=find_father(fa[x]);
}
void merge(int x,int y){
    int f1=find_father(x),f2=find_father(y);
    fa[f1]=f2;
}
void bfs(){
    memset(dist,-1,sizeof dist);
    q.push(1);
    vis[1]=1;
    dist[1]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=0,sz=edge[u].size();i<sz;i++){
            int v=edge[u][i];
            v=find_father(v);
            if(!vis[v]){
                dist[v]=dist[u]+1;
                q.push(v);
                vis[v]=1;
            }
        }
    }
}
int main()
{
    int cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        f[i][0]=++cnt;
    }
    for(int i=1;i<N;i++)//!
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        if(f[u][w]==0){
            f[u][w]=++cnt;
            //edge[u].push_back(cnt);
            //edge[cnt].push_back(u);
        }
        u=f[u][w];
        u=find_father(u);
        if(f[v][w]==0){
            f[v][w]=++cnt;
            //edge[v].push_back(cnt);
            //edge[cnt].push_back(v);
        }
        v=f[v][w];
        v=find_father(v);
        merge(u,v);
    }
    for(int i=1;i<=n;i++)
        for(map<int,int>::iterator it=f[i].begin();it!=f[i].end();it++){
            int j=it->second;
            j=find_father(j);
            edge[i].push_back(j);
            edge[j].push_back(i);
        }
    bfs();
    if(dist[n]==-1)
        puts("-1");
    else
        printf("%d\n",dist[n]/2);
}

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

int main()
{
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (((x-r) < 0) || ((x+r) > W) || ((y-r) < 0) || ((y+r) > H))
        cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll x[n][15], y[n][15];
  rep(i, 0, n){
    cin >> a[i];
    rep(j, 0, a[i]){
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  ll ans = 0;
  for(ll bit = 0; bit < (1 << n); bit++){
    ll cnt = 0;
    bool ok = true;
    for(ll i = 0; i < n; i++){
      if(bit & (1 << i)){
        cnt++;
        for(ll j = 0; j < a[i]; j++){
          if(bit & (1 << x[i][j])){
            if(y[i][j] == 0) ok = false;
          }else{
            if(y[i][j] == 1) ok = false;
          }
        }
      }
    }
    if(ok) chmax(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

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

void chmax (int &a, int b) {
	if (a < b) a = b;
}

int main() {
	int n, max_w;
	cin >> n >> max_w;
	vector<int> v(n), w(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	
	vector<int> dp(max_w + 1, 0);
	
	for (int i = 0; i < n; i++) {
		for (int sum_w = max_w; sum_w >= 0; sum_w--) {
			if (sum_w + w[i] <= max_w) {
				chmax(dp[sum_w + w[i]], dp[sum_w] + v[i]);
			}
		}
	}
	
	cout << dp[max_w] << endl;
	
	return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll LINF = ll(1e18);

const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  vector<vector<ll>> dp(n+1, vector<ll>(64, 0LL));
  rep(i, 64)dp[3][i]=1LL;
  dp[3][6]=dp[3][9]=dp[3][18]=0LL;
  repb(i, 3, n){
  	rep(j, 64){
      dp[i][j]%=MOD;
      int c1=j>>2, c2=j%16;
      rep(k, 4){
        if(k==1 && c2==2)continue;
        if(k==2 && (c2==1 || c2==4 || c1==1 || (j%4==1 && j/16==0)))continue;
      	dp[i+1][c2*4+k]+=dp[i][j];
      }
    }
  }
  ll ans=0LL;
  rep(i, 64)ans+=dp[n][i]%MOD;
  cout<<ans%MOD<<endl;
}


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

LL N, M, K, fact[MAXN + 3];

LL fastExponentiation(LL base, LL p) {
    if (p == 0)
        return 1;

    LL half = fastExponentiation(base, p/2);
    LL halfhalf = (half * half)%MOD;

    if (p%2 == 0)
        return halfhalf;
    else
        return (halfhalf * base)%MOD;
}

LL C(LL n, LL k) {
    LL result = fact[n];

    result = (result * fastExponentiation(fact[k], MOD - 2))%MOD;
    result = (result * fastExponentiation(fact[n - k], MOD - 2))%MOD;

    return result;
}

int main() {
    fact[0] = 1;
    for (int i = 1; i <= MAXN; i++)
        fact[i] = (fact[i - 1] * i)%MOD;

    cin >> N >> M >> K;

    LL result = 0;
    for (int x = 0; x <= K; x++) {
        LL temp = C(N - 1, x); //choose x positions where the adjacent color is the same

        temp = (temp * M)%MOD; //there are M ways to paint the first block
        temp = (temp * fastExponentiation(M - 1, N - 1 - x))%MOD; //For every position where the adjacent color is different, there are (M -1) ways to choose the next color.

        result = (result + temp)%MOD;
    }

    cout << result << endl;
}


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

 
int main(){
    long long  x,k,d;
    cin >> x >> k >> d;
    long long y = abs(x);
    if(y/d <= k){
        if((k-y/d)%2 == 0){
            cout << y%d << endl;
        }
        else{
            cout << d-y%d << endl;
        }
    }
    else{
        if(x<0) cout << -x - k*d << endl;
        else cout << x-k*d << endl;
    }
}

Measured memory_bytes: 3596
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
    s = set()
    s.add(A[i])
    s.add(B[i])
    s.add(C[i])
    if len(s)==1:
        pass
    elif len(s)==2:
        ans+=1
    else:
        ans+=2
print(ans)


Measured memory_bytes: 3060
def main():
    import math
    n = int(input())
    n_sq = int(math.sqrt(n)) + 1
    tmp = 10 ** 13
    for i in range(n_sq, 1, -1):
        if n % i == 0:
            j = n // i
            k = (i-1) + (j-1)
            if tmp > k :
                tmp = k
    if tmp != 10 ** 13:
        ans = tmp
    else:
        ans = n-1
    print(ans)


    
if __name__ == "__main__":
    main()


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

#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b; cin >> a >> b;
    int c = min(a, b);
    int d = max(a, b);
    rep(i, d) {
        cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

/*
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
*/

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-9;

void solve() {
    ll x;
    cin >> x;
    ll s = 0, y = x;
    while(y > 0) {
        s += y % 10;
        y /= 10;
    }
    bool ans = x % s == 0;
    cout << (ans ? "Yes" : "No") << endl;
    return;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
    int x, t,n;
  
  scanf("%d %d %d", &n, &x, &t);
  if(n%x==0) printf("%d", (n/x)*t);
  else   printf("%d", ((n/x)+1)*t);

//  printf("%d", ((n/x))*t);
  
  
}

Measured memory_bytes: 1736
S_ = list(input())
T = list(input())

N = len(S_)
for i in range(N):
    if i < len(T) - 1:
        continue

    check = [S_[-i - 1 + k] == T[k] or S_[-i - 1 + k] == "?" for k in range(len(T))]
    # print(i, check)
    if all([S_[-i - 1 + k] == T[k] or S_[-i - 1 + k] == "?" for k in range(len(T))]):
        S = list(S_)
        for j, t in enumerate(T):
            S[N - i - 1 + j] = t
        for j in range(len(S)):
            if S[j] == "?":
                S[j] = "a"
        print("".join(S))
        exit()

print("UNRESTORABLE")


Measured memory_bytes: 3064
#![allow(dead_code)]
use std::io;

fn main() {
    //solve_b();
    solve_d();
}

fn solve_d() {
    let mut x = String::new();

    io::stdin().read_line(&mut x).unwrap();
    let mut x = x.trim().parse::<u64>().unwrap();

    let h = x / (60 * 60);
    x = x % (60 * 60);
    let m = x / 60;
    let s = x % 60;

    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

lint gyaku(lint a, lint mod){
  lint s = 1, tmp = a, t = mod - 2;
  while(t > 0){
    if(t % 2 == 1){
      s *= tmp;
      s %= mod;
    }
    t /= 2;
    tmp *= tmp;
    tmp %= mod;
  }
  return s;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  v1li v(n), b(n+1, 1), c(n+1, 1);
  rep(i, n) scanf("%ld", &v[i]);
  sort(v.begin(), v.end());
  lint a = 0;
  rep(i, n){
    b[i+1] = b[i] * (i+1);
    b[i+1] %= mod1;
    c[i+1] = c[i] * gyaku(i+1, mod1);
    c[i+1] %= mod1;
  }
  if(k > 1){
    rep(i, n){
      if(i > n-k) break;
      lint d = b[n-1-i] * c[n-k-i];
      d %= mod1;
      d *= c[k-1];
      d %= mod1;
      d *= v[i];
      a -= d;
      if(a < 0){
        a *= -1;
        a %= mod1;
        a = mod1 - a;
      }
      else a %= mod1;
    }
    cout << endl;
    reverse(v.begin(), v.end());
    rep(i, n){
      if(i > n-k) break;
      lint d = b[n-1-i] * c[n-k-i];
      d %= mod1;
      d *= c[k-1];
      d %= mod1;
      d *= v[i];
      a += d;
      if(a < 0){
        a *= -1;
        a %= mod1;
        a = mod1 - a;
      }
      else a %= mod1;
    }
  }
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



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

  int ans=0;
  for(int b=1;b<=N;b++){
    int p=N/b,r=N%b;
    ans+=max(0LL,b-K)*p+max(0LL,r-K+1);
    if(K==0)ans-=1;
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int n, d[101];
	cin >> n;
	REP(i, 0, n) cin >> d[i];

	sort(d, d + n);
	int cnt = 1, size = d[0];
	REP(i, 1, n) {
		if (size != d[i]) {
			cnt++;
			size = d[i];
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAXN 100005
int n,l;
int a[MAXN];
int main()
{
	bool f=0;
	int pos;
	scanf("%d %d",&n,&l);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i>1&&a[i]+a[i-1]>=l)
		{
			f=1;
			pos=i-1;
		}
	}
	if(f) 
	{
		printf("Possible\n");
		for(int i=1;i<=pos-1;i++)
			printf("%d\n",i);
		for(int i=n-1;i>=pos;i--)
			printf("%d\n",i);
		/*for(int i=pos+1;i<=n-1;i++)
			printf("%d\n",i);
		printf("%d\n",pos);*/
	}
	else
		printf("Impossible\n");
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

 
int main() {
    int N, M; cin >> N >> M;
    vector<int> X(M), D(M-1);
    for(int i = 0; i < M; i++) cin >> X[i];
    sort(X.begin(), X.end());
    
    for(int i = 0; i < M-1; i++) D[i] = X[i+1] - X[i];
    sort(D.begin(), D.end());
    ll cnt=0;
    for(int i = 0; i < M-N; i++) cnt+=D[i];
    cout << cnt << endl;

}

Measured memory_bytes: 1024
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1); m]
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &es {
        g[a].push(b);
        g[b].push(a);
    }
    println!("{}", dfs(0, &g, 0));
}

fn dfs(r: usize, g: &Vec<Vec<usize>>, s: usize) -> usize {
    let n = g.len();
    let st = s | 1 << r;
    if st == (1 << n) - 1 {
        return 1;
    }
    let mut ret = 0;
    for &v in &g[r] {
        if st & 1 << v == 0 {
            ret += dfs(v, g, st);
        }
    }
    ret
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
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;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    string s;
    cin >> s;
  
    map<string, ll> mp;
    REP(i, 1 << N) {
        string a = "", b = "";
        REP(j, N){
            if(i >> j & 1){
                a += s[j];
            } else {
                b += s[j];
            }
        }
        reverse(all(a));
        mp[a + "." + b]++;
    }

    ll ans = 0;
    REP(i, 1 << N) {
        string a = "", b = "";
        REP(j, N){
            if(i >> j & 1){
                a += s[N + j];
            } else {
                b += s[N + j];
            }
        }
        reverse(all(b));
        ans += mp[a + "." + b];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 67968
#include <iostream>

using namespace std;

int B[25];

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    for (int i=0; i<M; i++) {
        cin >> B[i];
    }
    int res = 0;
    for (int i=0; i<N; i++) {
        int c=C;
        for (int j=0; j<M; j++) {
            int a;
            cin >> a;
            c+= a*B[j];
        }
        if (c>0)
            res ++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans = "No";
  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) ){
    ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
bool nums[110];
int main() {
	int n, x;
	cin >> x >> n;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		nums[a] = 1;
	}
	for (int i = 0; i <= n; i++) {
		if (x-i>=0&&!nums[x - i]) { cout << x - i; return 0; }
		if (!nums[x + i]) { cout << x + i; return 0; }
	}
	return 0;
}

Measured memory_bytes: 3624
n,x,*a=map(int,open(0).read().split())
ans=0
for i in range(n-1):
  sur=max(0,a[i]+a[i+1]-x)
  if sur > a[i+1]:
    a[i]-=sur-a[i+1]
    a[i+1]=0
  else:
    a[i+1]-=sur
  ans+=sur
print(ans)

Measured memory_bytes: 14092
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

long long int n, k;
long long int now = 1;
long long int counter = 0;

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

    vector<long long int> a(n);
    vector<long long int> isVisit(n);

    for(long long int i=0;i<n;i++){
        cin >> a[i];
        isVisit[i] = -1;
    }

    while(k>0){
        isVisit[now-1] = counter;
        now = a[now-1];
        ++counter;
        --k;
        if(isVisit[now-1] > 0){
            counter = counter - isVisit[now-1];
            break;
        }
    }
    
    int p = k % counter;

    for(int i=0;i<p;i++){
        now = a[now-1];
    }
    cout << now;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m, x, y;
  cin >> n >> m >> x >> y;
  vll a(n), b(m);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, m) {
    cin >> b[i];
  }

  ll a_max = *max_element(all(a));
  ll b_min = *min_element(all(b));

  if (a_max < b_min && b_min > x && a_max < y) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

def main():
  for i in reversed(range(n-1)):
    if h[i] - h[i+1] > 1:
      return False
      exit()
    elif h[i] - h[i+1] == 1:
      h[i] -= 1
    else:
      continue
  return True

if main() == True:
  print('Yes')

else:
  print('No')

Measured memory_bytes: 20800
#include<iostream>
using namespace std;
int main(){
long n,a[100],b,s,m,e,i,j;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>a[i];
cin>>b;
s=0;e=n-1;
for(j=1;;j++){
m=(s+e)/2;
if(a[m]==b)break;
else if(a[m]<b)s=m+1;
else e=m-1;
if(e<s)break;
}
cout<<j<<endl;
}
return 0;
}

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

int table[1000][1000];
const int INF =  1 << 29;

int main(void){
  int n, m;
  vector<int> delta;
  vector<int> weather;

  for(int i = 0;i < 1000; i++){
    for(int j = 0;j < 1000; j++){
      table[i][j] == INF;
    }
  }

  cin >> n >> m;
  for(int i = 0;i<n;i++){
    int in_d;
    cin >> in_d;
    delta.push_back(in_d);
  }
  for(int i = 0;i<m;i++){
    int in_w;
    cin >> in_w;
    weather.push_back(in_w);
  }

  for(int i = 0;i < n;i++){
    for(int j = i;j < (m - (n - i - 1));j++){
      int buf;
      if (i == 0 && j == i){
        buf = delta.at(i) * weather.at(j);
      }else if (i == 0){
        buf = min(table[i][j - 1], delta.at(i) * weather.at(j));
      }else if (j == i){
        buf = table[i - 1][j - 1] + delta.at(i) * weather.at(j);
      }else{
        buf = min(table[i][j-1], min(table[i - 1][j - 2], table[i - 1][j - 1]) + delta.at(i) * weather.at(j));
      }
      table[i][j] = buf;
      // cout << "---" << table[i][j] << endl;
    }
  }
  // for(int i = 0;i < n;i++){
  //   for(int j = 0; j < m; j++){
  //     cout << table[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  cout << table[n-1][m-1] << endl;
  return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define debug(x) cout << "debug: " << x << endl
#define MOD 1e9 + 7
#define INF 1e9

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

int main(){
    int n, w; cin >> n >> w;
    vector<vector<int>> v(n, vector<int>(2));
    rep(i, n) rep(j, 2) cin >> v[i][j];
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, -INF));
    rep(i, w + 1) dp[0][i] = 0;
    rep(i, n){
        rep(j, w + 1){
            if (j - v[i][0] >= 0)
                chmax(dp[i + 1][j], dp[i][j - v[i][0]] + v[i][1]);
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[n][w] << endl;
}

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

int main() {
    ll A; cin >> A;
    long double B; cin >> B;
    int C = (B+0.000001) * 100;
    ll D = A*C;
    string E = to_string(D);
    if (E.size() <= 2 || A*B < 1) {
        ll F = A*B;
        cout << F << endl;
        return 0;
    }

    for (int i = 0; i < E.size() - 2; i++) {
        cout << E[i];
    }
    cout << endl;
}

Measured memory_bytes: 3744
#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>;

const int MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll res = 0;
  ll two_factor = 1;
  for (int d = 0; d < 60; ++d) {
    ll even = 0, odd = 0;
    rep(i, n) {
      if (a[i] & (1LL << d))
        ++odd;
      else
        ++even;
    }
    ll add = (odd * even) % MOD * two_factor % MOD;
    res = (res + add) % MOD;
    two_factor = (two_factor * 2) % MOD;
  }
  cout << res << endl;
}

Measured memory_bytes: 5556
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

template<class T>bool ch1000000(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; }


const int MAX = 42;




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

  vector<double> A(N+1);

  rep(i, 1, N+1){
    cin >> A[i];
  }

  for(int i = K+1; i <= N; i++){
    if(A[i] / A[i-K] > 1){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }


  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 4844
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long i64;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

namespace task {
const int MOD = 998244353;
const int N = 200001;
int n, x, d;
pair<int, int> a[N];
int t[2 * N];
int b[N];
int dp[N];

void set(int p, int v) {
  for (t[p += n] = v; p > 1; p >>= 1) {
    t[p >> 1] = max(t[p], t[p ^ 1]);
  }
}

int get(int l, int r) {
  int v = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) v = max(v, t[l++]);
    if (r & 1) v = max(v, t[--r]);
  }
  return v;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> d;
    a[i] = {x, d};
  }
  sort(a, a + n);
  for (int i = n - 1; i >= 0; --i) {
    tie(x, d) = a[i];
    int p = lower_bound(a, a + n, pair<int, int>(x + d, 0)) - &a[0];
    b[i] = max(i, get(i + 1, p));
    set(i, b[i]);
  }
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    dp[b[i] + 1] = (dp[b[i] + 1] + dp[i]) % MOD;
  }
  cout << dp[n] << '\n';
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}


Measured memory_bytes: 5120
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int n = sc.nextInt();
        int[] X = new int[n];
        Arrays.setAll(X, i -> Integer.parseInt(sc.next()));
        int[] XS = Arrays.copyOf(X, X.length);
        Arrays.sort(XS);
        int m1 = XS[(n-1) / 2];
        int m2 = XS[(n-1) / 2 + 1];
        for(int i = 0; i < n; i++) {
            if(X[i] <= m1) sb.append(m2 + "\n");
            else if(X[i] >= m2) sb.append(m1 + "\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 64716
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
X = inpl()
Y = sorted(X[:])
median_l = Y[N // 2 - 1]
median_r = Y[N // 2]

for x in X:
    if x <= median_l:
        print(median_r)
    else:
        print(median_l)


Measured memory_bytes: 25620
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), m = fs.nextInt();
		int x[] = fs.nextIntArray(n);
		int y[] = fs.nextIntArray(m);
		long resX = 0;
		for(int i=1;i<n;i++) {
			long s = mul(i, sub(n,i)); //x方向の長方形の含み方		
			long len = x[i]-x[i-1];
			resX = plus(resX,mul(s,len));
		}
		long resY = 0;
		for(int j=1;j<m;j++) {
			long t = mul(j, sub(m,j));
			long len = y[j]-y[j-1];
			resY = plus(resY,mul(t,len));
		}
		long ans = mul(resX,resY);
		System.out.println(ans);
	}
	//MOD culculations
	static long plus(long x, long y) {
		x %= mod;
		y %= mod;
		long res = (x + y) % mod;
		return res;
	}

	static long sub(long x, long y) {
		x %= mod;
		y %= mod;
		long res = (x - y + mod) % mod;
		return res;
	}

	static long mul(long x, long y) {
		x %= mod;
		y %= mod;
		long res = x * y % mod;
		return res;
	}

	static long div(long x, long y) {
		x %= mod;
		y %= mod;
		long res = x * modpow(y, mod - 2) % mod;
		return res;
	}

	//modの元での高速pow()
	static long modpow(long a, long p) {
		if (p == 0)
			return 1;
		if (p % 2 == 0) {
			long halfP = p / 2;
			long root = modpow(a, halfP);
			return root * root % mod;
		} else
			return a * modpow(a, p - 1) % mod;
	}

	
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 44908
#include<bits/stdc++.h>
using namespace std;
int n,a[200010][2],p1=1,p2=1,p3=1,p4=1,ans=0;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
    for (int i=2;i<=n;i++)
    {
        if (a[i][0]+a[i][1]>a[p1][0]+a[p1][1]) p1=i;
        if (a[i][0]-a[i][1]>a[p2][0]-a[p2][1]) p2=i;
        if (a[i][1]-a[i][0]>a[p3][1]-a[p3][0]) p3=i;
        if (a[i][0]+a[i][1]<a[p4][0]+a[p4][1]) p4=i;
    }
     for (int i=1;i<=n;i++)
     {
        ans=max(ans,abs(a[i][0]-a[p1][0])+abs(a[i][1]-a[p1][1]));
        ans=max(ans,abs(a[i][0]-a[p2][0])+abs(a[i][1]-a[p2][1]));
        ans=max(ans,abs(a[i][0]-a[p2][0])+abs(a[i][1]-a[p2][1]));
        ans=max(ans,abs(a[i][0]-a[p2][0])+abs(a[i][1]-a[p2][1]));
     }
     cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5308
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		
		char[] charArray = str.toCharArray();
		ArrayList<Character> array = new ArrayList<Character>();
		for(int i=0; i< charArray.length; i++){
			array.add(charArray[i]);
		}

		//List<char[]> array = Arrays.asList(charArray);
		int len = array.size();
		while(len > 0){
			array.remove(len-1);
			array.remove(len-2);
			len -= 2;
			if(IsEvenString(array)){
				System.out.println(len);
				break;
			}
			
		}
		
	}

	public static boolean IsEvenString(ArrayList<Character> x){
		for(int i =0; i < x.size() / 2; i++){
			if (x.get(i) !=x.get(i + x.size() / 2)){
				return false;
			}
		}
		return true;
		
	}
}

Measured memory_bytes: 21972
stack=[]
i=0
x=int(input())
stack.append(x)
while 1:
    try:
        x=int(input())
        if (x==0):
            print(stack[i])
            stack.pop()
            i-=1
        else:
            stack.append(x)
            i+=1
    except EOFError:
        break

Measured memory_bytes: 7556
N,T=map(int,input().split())
x=[(0,0)] # x[0]
for i in range(1,N+1): # x[i]のiに対応させる
    x.append(tuple(map(int,input().split()))) # x[1]~x[N]

x.sort()
# print(x) #DB★

dp1=[[0 for j in range(T)] for i in range(N+2)] # 0~N+1 dp1[i]はx[1]からx[i]まで使用（dp1[0]は使用するx[i]なしの初期値，dp1[N+1]は余り→0で初期化していることが後で役に立つ）
for i in range(1,N+1): # dp1[0]は初期値なのでいじらない。dp1[N+1]は余りなので計算しない。dp1[N]まで計算するので，iはNまで
    for j in range(T): # 0分後からT-1分後まで計算する
        if x[i][0]>j:
            dp1[i][j]=dp1[i-1][j]
        else:
            dp1[i][j]=max(dp1[i-1][j],dp1[i-1][j-x[i][0]]+x[i][1])

cans=[dp1[i-1][T-1]+x[i][1] for i in range(1,N+1)]

# print(cans) #DB★ 

ans=max(cans)

print(ans)

Measured memory_bytes: 123864
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

ans = 0
pre = nil
for i in 0...n
    ans += b[a[i]-1] 
    ans += c[a[i-1]-1] if i > 0 && (a[i] - a[i-1] == 1)
end

puts ans

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

typedef long long ll;

int main(){
    int n, a[3];
    cin >> n;
    for(int i = 0; i < 3; i++)  cin >> a[i];
    vector<string> vs(n);
    for(int i = 0; i < n; i++)  cin >> vs[i];
    string t = "";
    for(int i = 0; i < n; i++){
        int aind = vs[i][0]-'A', bind = vs[i][1]-'A';
        if(a[aind]==0 && a[bind]==0){
            cout << "No" << endl;
            return 0;
        }
        if(a[aind] == 0){
            t += vs[i][0];
            a[aind]++, a[bind]--;
        }else if(a[bind] == 0){
            t += vs[i][1];
            a[aind]--, a[bind]++;
        }else{
            if(i == n-1){
                t += vs[i][0];
            }else{
                int naind = vs[i+1][0]-'A', nbind = vs[i+1][1]-'A';
                if(aind == naind || aind == nbind){
                    t += vs[i][0];
                    a[aind]++, a[bind]--;
                }else{
                    t += vs[i][1];
                    a[aind]--, a[bind]++;
                }
            }
        }
    }
    cout << "Yes" << endl;
    for(char c : t) cout << c << endl;
    return 0;
}

Measured memory_bytes: 6656
from functools import reduce


def primes_list(N):
    l = [v for v in range(2, N+1)]
    ret = []
    while l:
        cur = l.pop(0)
        l = list(filter(lambda x: x % cur != 0, l))
        ret.append(cur)
    return ret


mod = 10**9+7
N = int(input())

l = [0]*(N+1)
primes = primes_list(N)

for i in range(2, N+1):
    for p in primes:
        if p > i:
            break
        tmp = 0
        while i % p == 0:
            i //= p
            tmp += 1
        l[p] += tmp

ans = 1
for i in l:
    if i == 0:
        continue
    else:
        ans = ans*(i+1) % mod
print(ans)


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

int main() {
	char chr, chr0;
	int ans = 0, count_s = 0;
	while (cin >> chr) {
		switch(chr) {
			case 'S':
				ans++;
				count_s++;
				break;
			case 'T':
				ans++;
				if (count_s > 0) {
					ans -= 2;
					count_s--;
				}
				break;
			default:
				break;
		}
		chr0 = chr;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n+1];
for(int i=1;i<n+1;i++) {
	a[i]=sc.nextInt();

}
int count=0;
for(int i=1;i<n+1;i++) {
if((i&1)!=0) {
	if((a[i]&1)!=0) {
		count++;
	}
}
}
System.out.println(count);
	}

}


Measured memory_bytes: 36136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	for(ll i=1;i<=9;i++){
		for(ll j=1;j<=9;j++){
			if(i*j==n){
				cout <<"Yes";
				return 0;
			}
		}
	}
	cout <<"No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI (3.141592653589793)
int main()
{
	double ang_to_rad = PI / 180;
	double now_angle = 90;
	double x = 0, y = 0;
	double distance = 0, angle = 0;
	int final_x, final_y;
	
	while (1){
		scanf("%lf,%lf", &distance, &angle);
		if (distance == 0 && angle == 0)
			break;
		if (distance < 0 || distance > 100 || angle < -180 || angle > 180)
			continue;
		x += distance * cos(now_angle * ang_to_rad);
		y += distance * sin(now_angle * ang_to_rad);
		now_angle -= angle;
	}
	final_x = x;
	final_y = y;
	printf("%d\n%d\n", final_x, final_y);
	
	return 0;
} 

Measured memory_bytes: 632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

const ll MOD = 1e9 + 7;



int main() {


	int r, d, a;
	cin >> r >> d >> a;

	for (int i = 0; i < 10; i++)
	{
		a = a * r - d;
		cout << a << endl;

	}




	return 0;
}


Measured memory_bytes: 256