akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.read();
    let s: String = sc.read();
    let s: Vec<char> = s.chars().collect();
    let mut dp: Vec<Vec<i64>> = vec![vec![0; n + 2]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..i+1 {
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * 2) % MODLL;
            if j != 0 {
                dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MODLL;
            } else {
                dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % MODLL;
            }
        }
    }
    let mut ans = dp[n][s.len()];
    for _i in 0..s.len() {
        ans = ans * ((MODLL + 1) / 2) % MODLL;
    }
    println!("{}", ans);
}

Measured memory_bytes: 231676
import java.util.Scanner;

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

		if (abc.equals("abc") || abc.equals("acb") || abc.equals("bac") || abc.equals("bca") || abc.equals("cab") || abc.equals("cba")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

S = input()
if S[2]==S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void YAY(bool b = true) {cout << (b ? "Yay!" : ":(") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
V<> VEC(ll n) {V<> v(n); REP(i, n) cin >> v[i]; return v;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1;} return ret;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    auto a = VEC(n);
    ll mon = 1000, have = 0;
    REP(i, n-1){
        if(a[i] >= a[i+1])continue;
        mon += (mon / a[i]) * (a[i+1] - a[i]);
    }
    cout << mon << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;
 
lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a);
        b >>= 1;
        if (!b)
            break;
        a = (a*a);
    }
    return result;
}
int main()
{
	IOS;
	lli k;
	cin>>k;
	if(k<=10)
	{
		cout<<k<<endl;
		return 0;
	}
	queue<string> q;
	for(lli i = 1; i<10; i++)
	{
		string temp;
		temp += (char)(i+'0');
		q.push(temp);
	}
	lli s = 9;
	string ans;
	while(1)
	{
		string temp = q.front();
		q.pop();
		if(temp.back() == '9')
		{
			temp += '8';
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}

			temp[temp.size()-1] = '9';
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}
		} else if(temp.back() == '0')
		{
			temp += '0';
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}

			temp[temp.size()-1] = '1';
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}
		} else
		{
			temp += (char)(temp.back()-1);
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}

			temp[temp.size()-1]++;
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}
			temp[temp.size()-1]+=1;
			q.push(temp);
			s++;
			if(s == k)
			{
				ans = temp;
				break;
			}
		}
	}
	cout<<ans<<endl;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


const ll MAX_D=365;
const ll NUM=26;

ll d;
vll c(NUM);
vvll s(MAX_D,vll(NUM));
vll ans(MAX_D);


struct Solve{
  random_device seed_gen;
  default_random_engine engine;
  uniform_int_distribution<ll> day;
  uniform_int_distribution<ll> val;

  ll best_score=0;
  ll pre_score=0;

  Solve():day(0,MAX_D-1),val(0,NUM-1){
//    REP(i,d)ans[i]=i%NUM;
    for(ll i=0; i<d; i++){
      ll m=0;
      ll mi=0;
      REP(j,NUM){
        if(m<s[i][j]){
          m=s[i][j];
          mi=j;
        }
      }
      ans[i]=mi;
    }

    engine=default_random_engine(seed_gen());
  }


  void init(){
    best_score=calcScore();
    pre_score=best_score;
  }


  void modify(ll index, ll value){
    //swap(state[l],state[r]);
    ans[index]=value;
  }


  ll calcScore(){
    vll last(NUM,-1);
    ll score=0;
    REP(i,d){
      ll now=ans[i];
      last[now]=i;

      ll cost=0;
      REP(j,NUM)cost+=c[j]*(i-last[j]);

      score+=s[i][now]-cost;
    }

    //score=max(ll(score+1e6),0LL);
    return score;
  }


  void climbMountain(){
    ll value=val(engine);
    ll index=day(engine);

    ll prevalue=ans[index];
    modify(index,value);
    ld now_score=calcScore();

    if(best_score<now_score)
      best_score=now_score;
    else
      modify(index,prevalue);
  }


};


