akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull n, k, q;
  cin >> n >> k >> q;

  vector<ull> a;
  each(i, q) {
    ull tmp;
    cin >> tmp;
    a.push(tmp);
  }

  unordered_map<ull, ull> points = {};
  each(i, q) {
    ull number = a[i];

    if (points.count(number) == 0) {
      points[number] = 1;
    } else {
      const auto v = points[number];
      points[number] = v + 1;
    }
  }

  each(i, n) {
    long long point = k;
    if (points.count(i+1) == 0) {
      point = (long long)k - (long long)q;
    } else {
      point = (long long)k - (long long)q + points[i+1];
    }

    if (point > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4852
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	long a = sc.nextLong();
    int b = (int)(sc.nextDouble() * 100.00); 
  	long c = a * b / 100L;
    System.out.println(c);
  }
}

Measured memory_bytes: 36644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    rep1(i, n) cin >> s[i];
    sort(s.begin(),s.end());
    ll ans = 1;
    rep2(i,1,n){
        if (s[i-1]!=s[i]) ans++;
    }
    cout << ans << endl;
}

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


int main(){

long n,W;
cin>>n>>W;

long wt[n+1];
long v[n+1];

for(int i=0;i<n;i++)
cin>>wt[i]>>v[i];

long dp[n+1][W+1];//the cells consider the subproblem where we have the first i elements with maximum capacity of j,for example dp[1,10] 
//considers the subproblem with first element available and 10 capacity 

memset(dp,0,sizeof(dp));

for(int i=0; i <=n; i++){
            for(long j=0; j <= W; j++){
                if(i == 0 || j == 0){
                    dp[i][j] = 0;
                    continue;
                }
                if(j - wt[i-1] >= 0){ // if at the current capacity j we can put at least element i-1 
                    dp[i][j] = max(dp[i-1][j], dp[i-1][j-wt[i-1]] + v[i-1]);     //the solution for the subproblem is the maximum between
                    // the value dp[i-1][j] which is the solution with the items up to i-1 available,and the result when we try to add 
                    //the previous element with some element with weight [j-wt[i-1]] IF EXISTANT in the dp cell of a precomputed subproblem 
                }else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
/*
for(int i=0;i<=n;i++){
    for(long j=0;j<=W;j++){
        cout<<dp[i][j]<<" ";
    }
    cout<<endl;
}
*/

cout<<dp[n][W];


}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int ii=1,f=0;
	long long temp1=1;
	long long a,temp2;
	cin>>n;
	for(ii=1;ii<=n;ii++)
	{
		cin>>a;
		if(f==0)
		{
			temp2=temp1*a;

			if(temp2<temp1 && a!=0)
			{	
				temp1=-1;
				f=1;
			}
			else
				temp1=temp2;			
		}
		else
		{
			if(a==0)
				temp1=0;
			else
				temp1=temp1;
		}	
	}
	
	if(temp1>1000000000000000000)
		cout<<-1;
	else
		cout<<temp1;			
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
ll gcd(ll a,ll b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n],i,j,ans=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		ll ctr1=0,ctr=0;
		for(j=0;j<n;j++)
		{
			if(a[i]>a[j])
			{
				if(i<j)
				{
					ctr1++;
				}
				ctr++;
			}
		}
		ll ans1=((ctr1*k)%mod+((ctr)*((k*(k-1)/2)%mod))%mod)%mod;
		ans+=ans1;
		ans=ans%mod;
	}
	cout<<ans;
	return 0;
}

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

constexpr int INF = 1e9;
constexpr int MAX_SCORE = 1010101;
int score_cnt[MAX_SCORE];