ll calc(ll x){
  return max(ll(x+1e6),0LL);
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  const ll TIME_LIMIT=1900; //ms
  chrono::system_clock::time_point begin_time,now_time;
  begin_time=chrono::system_clock::now();

  cin>>d;
  REP(i,NUM)cin>>c[i];
  REP(i,d)REP(j,NUM)cin>>s[i][j];


  Solve sl=Solve();
  sl.init();

  ll cnt=0;
  ll kosin=0;
  while(true){
    if(kosin<cnt/10000){
      kosin=cnt/10000;

      now_time=chrono::system_clock::now();
      ld diff_time=chrono::duration_cast<chrono::milliseconds>(now_time-begin_time).count();
      if (diff_time > TIME_LIMIT) break;
    }

    sl.climbMountain();
    cnt++;
  }

//  cout<<calc(sl.best_score)<<endl;
//  cout<<cnt<<endl;

  REP(i,d)cout<<ans[i]+1<<endl;
}



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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N 1000001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountl(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

main()
{
  ios
int n,m,i;
int j;
int u,v,q;
int test=1;
//si(test);

while(test--)
{
    cin>>n;
    int h[n];
    for(i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    for(i=0;i<n;i++)
        dp[i]=0;
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }

    cout<<dp[n-1];
}

}


Measured memory_bytes: 5156
lines = readlines.map(&:strip)

n, m = lines.shift.split.map(&:to_i)
p = lines.pop.split.map(&:to_i)
k = lines.map{|line| line.split.map(&:to_i)}

#puts [n, m].inspect
result=0
(2**n).times do |number|
  current_switches = ("%0#{n}b" % number).split('').map(&:to_i)

#  puts '='
#  puts current_switches.inspect
#  puts '-'

  all_on=true
  m.times do |index|
    k_condition_switches = k[index][1..-1]

#  puts k_condition_switches.inspect
#  puts k_condition_switches.map{|k_switch|current_switches[k_switch-1]}.inspect
#  puts '---'

    on_count = k_condition_switches.map{|k_switch|current_switches[k_switch-1]}.inject(:+)
    unless p[index] == on_count % 2
      all_on=false
      break
    end
  end
  result += 1 if all_on
end

puts result

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

int main(){
	int n, k = 0;
	int a[5000];
	long long int b[1000] = {0}, c[1000] = {0};
	while(cin >> n){
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
			b[k] = b[k]+a[i];
			if(b[k] < 0){
				b[k] = 0;
			}
			if(b[k] > c[k]){
				c[k] = b[k];
			}
		}
		if(c[k] == 0){
			sort(a,a+n);
			c[k] = a[n-1];
		}
		k++;
	}
	for(int i = 0; i < k; i++){
		cout << c[i] << endl;
	}
}

Measured memory_bytes: 1200
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int a, b, i, j, k,  n, m;
int main() {
	scanf("%d%d", &a, &b);
	if (b == 1) {
		printf("0");
		return 0;
	}
	i = a; j = 1;
	while (i < b) {
		i += (a - 1);
		j++;
	}
	printf("%d\n", j);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
typedef long long ll;

int main(void) {
  ll i, j, k, n;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  std::sort(a, a + n);
  for(i = 1; i < n; ++i) if(a[i] == a[i - 1]) {
    printf("NO");
    return 0;
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int n;
    is >> n;
    i64 t_res = 1, a_res = 1;
    while (n--) {
        i64 t, a;
        is >> t >> a;
        i64 mul = max((t_res + t - 1) / t, (a_res + a - 1) / a);
        t_res = t * mul;
        a_res = a * mul;
    }
    os << t_res + a_res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a,b,c,d[ohara],cmp,cmpp,m,h,w,x,y,sum=0,pos,ca=0;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
     cin >> n;
     rep(i,n){
       cin >> d[i];
       d[i] /= 10;
     }
     ca = d[0];
     rrep(i,1,n){
       if(ca < i){
         Cout("no");
         return 0;
       }
       ca = max(ca,i + d[i]);
       if(ca == n - 1)break;
     }
     reverse(d,d + n);
     ca = d[0];
     rrep(i,1,n){
       if(ca < i){
         Cout("no");
         return 0;
       }
       ca = max(ca,i + d[i]);
       if(ca == n - 1)break;
     }
     Cout("yes");


       
return 0;
}



Measured memory_bytes: 5588
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    n,m = map(int,input().split())    
    if abs(n-m)>1:
        print(0)
    else:
        a=max(n,m)
        b=min(n,m)
        if a>b:
            print((factorial(a)*factorial(b))%mod)
        else:
            ans=(factorial(a)**2)%mod
            print((2*ans)%mod)
main()

Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
int main(){
  int p,q,r;
  std::cin >> p>>q>>r;
  std::cout << min(p+q,min(q+r,r+p)) << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
const int INF = (1<<30) - 1;
const int MOD = 1000000007;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, D;

void solve(){
    vector<vector<int>> countries(N);
    vector<int> cursors(N);
    
    for(int i=0; i<N; i++){
        int m; cin >> m;
        cursors[i] = m;
        
        vector<int> v(m+1);
        for(int j=0; j<m; j++){
            int c; cin >> c;
            v[j+1] = v[j] + c;
        }
        countries[i] = v;
    }

    bool updated = true;
    while(updated){
        updated = false;
        for(int i=0; i<N; i++) if(cursors[i]>0){
            int _max = 0;
            int _min = INF;
            for(int j=0; j<N; j++){
                int cur = cursors[j];
                if(i == j)
                    cur--;
                _max = max(_max, countries[j][cur]);
                _min = min(_min, countries[j][cur]);
            }
            if(_max - _min <= D){
                cursors[i]--;
                updated = true;
            }
        }
    }
    
    for(int i=0; i<N; i++){
        if(cursors[i] != 0){
            cout << "No" << endl;
            return;
        }
    }
    
    cout << "Yes" << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin>>N>>D, N|D){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 1260
#include <stdio.h>

int main(){
    int x,y,num,flag=0;
    scanf("%d%d",&x,&y);

    for (int i=0;i<=x;i++){
        num=4*i+2*(x-i);
        if(num==y)
            flag=1;
    }
    if(flag==1)
        printf("Yes\n");
    else
    {
        printf("No\n");
    }
    
}


Measured memory_bytes: 1664
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<ll> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    int p = 0;
    while (p < N && x[p] < 0) ++p;
    ll res = 1ll << 60;
    for (int i = 0; i < N; i++) {
      if (i < p) {
        ll cost = -x[i];
        int rem = K - (p - i);
        if (rem <= 0) {
          res = min(res, cost);
        } else if (p + rem - 1 < N) {
          cost += x[p + rem - 1] - x[i];
          res = min(res, cost);
        }
      } else {
        ll cost = x[i];
        int rem = K - (i - p + 1);
        if (rem <= 0) {
          res = min(res, cost);
        } else if (p - rem >= 0) {
          cost += x[i] - x[p - rem];
          res = min(res, cost);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

const int mod=1000000007;
int N,W;
int w[201];
ll dp[2][10001][202];

int main(){

	cin>>N>>W;
	for(int i=0;i<N;i++)cin>>w[i];
	for(int j=0;j<10001;j++){
		for(int k=0;k<=N;k++){
			if(j<=W&&(k==N||w[k]+j>W))dp[N%2][j][k]=1;
			else dp[N%2][j][k]=0;
		}
	}

	for(int i=N-1;i>=0;i--){
		int cur=(i+1)%2;
		int nxt=(i)%2;
		for(int j=0;j<10001;j++){
			for(int k=0;k<=N;k++){
				dp[nxt][j][k]=0;
				int nmwidx=k;
				if(k==N||w[k]>w[i])nmwidx=i;
				dp[nxt][j][k]+=dp[cur][j][nmwidx];
				if(j+w[i]<=W)dp[nxt][j][k]+=dp[cur][j+w[i]][k];
				dp[nxt][j][k]%=mod;
			}
		}
	}
	cout<<dp[0][0][N]<<endl;

	return 0;
}

Measured memory_bytes: 0
N = int(input())
s = list(input())

for i in range(len(s)):
    if ord(s[i])+N-ord('A') < 26:
        s[i] = chr(ord(s[i])+N)
    else:
        s[i] = chr(ord(s[i])+N-26)
print(''.join(s))

Measured memory_bytes: 9240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a < b){
            System.out.println("a < b");
        }
        if(a > b){
            System.out.println("a > b");
        }
        if(a == b){
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26360
import sys
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())

LR = [tuple(map(int, input().split())) for _ in range(M)]

mae = 0
usiro = 10**6

for i in range(M):
    if LR[i][0] > mae:
        mae = LR[i][0]
    if LR[i][1] < usiro:
        usiro = LR[i][1]

if usiro - mae < 0:
    print(0)
else:
    print(usiro - mae + 1)

Measured memory_bytes: 16632
N, M = map(int,input().split())
H = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(M)]
highest_tenbo = [0 for i in range(N)]

for a, b in arr:
    highest_tenbo[a-1] = max(highest_tenbo[a-1], H[b-1])
    highest_tenbo[b-1] = max(highest_tenbo[b-1], H[a-1])

ans = 0
for i, t in enumerate(highest_tenbo):
  if t < H[i]:
    ans+=1
print(ans)

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

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int b;//tou
	int f;//kai
	int r;//heyabangou
	int v;//ninzu
	int a[5][4][11];
	int n;//kensu
	int i,j,k;

	for(i=1;i<=4;i++)
	{
		for(j=1;j<=3;j++)
		{
			for(k=1;k<=10;k++) a[i][j][k]=0;
		}
	}

	scanf("%d\n",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d\n",&b,&f,&r,&v);
		a[b][f][r]+=v;
	}
	
	for(i=1;i<=4;i++)
	{
		for(j=1;j<=3;j++)
		{
			for(k=1;k<=10;k++) printf(" %d",a[i][j][k]);
			printf("\n");
		}
		if(i<4) printf("####################\n");
	}
	return 0;
}



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

const int INF = 1 << 30;
const int MAX_N = 2 * 1e5 + 2;

int sum_w[MAX_N], sum_b[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    for (int i = 1; i <= N; i++) {
        if (S[i - 1] == '#') sum_b[i]++;
        sum_b[i] += sum_b[i - 1];
    }
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == '.') sum_w[i + 1]++;
        sum_w[i + 1] += sum_w[i + 2];
    }
    int ans = INF;
    for (int i = 1; i <= N + 1; i++) {
        // black pos
        ans = min(ans, sum_b[i - 1] + sum_w[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define par pair<pair<int,int>, int>
#define f first
#define s second

int l,r;


int main() {
    scanf("%d%d",&l,&r);
    int m1 = l%2019;
    int m2 = r%2019;
    int ans=oo;
    if(m1 >= m2 || !m1 || !m2 || r-l >= 2019) ans = 0;
    else 
    {
        for(int i=l; i<r; i++)
        {
            for(int j=i+1; j<=r; j++)
            {
                ans = min(ans , ((i%2019)*(j%2019))%2019);
            }
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var n = Read<int>();
        var s = Read<string>();

        var count = 0;

        var l = 0;
        var r = s.Length - 1;

        while (l < r)
        {
            while (l < r && s[l] == 'R') l++;
            while (r > l && s[r] == 'W') r--;
            if (s[l] == 'W' && s[r] == 'R')
            {
                count++; l++; r--;
            }
        }
        Console.WriteLine(count);
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0, i = k;

    if (a <= i) {
        sum += a;
        i -= a;
    }
    else {
        sum += i;
        i -= i;
    }
    
    if (b <= i) {
        i -= b;
    }
    else {
        i -= i;
    }

    if (c <= i) {
        sum -= c;
        i -= c;
    }
    else {
        sum -= i;
        i -= i;
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 3552
// Created by arjun_singh12 (Arjun Singh) on [12-05-2020 03:39:27]
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
#define INF LLONG_MAX
#define vll vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>>
#define pb push_back
#define pll pair<ll,ll>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define repr(i,n,a) for(ll i=n;i>=a;i--)
#define endl "\n"
#define db(x); cout<<"Debug: "<<#x<<" = "<<x<<endl;
#define dbv(v); cout<<"Debug: Vector "<<#v<<" = "; for(ll i=0;i<sz(v);i++) cout<<v[i]<<" "; cout<<endl;
using namespace std;
ll dp[105][1000005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll test=1;
	// cin>>test;
	while(test--)
	{
	    ll n,W; cin>>n>>W;
	    vll wt(n),v(n);
	    rep(i,0,n)
	    {
	    	cin>>wt[i]>>v[i];
	    }
	    memset(dp,-1,sizeof(dp));
	    rep(i,0,n+1)
	    {
	    	rep(j,0,W+1)
	    	{
	    		if(i==0 || j==0)
	    			dp[i][j]=0;
	    	}
	    }
	    rep(i,1,n+1)
	    {
	    	rep(j,1,W+1)
	    	{
	    		if(wt[i-1]<=j)
	    		{
	    			dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
	    		}
	    		else
	    		{
	    			dp[i][j]=dp[i-1][j];
	    		}
	    	}
	    }
	    cout<<dp[n][W];
	}
}


Measured memory_bytes: 820608
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator 
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
    char c=gc; x=0; int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
    while(isdigit(c)) x=x*10+c-'0',c=gc;
    x*=f;
}
template<class o> void qw(o x) {
    if(x/10) qw(x/10);
    putchar(x%10+'0');
}
template<class o> void pr1(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar('\n');
}

int x[N],y[N],n,sta[N],top,fa[N],sz[N],f[N];
int get(int x) {return fa[x] == x?x:fa[x]=get(fa[x]);}

int main() {
    qr(n);
    for(int i=1;i<=n;i++) qr(x[i]),qr(y[x[i]]);
    for(int i=1;i<=n;i++) {
        fa[i]=i; sz[i]=1; f[i]=y[i];
        while(top&&f[sta[top]]<y[i]) {
            int t=get(sta[top--]);
            if(t^i) fa[t]=i,sz[i] += sz[t],f[i]=min(f[i],f[t]);
        }
        sta[++top]=i;
    }
    for(int i=1;i<=n;i++) pr2(sz[get(x[i])]);
    return 0;
}

Measured memory_bytes: 12152
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
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();
}

int main(void){

    char c[10];
    FOR(i,0,10)cin >> c[i];

    int year = 1000*int(c[0]-'0')+100*int(c[1]-'0')+10*int(c[2]-'0')+int(c[3]-'0');

    int month = 10*int(c[5]-'0')+int(c[6]-'0');

    if(year<2019)cout << "TBD" << endl;
    else if(year==2019){
        if(month>4)cout << "TBD" << endl;
        else cout << "Heisei" << endl;
    }else cout << "Heisei" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;



void solve()
{
    int a, b;
    cin >> a >> b;

    cout <<min(1, a%b);
}


 int main(){
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define NIL -1
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  int N,Q;
  cin >> N >> Q;
  vector<vector<int>> G(N);
  for(int i=0; i<N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> count(N,0);
  for(int i=0; i<Q; i++){
    int p,x;
    cin >> p >> x;
    p--;
    count[p] += x;
  }
  vector<int> dist(N,-1);
  queue<int> que;
  dist[0] = 0;
  que.push(0);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int nv: G[v]){
      if(dist[nv] != -1){
       continue;
      }
      dist[nv] = 0;
      count[nv] += count[v];
      que.push(nv);
    }
  }
  for(int i=0; i<N; i++){
    cout << count[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 16372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi arr(n);
  rep(i,n) cin >> arr[i];

  ll sum;
  ll plus_start = 0;

  if (arr[0] <= 0) plus_start += 1 - arr[0];
  sum = max(arr[0], 1);
  for (int i=1; i<n; ++i) {
    sum += arr[i];
    if (i%2 == 0 && sum <= 0) {
      plus_start += 1 - sum;
      sum = 1;
    }
    if (i%2 == 1 && sum >= 0) {
      plus_start += 1 + sum;
      sum = -1;
    }
  }

  ll minus_start = 0;

  if (arr[0] >= 0) minus_start += 1 + arr[0];
  sum = min(arr[0], -1);
  for (int i=1; i<n; ++i) {
    sum += arr[i];
    if (i%2 == 1 && sum <= 0) {
      minus_start += 1 - sum;
      sum = 1;
    }
    if (i%2 == 0 && sum >= 0) {
      minus_start += 1 + sum;
      sum = -1;
    }
  }

  cout << min(plus_start, minus_start) << endl;
  return 0;
}


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

int n;
const int mod = 1e9 + 7;
const int maxn = 1005;
bool prime[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    int res = 1;
    for(int i = 2;i <= n;i++){
        if(!prime[i]){
            int ans = 0;
            for(int j = i;j <= n;j *= i){
                ans += n / j;
            }
            for(int j = i * 2;j <= n;j += i){
                prime[j] = true;
            }
            res = 1LL * (ans + 1) * res % mod;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace codefestival_2016_qualC_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();bool flag = false;
            for(int i = 0; i < a.Length; i++) { if (a[i] == 'C') { flag = true; }if (flag && a[i] == 'F') { Console.WriteLine("Yes");break; }
                if (i == a.Length - 1) { Console.WriteLine("No"); }
            }
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
 
int main(void) {
    char day[5];
    scanf("%s",day);
    if(strcmp(day,"SUN")==0){
   		 printf("7\n");
  	}
    else if(strcmp(day,"MON")==0){
   		 printf("6\n");
  	}
    else if(strcmp(day,"TUE")==0){
   		 printf("5\n");
  	}
   else if(strcmp(day,"WED")==0){
   		 printf("4\n");
  	}
   else if(strcmp(day,"THU")==0){
   		 printf("3\n");
  	}
    else if(strcmp(day,"FRI")==0){
   		 printf("2\n");
  	}
   else
     printf("1\n");
  
  
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    vector<string> A(N), B(M);
    bool match = false;
    rep(i, N){
        cin >> A[i];
    }
    rep(i,M){
        cin >> B[i];
    }
    rep(i, N){
        rep(j, N){
            if(i+M-1 >= N || j+M-1 >= N) continue;
            bool exit = true;
            rep(k, M){
                rep(l, M){
                    if(A[i+k][j+l] != B[k][l])  exit = false;
                }
            }
            if(exit) match = true;
        }
    }
    if(match) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
X,Y=list(map(int,input().split()))

import sys
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
  print(0)
  sys.exit()
if (2*Y-X)<0 or (2*X-Y)<0:
  print(0)
  sys.exit()
x=(2*Y-X)//3
y=(2*X-Y)//3
#(x+y)Cxを求める
fac=[0 for i in range(x+y+1)]
inv=[0 for i in range(x+y+1)]
finv=[0 for i in range(x+y+1)]
#初期条件
p=1000000007
fac[0]=fac[1]=1
inv[1]=1
finv[0]=finv[1]=1
#テーブルの作成
for i in range(2,x+y+1):
  fac[i]=fac[i-1]*i%p
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  inv[i]=(-(p//i)*inv[p%i])%p
  finv[i]=finv[i-1]*inv[i]%p
#求める

print((fac[x+y]*finv[x]%p)*finv[y]%p)




Measured memory_bytes: 88080
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "Yes\n"
#define no cout << "No\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

void solve() {
    string s, t;
    cin >> s >> t;
    int cost = 1e8;
    for(int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
        int tcost = 0;
        //if(s[i] == t[0]) {
            int p1 = i, p2 = 0;
            while(p2 < (int)t.size()) {
                if(s[p1] != t[p2]) tcost++;
                p2++;
                p1++;
            }
            cost = min(cost, tcost);
        //}
    }
    cout << cost << '\n';
}

int main() {
    /*int tc;
    cin >> tc;
    while(tc-- > 0)*/
    solve();
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>

using namespace std;
int main(){
	int N;
	int K;
	int x[N];
	cin>>N;
	cin>>K;
	for(int i=0;i<N;i++){
		cin>>x[i];
	}
	int sum=0;
	for(int i=0;i<N;i++){
		if(x[i]<K/2.0){
			sum+=2*x[i];
		}
		else
			sum+=2*(K-x[i]);
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n,l,r;cin>>l>>r>>n;
        ll num;
        num=r/n;
        num-=(l/n);
        if(l%n==0)num++;cout<<num;


}


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

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

int main(){
    int N,H;  
    cin >> N >> H;
    vector<int> A(N),B(N);
    int a=0,b=0,index=0;
    rep(i,N){
        cin >> A[i] >> B[i];
        if(A[i] > a){
            a = A[i];
            b = B[i];
            index = i;
        }
    }
    B.erase(B.begin() + index);
    sort(B.begin(),B.end(),greater<int>());
    int res = 0;
    for(auto r : B){
        if(r<a)break;
        H -= r;
        res++;
        if(H-b<=0)break;
    }
    if(H<=0){
        cout << res << endl;
    }else{
        while(true){
            if(H<=b){
                break;
            }else{
                int r = ceil((H-b) / (double)a);
                res += r;
                H -= r * a;
            }
        }
        cout << res+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	static class Tree {
		public class Edge {
			int to, rev;

			public Edge(int to, int rev) {
				this.to = to;
				this.rev = rev;
			}
		}
		
		int V;
		ArrayList<ArrayList<Edge>> G;
		int root;
		int[] p;
		
		public Tree(int[] a, int[] b) {
			this.V = a.length+1;
			p = new int[V];
			
			G = new ArrayList<ArrayList<Edge>>();
			for(int i=0; i<V; i++) {
				G.add(new ArrayList<Edge>());
			}
			
			for(int i=0; i<V-1; i++) {
				G.get(a[i]).add(new Edge(b[i], G.get(b[i]).size()));
				G.get(b[i]).add(new Edge(a[i], G.get(a[i]).size()-1));
			}
			setRoot(0);
		}
		
		public void setRoot(int root) {
			this.root = root;
			setRoot(root, -1);
		}
		public void setRoot(int cur, int parent) {
			p[cur] = parent;
			for(int i=0; i<G.get(cur).size(); i++) {
				int next = G.get(cur).get(i).to;
				if(next!=parent) {
					setRoot(next, cur);
				}
			}
		}
		
		public boolean firstWin() {
			int len = 0;
			for(int i=0; i<G.get(root).size(); i++) {
				int next = G.get(root).get(i).to;
				if(next!=p[root]) {
					int cb = branchLength(next);
					if(cb<0)
						return true;
					else
						len += cb;
				}
			}
			return len!=1;
		}
		
		int branchLength(int cur) {
			int len = 0;
			for(int i=0; i<G.get(cur).size(); i++) {
				int next = G.get(cur).get(i).to;
				if(next!=p[cur]) {
					int cb = branchLength(next);
					if(cb<0)
						return cb;
					else
						len += cb;
				}
			}
			if(len>=2)
				return -1;
			else if(len==1)
				return 0;
			else
				return 1;
		}
	}
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N-1];
		int[] b = new int[N-1];
		for(int i=0; i<N-1; i++) {
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
		}
		
		Tree tree = new Tree(a,b);
		
		System.out.println(tree.firstWin() ? "First" : "Second");
		
		sc.close();
	}
}


Measured memory_bytes: 91668
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
int main()
{
	int n,k,item,ans=0,a[100005];
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)item=i+1;
	}
	int l=item-1,r=n-item;
	if(l%(k-1)==0)
	{
		ans+=(l/(k-1));
		if(r%(k-1)==0)ans+=(r/(k-1));
		else ans+=(r/(k-1)+1);
	}
	else
	{
		ans+=(l/(k-1));
		r=n-item+(l%(k-1));
		if(r%(k-1)==0)ans+=(r/(k-1));
		else ans+=(r/(k-1)+1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    int ans = 0;
    int active = 0;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++) {
        
        if (active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 1000000007;

int arr[202020];
int val[202020];
int32_t main()
{
    usecppio
    int n; cin >> n;
    for (int i = 1; i<=n; i++)
        cin >> arr[i];
    if (n % 2 == 0)
    {
        int xorval = 0;
        for (int i = 1; i<=n; i+=2)
        {
            int tmp = arr[i]^arr[i+1];
            xorval^=tmp;
        }
        for (int i = 1; i<=n; i++)
        {
            cout << (xorval^arr[i]) << ' ';
        }
        cout << '\n';
    }
    else
    {
        cout << 0 << ' ';
        for (int i = 2; i<=n; i++)
            cout << (arr[i]) << ' ';
        cout << '\n';
    }
}   

Measured memory_bytes: 5216
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)
 
const int MAXN = 4e5+5;
const int MOD = 998244353; //1e9+7;
const int INF = 1e9+1;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    char S[104];
    cin >> S;
    int l = 0, r = strlen(S)-1;
    int ans = 0;
    while(l < r) {
        ans += S[l] != S[r];
        l++; r--;
    }

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


Measured memory_bytes: 256
#include<stdio.h>
int m[12][12];
void f(int c,int r)
{
	int x[4]={-1,0,1,0},y[4]={0,1,0,-1},i,C,R;
	if(m[r][c]==1)
	{
		m[r][c]=0;
		for(i=0;i<4;i++)
		{
			C=c+x[i];
			R=r+y[i];
			if(C>=0&&C<12&&R>=0&&R<12)
				f(C,R);
		}
	}
	return;
}

int main()
{
	int i,j,c;
	while(1)
	{
		c=0;
		for(i=0;i<12;i++)
			for(j=0;j<12;j++)
				if(scanf("%1d",&m[i][j])==EOF)
					return 0;
		for(i=0;i<12;i++)
			for(j=0;j<12;j++)
				if(m[i][j]==1)
				{
					c++;
					f(j,i);
				}
		printf("%d\n",c);
	}
}

Measured memory_bytes: 604