int main() {
    int d, g;
    cin >> d >> g;
    g /= 100;
    
    for (int i = 0; i < MAX_SCORE; i++) {
        score_cnt[i] = INF;
    }
    
    score_cnt[0] = 0;
    
    for (int i = 1; i <= d; i++) {
        int p, c;
        cin >> p >> c;
        c /= 100;
        // すでに解かれてる問題＋その問題
        for (int j = MAX_SCORE - 1; j >= 0; j--) {
            if (score_cnt[j] != INF) {
                for (int k = 1; k <= p; k++) {
                    if (j + i * k < MAX_SCORE) {
                        score_cnt[j + i * k] = min(score_cnt[j + i * k], score_cnt[j] + k);
                    }
                }
                if (j + i * p < MAX_SCORE) {
                    score_cnt[j + i * p + c] = min(score_cnt[j + i * p + c], score_cnt[j] + p);
                }
            }
        }
        
        // その問題だけ
        for (int j = 1; j <= p; j++) {
            score_cnt[i * j] = min(score_cnt[i * j], j);
        }
        // 全完した場合
        score_cnt[i * p + c] = min(score_cnt[i * p + c], p);
    }
    
    int ans = 1e9;
    for (int i = g; i < MAX_SCORE; i++) {
        ans = min(ans, score_cnt[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4224
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << B * (T / A) << endl;
    return 0;
}

Measured memory_bytes: 764
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::{max, min};

#[fastout]
fn main() {
    input! {
    n: usize,
    a: [usize; n],
    q: usize,
    bc: [(i64, i64); q]
    }
    let mut l = [0; 100005];
    let mut ans = a.iter().sum::<usize>() as i64;
    for &i in &a {
        l[i] += 1;
    }
    for (b, c) in bc {
        let k = l[b as usize];
        ans += (c - b) * k;
        l[b as usize] = 0;
        l[c as usize] += k;
        println!("{}", ans);
    }
}


Measured memory_bytes: 6784
list_length = int(input())
word_list = list()
for i in range(list_length):
  w = input()
  try:
    if w[0] != word_list[-1][-1]:
      break                
  except IndexError:
  	pass
  word_list.append(w)

if len(set(word_list)) == list_length:
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

#define INF 0x3f3f3f3f


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int i,j,k,n,sum=0;
    cin>>n;
    for(i=1 ; i<=n ; i++)
    {
        for(j=1 ; j<=n ; j++)
        {
            for(k=1 ; k<=n ; k++)
            {
                sum += __gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll X;
  cin >> X;

  if(X <= 3){
    cout << 1 << endl;
    return 0;
  }

  ll sqX = (ll)sqrt(X) + 1;
  ll ans = -1;

  rep2(b, 2, sqX){
    ll num = b;
    while(num < X) num *= b;
    if(num > X) num /= b;
    ans = max(ans, num);
  }

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


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: u64,
    }
    let ans = (1 + n - 1) * (n - 1) / 2;

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main (){
    double a, b, x ;
    cin >> a >> b >> x ;
    if(a*a*b/2 <= x){
        double ans = atan(2*(a*a*b - x)/(a*a*a)) ;
        ans = ans * 180 / PI ;
        cout << fixed << setprecision(10) ;
        cout << ans << endl ;
    }
    else {
        double ans = atan(a*b*b/(2*x)) ;
        ans = ans * 180 / PI ;
        cout << fixed << setprecision(10) ;
        cout << ans << endl ;
    }
}

Measured memory_bytes: 4084
///in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(k--)
    {
        if(b<=a)
            b=2*b;
        else
            c=2*c;
    }
    if(b>a && c>b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}



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

typedef complex<double> P;

typedef vector<P> poly;

typedef pair<P, P> L;

const double EPS = 1e-9;

double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }

int ccw(P a, P b, P c) {
	double d = cross(b -= a, c -= a);
	return d > EPS ? 1 : d<-EPS ? -1 : dot(b, c) < -EPS ? 2 : norm(b) + EPS < norm(c) ? -2 : 0;
}

#define DI(l) ((l).second - (l).first)
#define CCW(l, a) ccw((l).first, (l).second, (a))

bool intersectSS(const L &s, const L &t) { return CCW(s, t.first)*CCW(s, t.second)<=0 && CCW(t, s.first)*CCW(t, s.second) <= 0; }
P crosspoint(const L &l, const L &m) {
	P a = DI(l), b = DI(m);
	double A  = cross(a, b), B = cross(a, l.second - m.first);
	return m.first + B / A * b;
}

double signed_area(const poly &v) {
	double res = 0;
	rep(i, sz(v)) res += cross(v[i], v[(i+1)%sz(v)]);
	return res * 0.5;
}



vector<P> v;
double calc(double x) {
	L a(P(x, -1e3), P(x, 1e3)), b(P(x+0.5, -1e3), P(x+0.5, 1e3));

	vector<double> ap, bp;
	rep(i, sz(v)) {
		L l = L(v[i], v[(i+1)%sz(v)]);
		if (!(intersectSS(l, a) && intersectSS(l, b))) continue;
		ap.push_back(imag(crosspoint(l, a)));
		bp.push_back(imag(crosspoint(l, b)));
	}
	sort(ap.begin(), ap.end());
	sort(bp.begin(), bp.end());
	assert(sz(ap) % 2 == 0);
	double S = 0;
	rep(i, sz(ap)/2) {
		S +=  (ap[i*2 + 1] - ap[i*2] + bp[i*2 + 1] - bp[i*2]) * 0.5 * 0.5;
	}
	return S;
}
int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	rep(i, N) {
		double x, y;
		cin >> x >> y;
		v.push_back(P(x, y));
	}

	double s0 = 0, s1 = 0;
	for(double x = -1e3; x <= 1e3; x += 1) {
		s0 += calc(x);
	}
	for(double x = -1e3 - 0.5; x <= 1e3; x += 1) {
		s1 += calc(x);
	}

	printf("%.20f\n", max(s0, s1));
}

Measured memory_bytes: 1284
h,w = map(int,input().split())
ss = []
for i in range(h):
    ss.append(list(input()))

def search(i,j):
    c = 0

    if i != 0:
        if ss[i-1][j] == "#":
            c += 1
    if i != h-1:
        if ss[i+1][j] == "#":
            c += 1
    if j != 0:
        if ss[i][j-1] == "#":
            c += 1
    if j != w-1:
        if ss[i][j+1] == "#":
            c += 1

    if c > 0:
        return False
    else:
        return True

ans = "Yes" 
for i in range(h):
    for j in range(w):
        if ss[i][j] == "#":
            if search(i,j):
                ans = "No"
                break

print(ans)

Measured memory_bytes: 3064
function main(input) {
    var line = input.split(/\r?\n/g);
    var arr = line[0].split(" ");
    const H = arr[0], N = arr[1];
    var A = line[1].split(" ").map(Number);
    A = A.reduce((A, x) => A + x)
    console.log(1 < Math.ceil(H / A) ? "No" : "Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 16716
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,k;cin>>n>>k;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  sort(h.begin(),h.end());
  lint res=inf;
  rep(i,n){
      if(i+k-1==n)break;
      res=min(res,h[i+k-1]-h[i]);
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int K;cin >> K;
    int s[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << s[K-1] << endl;
}


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

int main()
{
	int N;
	int i, j;
	int Ali = 0;
	int Bob = 0;
	int b = 0;
	scanf("%d", &N);

	int a[N + 10];
	for (i = 0; i < N; i++)
		scanf("%d", &a[i]);


	for (i = 0; i < N - 1; i++) {
		for (j = N - 1; j > i; j--) {
			if (a[j - 1] > a[j]) {
				b = a[j - 1];
				a[j - 1] = a[j];
				a[j] = b;
			}
		}
	}

	for (i = N - 1; i >= 0; i -= 2) Ali += a[i];
	for (i = N - 2; i >= 0; i -= 2) Bob += a[i];

	printf("%d", Ali - Bob);
	return 0;
}

Measured memory_bytes: 128
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var H = one[0];
  var N = one[1];
  var maxIndex = 11007;
  var max = 1000000000;
  var dp = new Array(maxIndex);
  dp[0] = 0;
  for(var i = 0; i < N; i++){
    var tmp = nextIntArray();
    var Ai = tmp[0];
    var Bi = tmp[1];
    for(var j = 0; j < maxIndex; j++){
      if(dp[j] != null){
        if(dp[j + Ai] == null){
          dp[j + Ai] = dp[j] + Bi;
        }else{
          dp[j + Ai] = Math.min(dp[j + Ai], dp[j] + Bi);
        }
      }
    }
  }
  dp[maxIndex - 1] = max;
  for(var i = maxIndex - 2; i >= 0; i--){
    if(dp[i] == null){
      dp[i] = dp[i + 1];
    }else{
      dp[i] = Math.min(dp[i + 1], dp[i]);
    }

  }
  myout(dp[H]);
}


Measured memory_bytes: 34476
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
const int maxM=5010;
const int maxn=1010;
const int INF=0x3f3f3f3f;
int f[maxn],g[2][maxM],n;
int head[maxn],tot,v[maxn];
struct edge {
    int v,next;
} e[maxn];
void addEdge(int u,int v) {
    e[++tot].v=v;
    e[tot].next=head[u];
    head[u]=tot;
}
void cl(int t) {
    memset(g[t],0x3f,sizeof(g[t]));
}
void dfs(int x) {
    for(int i=head[x]; i; i=e[i].next)
        dfs(e[i].v);
    cl(0);
    int X=0;
    g[X][0]=0;
    for(int i=head[x]; i; i=e[i].next) {
        int y=e[i].v;
        X=1-X;
        cl(X);
        for(int j=0; j<=v[x]; j++) {
            if(j-f[y]>=0)
                g[X][j]=min(g[X][j],g[1-X][j-f[y]]+v[y]);
            if(j-v[y]>=0)
                g[X][j]=min(g[X][j],g[1-X][j-v[y]]+f[y]);
        }
    }
    for(int i=0; i<=v[x]; i++)
        f[x]=min(f[x],g[X][i]);
}
void init() {
    scanf("%d",&n);
    for(int i=2; i<=n; i++) {
        int p;
        scanf("%d",&p);
        addEdge(p,i);
    }
    for(int i=1; i<=n; i++)
        scanf("%d",&v[i]);
    memset(f,0x3f,sizeof(f));

}
void solve() {
    dfs(1);
}
void pri() {
    if(f[1]>=INF)
        printf("IMPOSSIBLE\n");
    else
        printf("POSSIBLE\n");
}
int main() {
    init();
    solve();
    pri();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<cstdio>

using namespace std;

typedef pair<int,int> P;

struct State{
  int x,y,t;
  bool isR;
  State(){}
  State(int a, int b, int c, bool d):
    x(a),y(b),t(c),isR(d){}
  bool operator < (const State& s) const {return t > s.t;}
};

const int MW = 31;
const int MH = 61;
const int INF = (1<<25);

int M[MH][MW],T[MH][MW][2],w,h;
vector<P> S;
vector<P> G;

void print(){
  for(int i = 0; i < h; i++){
    for(int x = 0; x < 2; x++){
      for(int j = 0; j < w; j++) 
	if(T[i][j][x] == INF) cout << "  X";
	else printf("%3d",T[i][j][x]);
      cout << "                 ";
    } 
    cout << endl;
  }
  cout << endl << endl;
}

bool isInside(int x, int y) {return 0<=x&&x<w&&0<=y&&y<h;}

void init(){
  for(int i = 0; i < MH; i++)
    for(int j = 0; j < MW; j++) T[i][j][0] = T[i][j][1] = INF;
}

void input(){
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++){
      char c;
      cin >> c;
      if(c == 'X') M[i][j] = INF;
      else if(c == 'T'){
	M[i][j] = 0;
	G.push_back(P(j,i));
      }else if(c == 'S'){
	M[i][j] = 0;
	S.push_back(P(j,i));
      }else M[i][j] = c-'0';
    }
}

int solve(bool R){
  
  init();

  priority_queue<State> Q;

  for(int i = 0; i < S.size(); i++){
    int sx = S[i].first;
    int sy = S[i].second;
    Q.push(State(sx,sy,0,R));
    T[sy][sx][R] = 0;
  }

  while(!Q.empty()){
    State now = Q.top();
    Q.pop();
    if(T[now.y][now.x][now.isR] < now.t) continue;
    
    for(int i = 1; i <= 3; i++)
      for(int j = -2; j <= 2; j++){
	int mx = i,my = j;
	if(now.isR) mx *= -1;
	int nx = now.x+mx;
	int ny = now.y+my;
	
	//	if(abs(mx) + abs(my) <= 3) cout << now.isR << " " <<  mx << " " << my << " " << endl;
	if(isInside(nx,ny) && abs(mx)+abs(my) <= 3 && T[ny][nx][!now.isR] > now.t+M[ny][nx]){
	  T[ny][nx][!now.isR] = now.t+M[ny][nx];
	  Q.push(State(nx,ny,now.t+M[ny][nx],!now.isR));
	}
      }
  }

  //print();
  int ans = INF;

  for(int i = 0; i < G.size(); i++) ans = min(ans,min(T[G[i].second][G[i].first][0],T[G[i].second][G[i].first][1]));

  return ans;
}

int main(){

  while(cin >> w >> h && w+h){
    S.clear();
    G.clear();
    input();
    int ans = min(solve(true),solve(false));
    if(ans == INF) cout << "-1" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;

#define error(x) cout << #x << " = " << x << endl;
 
const int N = 1e5 + 5, mod = 1e9 + 7;
const ll inf = 1e15;
 
inline int sum(int a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	if(a < 0)
		a += mod;
	return a;
}
 
inline int mult(int a, int b) {
	return (1LL * a * b) % mod;
}
 
int n, m, dp[N][2], S, T;
ll dist[N][2];
vector <pii> adj[N];
vector <pair <pii, int> > edge;
 
inline void dijkstra(int src, int id) {
	for (int i = 0; i < n; i++)
		dist[i][id] = inf;
	dp[src][id] = 1;
	dist[src][id] = 0;
	set <pair <ll, int>> s;
	s.insert({0, src});
	while(!s.empty()) {
		pair <ll, int> p = (*s.begin());
		s.erase(p);
		int v = p.second;
		for (auto e : adj[v]) {
			int u = e.first, w = e.second;
			if(dist[u][id] > dist[v][id] + w) {
				s.erase({dist[u][id], u});
				dist[u][id] = dist[v][id] + w;
				s.insert({dist[u][id], u});
				dp[u][id] = dp[v][id];
			}
			else if(dist[u][id] == dist[v][id] + w)
				dp[u][id] = sum(dp[u][id], dp[v][id]);
		}
	}
}
 
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> n >> m >> S >> T;
	S--, T--;
	for (int i = 0; i < m; i++) {
		int v, u, w;
		cin >> v >> u >> w;
		v--, u--;
		adj[v].push_back({u, w});
		adj[u].push_back({v, w});
		edge.push_back({{u, v}, w});
	}
	dijkstra(S, 0);
	dijkstra(T, 1);
	int ans = mult(dp[S][1], dp[T][0]);
	for (int i = 0; i < n; i++) {
		if(dist[i][0] == dist[i][1]) {
			ans = sum(ans, - mult(mult(dp[i][0], dp[i][0]), mult(dp[i][1], dp[i][1])));
		}
	}
//*
	for (auto e : edge) {
		int vv = e.first.first, uu = e.first.second, w = e.second;
		for (auto x : {make_pair(vv, uu), make_pair(uu, vv)}) {
			int v = x.first, u = x.second;
			if(dist[v][0] < (dist[S][1] / 2) && dist[u][1] < (dist[S][1] / 2) && dist[v][0] + dist[u][1] + w == dist[S][1]) {
				ans = sum(ans, -mult(mult(dp[v][0], dp[u][1]), mult(dp[v][0], dp[u][1])));
			}
		}
	}
//*/
	cout << ans << "\n";
 
}


Measured memory_bytes: 22320
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	string s;
	cin >> s;

	int n = s.size(), cnt = 0, ans = 0;

	rep(i, 0, n) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			cnt = 0;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def Li():
    return list(map(int, input().split()))


n, a, b = Li()
mod = pow(10, 9)+7
bunshi = 1
bunbo = 1
ans = pow(2, n, mod)-1
for i in range(a):
    bunshi = (bunshi*(n-i)) % mod
    bunbo = (bunbo*(i+1)) % mod
ans = (ans-bunshi*pow(bunbo, -1, mod)) % mod
for i in range(a, b):
    bunshi = (bunshi*(n-i)) % mod
    bunbo = (bunbo*(i+1)) % mod
ans = (ans-bunshi*pow(bunbo, -1, mod)) % mod
print(ans)


Measured memory_bytes: 9152
import itertools
import numpy as np
N = input()
digit = len(N)
ans = 0
if int(N) < 357:
    print(ans)
else:
    for i in range(3, len(N)):
        ans += 3**i - 3 * 2**i + 3
    for v in itertools.product('753', repeat=digit):
        if (len(set(list(v)))==3) & (int(''.join(list(v))) <= int(N)):
            ans +=1
    print(ans)


Measured memory_bytes: 12420
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35972
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define X first
#define Y second
#define mp make_pair
#define eb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
    char c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}

const int MAX_N = 1e5 +5;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int h, w, k;
LL dp[105][10];

int main() {
#ifdef ANONYM
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    Read(h), Read(w), Read(k);
    dp[0][0] = 1;
    /*
    for (int i=1; i<=h; i++) {
        for (int p=0; p<w; p++) {
            for (int j=0; j<(1<<(w-1)); j++) {
                bool f = false;
                int q = p;
                for (int l=0; l<w-1; l++) {
                    if (((j>>l)&1) && ((j>>(l+1))&1)) f = true;
                }
                if (f) continue;

                if ((j>>p) & 1) {
                    q = p + 1;
                } else if (p>0 && ((j>>(p-1))&1)) {
                    q = p - 1;
                }

                dp[i][q] = (dp[i][q] + dp[i][p]) % MOD;
            }
        }
    }
    */
    for(int i=0;i<h;i++){
      for(int p=0;p<w;p++){
        for(int j=0;j<(1<<(w-1));j++){
          bool f = false;
          int q = p;
          for(int l=0;l<w-1;l++){
            if(((j>>l)&1) && ((j>>(l+1))&1)){
              f = true;
            }
          }
          if(f) continue;

          if((j>>p)&1){
            q = p+1;
          }else if(p>0 &&((j>>(p-1))&1)){
            q = p-1;
          }

          dp[i+1][q] = (dp[i+1][q] + dp[i][p])%MOD;
        }
      }
    }

    printf("%lld\n", dp[h][k-1]);
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc128/abc128_d
import itertools as it

N, K = map(int, input().split())
vs = [int(s) for s in input().split()]

acc = [0] + list(it.accumulate(vs))
res = 1000000000
for left in range(min(N, K) + 1):
    for right in range(min(N, K) + 1 - left):
        tmp = acc[N - right] - acc[left]
        rem = K - left - right
        rest = sorted(vs[:left] + vs[N - right :])[:rem]

        for x in rest:
            if x < 0:
                tmp += x
        if tmp < res:
            res = tmp

print(acc[-1] - res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,cont=0; cin>>n;
  vector<int> lista;
  for(int i=0; i<n;i++){
    int aux; cin>>aux;
    lista.push_back(aux);
  }
  for(int i=0; i<n;i++){
    if(i+1!=lista[i]){cont++;}}
  (cont==0||cont==2)?cout<<"YES":cout<<"NO";
}


Measured memory_bytes: 256
#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()

int main(){
    int n;
    cin >> n;
    int i;
    string ans = "No";
    if(n/100 == 7) ans = "Yes";
    else{
        n = n%100;
        if(n/10 == 7) ans = "Yes";
        else{
            n = n%10;
            if(n == 7) ans = "Yes";
        }
    }

    cout << ans << endl; 
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=200010;

signed main(){
    ll n;cin>>n;
    vector<ll>a(n);
    vector<ll>b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    bool f=0;
    REP(i,1,n-1){
        if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i+1]==b[i+1])f=1;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;

ll dub[62][200001];

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

	for (int i = 0; i < n; i++){
		dub[0][i] = a[i];
	}
	
	for (int i = 1; i <= 60; i++){
		for (int j = 0; j < n; j++){
			dub[i][j] = dub[i-1][dub[i-1][j]];
		}
	}

	ll ans = 0;
	for (int i = 0; i <= 60; i++){
		if (k & (1LL<<i)){
			ans = dub[i][ans];
		}
	}
	cout << ans+1 << endl;
	return 0;
}


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

int solve(int, int);

int main() {
    int n, x;
    
    while(1) {
        cin >> n >> x;
        
        if (n == 0 && x == 0) {
            break;
        } else {
            cout << solve(n, x) << endl;
        }
        
    }
}

int solve(int n, int x) {
    int cnt = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if ((i + 1) + (j + 1) + (k + 1) == x) {
                    cnt++;
                } else if (i + j + k >= x) {
                    break;
                }
            }
        }
    }
    
    return cnt;
}


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

const int inf = 1000000037;
const int maxn = 10004;
const int maxm = 10;

int n, m;
int a[maxm], dp[maxn], p[maxn];
int req[maxm] = {inf, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int rec (int x) {
	if (x < 0) 
		return -inf;
	else if (dp[x] != -1)
		return dp[x];
	else {
		vector < pair < int, int > > to;
		for (int i = 0; i < m; ++i) 
			to.push_back(make_pair(rec(x - req[a[i]]), a[i]));
		sort(to.begin(), to.end());
		if (to.back().first < 0)
			return dp[x] = -inf;
		else {
			p[x] = to.back().second;
			return dp[x] = to.back().first + 1;
		}
	}
}

signed main () {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i)
		scanf("%d", &a[i]);
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	rec(n);
	while (n > 0) {
		printf("%d", p[n]);
		n -= req[p[n]];
	}
	printf("\n");
}


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

int main(){
    long long n, m, x;
    cin >> n >> m >> x;
    vector<long long> c(n);
    vector<vector<long long> > a(n, vector<long long>(m));

    for(long long i = 0; i < n; i++){
        cin >> c[i];
        for(long long j = 0; j < m; j++) cin >> a[i][j];
    }

    long long minv = 1e9;
    vector<bool> buy(n); 
    for(long long bit = 0; bit < (1 << n); bit++){
        for(long long mask = 0; mask < n; mask++){
            if(bit & (1 << mask)) buy[mask] = true;
            else buy[mask] = false;
        }
        long long cost = 0;
        vector<long long> algo(m, 0);
        for(long long i = 0; i < n; i++){
            if(buy[i] == false) continue;
            cost += c[i];
            for(long long j = 0; j < m; j++) algo[j] += a[i][j];
        }

        bool flag = true;
        for(long long i = 0; i < m; i++){
            if(algo[i] < x){
                flag = false;
                break;
            }
        }
        if(flag == true) minv = min(minv, cost);
    }

    if(minv == 1e9) printf("-1\n");
    else printf("%lld\n", minv);

    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int n, cnt = 0;
void dfs(long long num, bool have3, bool have5, bool have7)
{
    if(num <= n)
    {
        if(have3 && have5 && have7)
            cnt++;
        dfs(num*10+3, true, have5, have7);
        dfs(num*10+5, have3, true, have7);
        dfs(num*10+7, have3, have5, true);
    }
}
int main()
{
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
if abs(A-B) % 2 == 0:
    ans = abs(A-B) // 2
else:
    # 折り返し考慮
    ans = min(A-1, B-1)
    ans2 = min(N-A, N-B)
    tmp = max((A-ans), (B-ans))
    ans = tmp // 2 + tmp % 2 + ans
    tmp2 = max(N-(A+ans2), N-(B+ans2))
    ans2 = tmp2 // 2 + tmp2 % 2 + ans2
    ans = min(ans, ans2)
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main()
{
	dhoom;
	string s , t;
	cin >> s >> t;
	int sz = s.size();
	//int tz = t.size();
	for(int i = 0 ; i < sz ; i++)
	{
		string temp = s.substr(i,sz - i)+s.substr(0,i);
	//	cout << temp << endl;
		if(temp == t)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
} 



Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, a, b) = get!(i32, i32, i32);
    let max = std::cmp::min(a, b);
    let min = std::cmp::max(0, a + b - n);
    println!("{} {}", max, min);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

int main() {

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; ++i) {
		int x;
		cin >> x;
		sum += x;
	}
	if (n - sum >= 0)
		cout << n - sum;
	else
		cout << -1;


	return 0;
}

Measured memory_bytes: 3644
#ifndef ___Class_Union_Find
#define ___Class_Union_Find

#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

class Union_Find
{
private:

	vector<int> data;

public:

	Union_Find(unsigned size_) : data(size_, -1) { }

	void unite(int x, int y);
	
	bool same(int x, int y);

	int root(int x);
};

void Union_Find::unite(int x, int y)
{
	x = root(x);
	y = root(y);

	if (x != y)
	{
		if (data[x] < data[y])
		{
			swap(x, y);
		}

		data[x] += data[y];
		data[y] = x;
	}
}

bool Union_Find::same(int x, int y)
{
	return root(x) == root(y);
}

int Union_Find::root(int x)
{
	return data[x] < 0 ? x : data[x] = root(data[x]);
}

#endif // ___Class_Union_Find


// ------ main ------ //

#include <iostream>

using namespace std;

int n, q, com, x, y;

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

	Union_Find u(n);

	for (int i = 0; i < q; i++)
	{
		cin >> com >> x >> y;

		if (com == 0) { u.unite(x, y); }
		if (com == 1) { cout << (u.same(x, y) ? 1 : 0) << endl; }
	}

	return 0;
}

Measured memory_bytes: 3240
n = int(input())
a_ls = list(map(int, input().split()))
a_ls = [0] + a_ls
a_ls.append(0)

S = 0
for i in range(n+1):
    S += abs(a_ls[i] - a_ls[i+1])
for i in range(1,n+1):
    ans = S + abs(a_ls[i+1] - a_ls[i-1]) - (abs(a_ls[i-1] - a_ls[i]) + abs(a_ls[i] - a_ls[i+1]))
    print(ans)

Measured memory_bytes: 14044
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

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

  int N;
  cin>>N;

  deque<pi> plus,zero,minus;
  string S;
  pi p;

  Rep(i,N){
  	cin >>S;
  	p=mp(0,0);
  	for(auto&& s:S){
  		if(s==')'){
  			if(p.se) p.se--;
  			else p.fi++;
  		}
  		else p.se++;
  	}
  	if(p.se>p.fi) plus.eb(p);
  	else if(p.se==p.fi) zero.eb(p);
  	else{
  		swap(p.fi,p.se);
  		minus.eb(p);
  	}
  }

  SortA(plus);
  SortD(minus);

  li c=0;

  for(auto pl: plus){
  	if(pl.fi > c){Yes(0);return 0;}
  	else c=c-pl.fi+pl.se;
  }

  for(auto z:zero){
  	if(z.fi>c) {Yes(0);return 0;}
  }

  for(auto m:minus){
  	if(m.se > c){Yes(0);return 0;}
  	else c=c-m.se+m.fi;
  }

  Yes(!c);
 }

Measured memory_bytes: 19640
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  string s;
  cin>>s;
  REP(i,0,3){
    if(s[i]=='1')s[i]='9';
    else if(s[i]=='9')s[i]='1'; 
  }
  cout<<s<<endl;

  return 0;
}


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

int par[100000],q[100000];
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
int main(){
	int n,m,k;scanf("%d%d%d",&n,&m,&k);
	rep(i,n)par[i]=i;
	memset(q,-1,sizeof(q));
	rep(i,k){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);b--;c--;
		if(a==1){
			b=find(b);c=find(c);
			if(q[b]!=-1&&q[c]!=-1){
				if(q[b]!=q[c]){
					printf("%d\n",i+1);return 0;
				}
			}
			par[b]=c;q[c]=max(q[b],q[c]);
		}
		else{
			b=find(b);
			if(q[b]!=-1&&q[b]!=c){
				printf("%d\n",i+1);return 0;
			}
			q[b]=c;
		}
	}
	puts("0");
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		//String t = sc.next();
		//String g = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		long count=0;
		long[] array=new long[3];

		/*for(int i=0;i<=3;i++) {
			if(s.substring(i,i+1).equals("+")) {
				count++;
			}else {
				count--;
			}
		}*/
		Arrays.sort(array);
		/*if(n==1) {
			System.out.println("Hello World");
		}else {
			System.out.println(m+k);
		}*/
		System.out.println(n+m/2);
		//System.out.println(Math.abs(array[2]-array[1])+Math.abs(array[1]-array[0]));
	}
}




Measured memory_bytes: 23892
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<iostream>
#define int long long
const int maxn=1e5+5;
typedef long long ll; 
using namespace std;
string str;
bool check(string s){
	 string tmp=s;
	 reverse(s.begin(),s.end());
	 if(tmp==s){
	 	return true;
	 }
	 else{
	 	return false;
	 }
}
signed main(){
    cin>>str;
    int N=str.size();
    if(check(str)&&check(str.substr(0,(N-1)/2))&&check(str.substr((N+3)/2-1,N-(N+3)/2+1))){
    	puts("Yes");
    }
    else{
    	puts("No");
    }
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
ll n;
ll dfs(ll v, ll count, vector<ll> used) {
	if (used.size() == n) {
		return ++count;
	}
	bool deadEnd = true;
	rep(i, 0, n) {
		if (find(used.begin(), used.end(), i) == used.end()) {
			deadEnd = false;
			if (graph[v][i] > 0) {
				vector<ll> newUsed = used;
				newUsed.push_back(i);
				count = dfs(i, count, newUsed);
			}
		}
	}
	return deadEnd ? 0 : count;
}

//ABC 54
int main(void) {
	ll m;
	cin >> n >> m;
	graph = vector<vector<ll>>(n, vector<ll>(n,-1));
	rep(i, 0, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a][b] = 1;
		graph[b][a] = 1;
	}

	ll ans = 0;
	ans += dfs(0, 0, vector<ll>(1,0));
	
	cout << ans << endl;
}

Measured memory_bytes: 256
s = int(input())
l = [s]

a = s
for i in range(2, 10**6):
    if a % 2 == 0:
        if a // 2 in l:
            print(i)
            exit()
        l.append(a // 2)
        a = a // 2
    else:
        if 3 * a + 1 in l:
            print(i)
            exit()
        l.append(3 * a + 1)
        a = 3 * a + 1


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> A(n + 2, 0), B(m + 2, 0);
    rep(i, n) {
        ll a;
        cin >> a;
        A[i + 1] = A[i] + a;
    }
    A[0] = 0;
    A[n + 1] = LINF;
    rep(i, m) {
        ll a;
        cin >> a;
        B[i + 1] = B[i] + a;
    }
    B[0] = 0;
    B[m + 1] = LINF;
    int ans = 0;
    int j = m;
    rep(i, n + 1) {
        while(A[i] + B[j] > k) {
            j--;
            if (j < 0) {
                break;
            }
        }
        if (j < 0) break;
        chmax(ans, i + j);
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 6372