akhauriyash/Code-Regression huggingface dataset:
use std::cmp::{Ord, Ordering, PartialOrd};
use std::io::{stdin, Read};
#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, Hash)]
pub struct Reverse<T>(pub T);

impl<T: PartialOrd> PartialOrd for Reverse<T> {
    #[inline]
    fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }

    #[inline]
    fn lt(&self, other: &Self) -> bool {
        other.0 < self.0
    }
    #[inline]
    fn le(&self, other: &Self) -> bool {
        other.0 <= self.0
    }
    #[inline]
    fn gt(&self, other: &Self) -> bool {
        other.0 > self.0
    }
    #[inline]
    fn ge(&self, other: &Self) -> bool {
        other.0 >= self.0
    }
}

impl<T: Ord> Ord for Reverse<T> {
    #[inline]
    fn cmp(&self, other: &Reverse<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (usize, usize) = parse!(it, 2);
    let mut e = vec![];
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (l, r, c): (usize, usize, i64) = parse!(it, 3);
        e.push((l - 1, r - 1));
        g[l - 1].push((r - 1, c));
    }
    e.sort();
    let mut r = 0;
    for i in 0..e.len() {
        if e[i].0 > r {
            println!("{}", -1);
            return;
        }
        r = std::cmp::max(r, e[i].1);
    }
    if r != n - 1 {
        println!("{}", -1);
        return;
    }
    for i in 0..(n - 1) {
        g[i + 1].push((i, 0));
    }

    let mut q = std::collections::BinaryHeap::new();
    let mut d = vec![std::i64::MAX / 10; n];
    d[0] = 0;
    for i in 0..n {
        q.push((Reverse(d[i]), i));
    }
    while let Some((Reverse(du), u)) = q.pop() {
        for &(v, c) in g[u].iter() {
            if d[v] > du + c {
                d[v] = du + c;
                q.push((Reverse(d[v]), v));
            }
        }
    }
    println!("{}", d[n - 1]);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 25332
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PRINT(var) std::cout<<#var"= "<<var<<std::endl

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


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

  int a,b,x;
  vector<int> s(5);
  cin >> s[0] >>s[1] >>s[2]>>s[3]>>s[4]>>b;
  sort(ALL(s));

  if(s[4]-s[0]>b) {
    cout << ":(" <<endl;
  }else{
    cout <<"Yay!" <<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K; cin >> N >> K;
	VP A(N);
	REP(i, N)cin >> A[i].second >> A[i].first;
	rSORT(A);
	VI best(N + 1, 0);
	VI rem;

	REP(i, N) {
		if (best[A[i].second] == 0)best[A[i].second] = A[i].first;
		else rem.push_back(A[i].first);
	}
	rSORT(rem);
	rSORT(best);
	FOR(i, 1, rem.size()) rem[i] += rem[i - 1];
	FOR(i, 1, best.size()) best[i] += best[i - 1];

	int ans = 0;

	eFOR(i, 1, K) {
		if (i != 1 && best[i - 1] == best[i - 2])break;
		int cnt = 0;
		cnt += i * i;
		cnt += best[i - 1];
		if (K - i - 1>=0 && K - i - 1 < rem.size())cnt += rem[K - i - 1];


		chmax(ans, cnt);
	}





	cout << ans << endl;

	return 0;
}



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

int n;
vector<vector<int>> graph(101010, vector<int>(0));
vector<int> colors(101010);
map<P, int> edge_num;
int mc = 0;

void dfs(int a, int pa, int pc){
  int c = 1;
  for(int x : graph.at(a)){
    if(x == pa) continue;
    if(c == pc) c++;
    colors.at(edge_num[P(x, a)]) = c;
    dfs(x, a, c);
    c++;
  }
  mc = max(c - 1, mc);
}

int main(){
  cin >> n;
  rep(i, n - 1){
    int a, b;
    cin >> a >> b;
    graph.at(a).emplace_back(b);
    graph.at(b).emplace_back(a);
    edge_num[P(a, b)] = edge_num[P(b, a)] = i;
  }
  
  dfs(1, 0, 0);
  
  cout << mc << endl;
  rep(i, n - 1) cout << colors[i] << endl;
  
  return 0;
}

Measured memory_bytes: 19456
#include <stdio.h>

int linearSearch(int);
int s[10000],n;

main(){
  int t[10000];
  int i,j,c=0,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

  for(i=0;i<q;i++){
    c+=linearSearch(t[i]);
  }

  printf("%d\n",c);
  return 0;
}

int linearSearch(int key){
  int i;

  i=0;
  s[n]=key;
  while(s[i]!=key){
    i++;
    if(i==n) return 0;
  }
  return 1;
}
  

  
  

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

ll f(ll n) {
  int r = n % 4;
  if (r == 0) return n;
  else if (r == 1) return 1;
  else if (r == 2) return n ^ 1;
  else return 0;
}

int main() {
  ll A, B;
  cin >> A >> B;
  cout << (f(A - 1) ^ f(B)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int a,b; cin>>a>>b;
  if(a%b==0)cout<<-1<<endl;
  else cout<<a<<endl;
}

Measured memory_bytes: 3608
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<u64>().unwrap();
    let mut ans = 1;
    for i in 2..n + 1 {
        ans *= i;
    }
    println!("{}", ans);
}



Measured memory_bytes: 5036
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int A[3];
	for (int i = 0; i < 3; i++) {
		scanf("%d", &A[i]);
	}
	int m = max(max(A[0], A[1]),A[2]);
	printf("%d",   (A[0] * A[1] * A[2]) /(m*2) );




}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cmath>
#include<queue>

using namespace std;
#define MAX 150000
int sieve[MAX+1]={0};//i番目が整数iに対応(1~100000)
//エラトステネスの篩を実装する
void es(){
  //0のところは素数
  for(int i=2;i<=1000;i++){
    if(sieve[i]==0){
      for(int j=1;j<=floor(MAX/i);j++){
        if(j!=1) sieve[j*i]=1;
      }
    }
  }
}


int main(){
  es();
  int k;cin >> k;
  for(int i=k;i<=100010;i++){
    if(sieve[i]==0){cout << i << endl;break;}
  }
}


Measured memory_bytes: 768
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC  127-B
int  main(void) {
	int  r,d,x,i;

	scanf("%d %d %d", &r,&d,&x);

	for (i = 0; i < 10; i++) {
		x = r * x - d;
		printf("%d\n", x);
	}

	return 0;
}
//ABC  131-C Anti-Division 

//int main(void) {
//	ll a, b, c, d,cc,dd,cd,ans;
//
//	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
//
//	cc = b / c - a / c;
//	dd = b / d - a / d;
//	cd = b / (c * d) - a / (c * d);
//
//	ans = (cd + dd) - 2 * cd;
//
//	printf("\n%lld\n",ans);
//	return 0;
//}





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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;
const int MAX_N=1000;

bool judge(string s){
	bool ok=true;
	REP(i,s.size()){
		if(s[i]!=s[s.size()-1-i])ok=false;
	}
	return ok;
}

int main(){
	int ans=0;
	string s;
	cin>>s;
	int j=s.size()-1;
	if(judge(s)){
		cout<<0<<endl;
		return 0;
	}
	REP(i,s.size()){
		if(s[i]=='x' && s[j]!='x'){
			ans++;
		}else if(s[i]!='x' && s[j]=='x'){
			ans++;
			i--;
			j--;
		}
		else if(s[i]==s[j]){
			j--;
		}else if(s[i]!=s[j]){
			ans=-1;
			break;
		}
		if(i>j || i==j)break;
	}
	if(ans==0)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}

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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll long long int

int main()
{
    FAST;
    ll a,b,c,d,e,l=1,lu=1,s=2,h=0,o,ax[1001],ce=1;
    cin>>a>>b>>c>>d>>e;
    if (a==0)
    {
    	cout<<b-(c-b);
	}
	else if (b==0)
    {
    	cout<<c-(d-c);
	}
	else if (c==0)
    {
    	cout<<d-(e-d);
	}
	else if (d==0)
    {
    	cout<<e-(b-a);
	}
	else if (e==0)
    {
    	cout<<d+(c-b);
	}
}

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

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

  int n;
  cin >> n;

  if (n % 2 == 0) {
    cout << n << endl;
  } else {
    cout << 2 * n << endl;
  }

  return 0;
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])

const v = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  const s = v.sort((a, b) => a - b)

  let res = s[0]
  for (let i = 1; i < n; i++) {
    const avg = (res + s[i]) / 2
    res = avg
  }

  console.log(res)
}

ans()


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

int main(){
    int L;
    cin >> L;
    int S = 1, T = 20;
    vector<vector<int>> ans;
    while(L > 1){
        if(L%2){
            ans.push_back({S, T, L-1});
            L--;
        }else{
            ans.push_back({S, S+1, 0});
            ans.push_back({S, S+1, L/2});
            S++;
            L /= 2;
        }
    }
    cout << S << " " << ans.size() << endl;
    for(auto& v : ans){
        cout << v[0] << " " << (v[1] == T ? S : v[1]) << " " << v[2] << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
#define min(a,b) a<b?a:b 
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x,char s) {
    if(x>=10) { print(x/10,'S'); }
    putchar(x%10+'0');
    if(s!='S') putchar(s);
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
template<class T>inline T po(T a) { return a*a; }
inline int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); }
int n,a,b,rans;
inline int ksm(int a,int b) {
	int ans=1,asd=a;
	while(b) {
		if(b&1) ans*=asd;
		asd=asd*asd; asd%=mod;
		b>>=1;
		ans%=mod;
	}
	return ans;
}
inline void exgcd(int a,int b,int &x,int &y) {
    if(!b) x=1,y=0;
    else exgcd(b,a%b,y,x),y-=a/b*x;
}
inline int C(int A,int B) {
	int ans=1,k=1;
	rep(i,A-B+1,A) ans*=i,ans%=mod;
	rep(i,1,B) k*=i,k%=mod;
	int x,y;
	exgcd(k,mod,x,y);
	x=(x+mod)%mod;
	return ((ans*x)%mod);
}
signed main() {
	read(n); read(a); read(b);
	rans=ksm(2,n); rans--;
	rans-=C(n,a); rans+=mod;
	rans-=C(n,b); rans+=mod;
	rans%=mod;
	print(rans);
}

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

int main() {
  int A,B;
  cin >> A >> B;
  
  int answer = 0;
  for (int N = A; N <= B; N++) {
    if ((N % 10 == N / 10000) && (N % 100 / 10 == N % 10000 / 1000)) {
      answer++;
    }
    else {
      continue;
    }
  }
  
  cout << answer << endl;
}




Measured memory_bytes: 256
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *	
#from heapq import *
from math import gcd,ceil,sqrt
from itertools import permutations as prm,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)

t=1

def updatepoint(point,val,bit):

	while point<=4*n:
		bit[point]+=val
		point+=(point&-point)
def query(point,bit):
	ans=0
	while point>0:
		ans+=bit[point]
		point-=(point&-point)
	return ans	

def update(l,r,val,bit):

	updatepoint(l,val,bit)
	updatepoint(r+1,-val,bit)


while t>0:
	t-=1
	n,q=mi()
	ans=(n-2)**2
	bitc=[0]*(4*n)
	bitr=[0]*(4*n)
	r={}
	c={}
	for i in range(q):
		x,y=mi()
		if x==1 and y not in c:
			c[y]=1
			p=query(y,bitc)
			ans-=(n-1+p)-1
			if n-1+bitr[2]>=y:
				update(2,n-1+bitc[2],y-1-(n-1+bitr[2]),bitr)
		elif x==2 and y not in r:
			r[y]=1
			p=query(y,bitr)
			ans-=(n-1+p)-1
			if n-1+bitc[2]>=y:
				update(2,n-1+bitr[2],y-1-(n-1+bitc[2]),bitc)

	print(ans)			


Measured memory_bytes: 111148
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
#define LL long long

#define Inf 0x7fffffff
int main()
{
    ios::sync_with_stdio(false);
    int N,c,i,j,res,flag;
    while(cin>>N)
    {
    	res=0;
    	for(i=105;i<=N;i+=2)
    	{
    		c=0;
    		for(j=1;j*j<=i;j++)
    		{
    			if(i==i/j*j)
    			c+=2;
			}
	
			if(c==8)
			res++;
		}
		cout<<res<<endl;
	}
    return 0;
}


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

int main()
{
  int n, p[200001];
  int q[200001], m = 0;;

  cin >> n;
  for(int i = 1; i <= n; i++){
    int x;
    cin >> x;
    p[x] = i;
    q[i] = 1;
  }

  for(int i = 1; i < n; i++){
    if(p[i] < p[i+1]){
      q[i+1] += q[i]; 
    }
  }

  for(int i = 1; i <= n; i++){
    if(m < q[i]) m = q[i];
  }

  cout << n - m << endl;
  
  return 0;
}


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

#define ll long long int
#define endl '\n'
#define inf 1e18
#define mod 1e9+7

double dp[3005][3005];
double ar[3005];
void testCase()
{
   // ll t; cin>>t; while(t--)
    {
      ll n;
      cin>>n;
      for(int i=0;i<n;i++)
      cin>>ar[i];

      dp[0][0]=(1-ar[0]);
      dp[0][1]=ar[0];

      for(int i=1;i<n;i++)
      {
          for(int j=0;j<3000;j++)
          {
              dp[i][j]+=dp[i-1][j]*(1-ar[i]);
              if(j>0)
              dp[i][j]+=dp[i-1][j-1]*ar[i];
          }
      }
      double ans=0;
      for(int i=n/2+1;i<3000;i++)
      ans+=dp[n-1][i];
      cout<<setprecision(9);
      cout<<fixed;
      cout<<ans<<endl;
    } 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 74096
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005, bs = 320;

int n, L, x[mxn], nxt[mxn], rootnxt[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    cin >> L >> Q;

    for (int i = 1; i <= n; i++) {
        nxt[i] = int(upper_bound(x+i, x+1+n, x[i]+L)-x)-1;//bug(i, nxt[i]);
    }

    for (int i = 1; i <= n; i++) {
        rootnxt[i] = i;
        for (int j = 0; j < bs; j++) {
            if (rootnxt[i] == n) {rootnxt[i] = n+1;break;}
            rootnxt[i] = nxt[rootnxt[i]];
        }//bug(i, rootnxt[i]);
    }

    while (Q--) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        int tmp = a, ans = 0;
        while (rootnxt[tmp]<=b) {
            tmp = rootnxt[tmp], ans += bs;
        }
        while (tmp<b) {
            tmp = nxt[tmp], ++ans;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
  string S; cin >> S;
  ll K; cin >> K;
  ll i, j=1, ans0=0, ans1=0, ans2=0;
  string SS = S + S, SSS = S + S + S;
  if(K!=1){
  rep(i,S.size()-1){
    if(S[i]==S[i+1]) j++;
    else {
      ans0 += j / 2;
      j=1;
    }
  }
  ans0 += j/2;
  j = 1;

  rep(i,SS.size()-1){
    if(SS[i]==SS[i+1]) j++;
    else {
      ans1 += j / 2;
      j=1;
    }
  }
  ans1 += j/2;
  j = 1;

  rep(i,SSS.size()-1){
    if(SSS[i]==SSS[i+1]) j++;
    else {
      ans2 += j / 2;
      j=1;
    }
  }
  ans2 += j/2;
  AA(ans0 + (ans2 - ans0) * ((K - 1) / 2) + (ans1 - ans0) * ((K-1)%2));
  }
  else{
    rep(i,S.size()-1){
    if(S[i]==S[i+1]) j++;
    else {
      ans1 += j / 2;
      j=1;
    }
  }
  ans1 += j/2;
  AA(ans1);
  }
  return 0;
}

Measured memory_bytes: 256
//Pranet Verma
#include <bits/stdc++.h>
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, ret = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		ret += a - 1;
	} 
	cout << ret;
}

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

int main(void)
{
	int n, i;
	char t[101], h[101];
	int t_p = 0, h_p = 0;
	int v;					//??????????????¨.

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s %s", t, h);

		v = strcmp(t, h);

		if (v > 0)
			t_p += 3;
		else if (v < 0)
			h_p += 3;
		else {
			t_p++;
			h_p++;
		}
	}

	printf("%d %d\n", t_p, h_p);

	return 0;
}

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

typedef long long ll;

template <class T>
ostream & operator << (ostream &out, const vector<T> v) {
    for (int i = 0; i < int(v.size()); i++) {
        out << v[i] << " ";
    }
    return out;
}

ll solve() {
    int R, C, K;
    cin >> R >> C >> K;

    auto A = vector<vector<ll>>(R, vector<ll>(C, 0ll));
    for (int k = 0; k < K; k++) {
        int r, c, v; cin >> r >> c >> v; r--; c--;
        A[r][c] = v;
    }

    // dp[r, c, p] = maximum sum of value from (0, 0) to (r, c) 
    //               if p items are picked in previous C grids
    auto dp = vector<vector<vector<ll>>>(R, vector<vector<ll>>(C, vector<ll>(4, 0)));
    dp[0][0][1] = ((A[0][0] > 0) ? A[0][0] : 0);
    for (int r = 0; r < R; r++) {
        for (int c = 0; c < C; c++) {
            // pick A[r][c]
            {
                // from left
                if (c >= 1) {
                    for (int p = 1; p < 4; p++) {
                        dp[r][c][p] = max(dp[r][c][p], dp[r][c - 1][p - 1] + A[r][c]);
                    }
                }
                // from top
                if (r >= 1) {
                    for (int p = 0; p < 4; p++) {
                        dp[r][c][1] = max(dp[r][c][1], dp[r - 1][c][p] + A[r][c]);
                    }
                }
            }
            // don't pick A[r][c]
            {
                // from left
                if (c >= 1) {
                    for (int p = 0; p < 4; p++) {
                        dp[r][c][p] = max(dp[r][c][p], dp[r][c - 1][p]);
                    }
                }
                // from top
                if (r >= 1) {
                    for (int p = 0; p < 4; p++) {
                        dp[r][c][0] = max(dp[r][c][0], dp[r - 1][c][p]);
                    }
                }
            }
        }
    }

    return *max_element(dp[R - 1][C - 1].begin(), dp[R - 1][C - 1].end());
}

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

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 706572
N,M=map(int,input().split())
L=[[] for _ in range(N)]
H=list(map(int,input().split()))
p=0
for i in range(M):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
for i in range(N):
    s=0
    for x in L[i]:
        if H[x]>=H[i]:
            s=1
            break
    if s==0:
        p+=1
print(p)


Measured memory_bytes: 30996
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//

int used[MAX];
vector<int> tv;
vector<vector<int> > g;

//----------//

void tsort(int v){
    if(used[v]) return;
    for(int u: g[v]){
        if(!used[u])tsort(u);
    }
    used[v] = true;
    tv.push_back(v);
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//

    int n, m;
    cin >> n >> m;
    g.resize(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }
    //print(g);

    rep(i, n){
        tsort(i);
    }
    //print(tv);

    int ans = 0;
    vector<int> dp(n);
    for(int i : tv){
        for(int v : g[i]){
            dp[i] = max(dp[i], dp[v]+1);
        }
        ans = max(dp[i], ans);
        // cout << "--" << i << endl;
        // cout << ans << endl;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  vector<string> A(a);
  vector<string> B(b);
  for(int i=0;i<a;i++)
    cin >> A.at(i);
  for(int i=0;i<b;i++)
    cin >> B.at(i);
    
  bool result = false;
  bool match;
  for(int ai = 0;ai< a-b+1;ai++){
    for(int aj = 0;aj < a-b+1;aj++){
      match = true;
      for(int i = 0;i<b;i++){
        for(int j = 0;j<b;j++){
          if(A.at(ai+i).at(aj+j) != B.at(i).at(j)){
            match = false;
            break;
          }
        }
      }
      if(match == true){
        break;
      }
    }
    if(match == true){
      result = true;
      break;
    }
  }
  if(result == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] strs = str.split(" ");
        int a = Integer.parseInt(strs[0]);
        int b = Integer.parseInt(strs[1]);
        int c = Integer.parseInt(strs[2]);
        int cnt = 0;
        for(int i = a; i <= b; i++){
            if((c % i) == 0){
                cnt++;
            }//if
        }//for
        System.out.println(cnt);
        br.close();
    }
}

Measured memory_bytes: 24296
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        h:usize,
        w:usize,
        ab:[(usize,usize);n],
    }

    println!(
        "{}",
        ab.into_iter().filter(|&(a, b)| a >= h && b >= w).count()
    );
}


Measured memory_bytes: 2236
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string a;
  int i,j,co,d;
  d=0;
  co=0;
  cin>> a;
  
  for(i=0;i<3;i++){
    for(j=1;i+j<4;j++){
      if(a.at(i)==a.at(i+j)){
        co++;
      }
      else{
        d++;
      }
    }
  }
  
  if((co==2)&&(d==4)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    cout << a+b/2 << endl;
}

Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Graph2 {
	int totalVertex;
	Queue<Integer> toVisit;
	int[] distance;
	public LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph2() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		toVisit = new LinkedList<Integer>();
		distance = new int[totalVertex];
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		
		for(int i = 1; i < totalVertex; i++) {
			distance[i] = Integer.MAX_VALUE;
		}
		
		in.close();
	}
	
	
	public void BFS(int v) {
		toVisit.add(v);
		while(!toVisit.isEmpty()) {
			int next = toVisit.remove();
			for(int neighbor : adjList.get(next)) {
				if(!toVisit.contains(neighbor)) {
					if(distance[neighbor] > distance[next] + 1) {
						toVisit.add(neighbor);
						distance[neighbor] = distance[next] + 1;
					}
				}
			}
		}
	}
	
	public void SearchGraph() {
		BFS(0);
		for(int i = 0; i < totalVertex; i++) {
			if(distance[i] == Integer.MAX_VALUE) {
				distance[i] = -1;
			}
			System.out.println(i+1 + " " + distance[i]);
		}
	}
	
}
//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {

	
	public static void main(String argv[]) {
		Graph2 g = new Graph2();
		g.loadAdjList();
		g.SearchGraph();
	}
}


Measured memory_bytes: 28432
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int min = 1001;
        for (int i = 0; i < N; i++) {
            int c = sc.nextInt();
            int t = sc.nextInt();
            if (T >= t && min > c) {
                min = c;
            }
        }
        sc.close();
        System.out.println(min == 1001 ? "TLE" : min);
    }
}

Measured memory_bytes: 22996
def rec(n):
    if n>0:
        for i in range(n,0,-1):
            if i<=ans[-1]:
                ans.append(i)
                rec(n-i)
                ans.pop()
    else:
        if len(ans)!=0:
            print ' '.join(map(str, ans[1:]))


while True:
    n = input()
    if n==0: break
    ans = [n]
    rec(n)

Measured memory_bytes: 4264
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<unordered_map>

#define ll long long
using namespace  std;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll qpow(ll a, ll b) {
	ll ans = 1, base = a;
	while (b) {
		if (b & 1) {
			ans *= base;
		}
		base *= base;
		b >>= 1;
	}
	return ans;
}

/*A*/

//int main() {
//	ios::sync_with_stdio(0);
//	int l, r,d; cin >> l >> r >> d;
//	cout << (r / d) - (l - 1) / d << endl;
//}

/*B*/

//int main() {
//	ios::sync_with_stdio(0);
//	int n; cin >> n;
//	int cnt = 0;
//	for (int i = 1; i <= n; ++i) {
//		int tmp; cin >> tmp;
//		if (i % 2 && tmp % 2) {
//			cnt++;
//		}
//	}
//	cout << cnt << endl;
//}

/*C*/
//typedef struct node {
//	int a, b, c;
//}Node;
int s[10005];
int main() {
	ios::sync_with_stdio(0);
	int n; cin >> n;
	for (int i = 1; i <= 100;++i) {
		for (int j = 1; j <= 100;++j) {
			for (int k = 1; k <= 100;++k) {
				int res = i * i + j * j + k * k + i * j + j * k + i * k;
				if (res <= 10000)
				{
					//struct node tmp = { i, j, k };
					s[res]++;;
				}
				else
					break;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << s[i] << '\n';
	}
}


Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.int_cols_list(N)
    ans = 0
    for i in range(N - 1):
        ans += A[i] // 2
        A[i] %= 2
        t = min(A[i], A[i + 1])
        ans += t
        A[i] -= t
        A[i + 1] -= t
    ans += A[-1] // 2
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 14668
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	var n = parseInt(input[0],10)
	var S = input[1];
	var value = 0;
	var max = 0;

	for(var i = 0; i < S.length; i++){
		if(S.charAt(i) === "I"){
			value++;
		} else {
			value--;
		}

		if(value > max){
			max = value;
		}
	}
	console.log(max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
int dp[101][100001], arr[101], pref[101][100001];
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int N, K, M= 1e9+7;
    cin >> N >> K;
    for (int i=1; i<=N; i++)
        cin >> arr[i];
    for (auto &i:  pref[0])
        i = 1;
    for (int i=1; i<=N; i++){
        for (int k=0; k<=min(arr[i], K); k++){
            dp[i][k] = pref[i][k] = pref[i-1][k];
            if (k) pref[i][k]+= pref[i][k-1];
            if (pref[i][k]>=M) pref[i][k] -= M;
        }
        for (int k=arr[i]+1; k<=K; k++) {
            dp[i][k] = pref[i - 1][k]-pref[i-1][k-arr[i]-1];
            while (dp[i][k]<0) dp[i][k] += M;
            pref[i][k] = (pref[i][k - 1] + dp[i][k]) % M;
        }
    }
    cout << dp[N][K] << "\n";
}

Measured memory_bytes: 82080
N, M = map(int, input().split())
x = []
y = []
z = []
for i in range(N):
 x1, y1, z1 = [int(i) for i in input().split()]
 x.append(x1)
 y.append(y1)
 z.append(z1)


ans = 0

for x_sign in range(2):
 for y_sign in range(2):
  for z_sign in range(2):
   x3 = [x1 * (1 - 2 * x_sign) for x1 in x]
   y3 = [y1 * (1 - 2 * y_sign) for y1 in y]
   z3 = [z1 * (1 - 2 * z_sign) for z1 in z]
   w = [x1+y1+z1 for (x1,y1,z1) in zip(x3,y3,z3)]
   w.sort(reverse=True)
   w = w[:M]
   tmp = sum(w)
   if ans<tmp:
    ans = tmp

print(ans)

Measured memory_bytes: 3316
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    s=[a[0]]*n
    for i in range(1,n):
        s[i]=s[i-1]+a[i]

    cnt1=0
    s1=s[:]
    f1=0
    #1,-1,...
    for i in range(n):
        if i%2==0:
            if s1[i]+f1<=0:
                cnt1+=abs(1-s1[i]-f1)
                f1+=1-s1[i]-f1
        else:
            if s1[i]+f1>=0:
                cnt1+=abs(-1-s1[i]-f1)
                f1+=-1-s1[i]-f1
    
    cnt2=0
    s2=s[:]
    f2=0
    #-1,1,...
    for i in range(n):
        if i%2==0:
            if s2[i]+f2>=0:
                cnt2+=abs(-1-s2[i]-f2)
                f2+=-1-s2[i]-f2
        else:
            if s2[i]+f2<=0:
                cnt2+=abs(1-s2[i]-f2)
                f2+=1-s2[i]-f2
    print(min(cnt1,cnt2))

if __name__=="__main__":
    main()

Measured memory_bytes: 14332
N = int(input())
a = list(map(int,input().split()))
a4 = [i for i in a if i%4 == 0]
a2 = [i for i in a if i%2 == 0]
num4 = len(a4)
num2 = len(a2) - num4
num1 = N-num2-num4
if num2 == 0 and num4 == num1-1:
    print('Yes')
elif num1 > num4:
    print('No')
else:
    print('Yes')

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

int main()
{
	string s;
	cin >> s;
	cout << 2018;
	REP(i, 4, s.size()) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = []

for i in range(h):
    r = list(input())
    if '#' in r:
        a.append(r)

box = [0] * w

for colum in range(w):
    if all(row[colum] == '.' for row in a) :
        box[colum] = 1

for j in range(w):
    if box[j] == 1:
        for row in a:
            row[j] = ''

for row in a:
    print(''.join(map(str, row)))

Measured memory_bytes: 9224
f=->b,x{x<b ?x: f[b,x/b]+x%b}
n,s=$<.map &:to_i;m=Math.sqrt(n).to_i
if n<s
	p -1
elsif n==s
	p n+1
elsif b=2.upto(m).find{|b|f[b,n]==s}
	p b
elsif b=m.downto(1).find{|b|(n-s)%b==0&&f[z=(n-s)/b+1,n]==s&&(break z)}
	p b
else
	p -1
end

Measured memory_bytes: 1916
import java.util.HashMap;
import java.util.Scanner;

class Main {
    void solve() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++) {
            int d = in.nextInt();
            if(map.containsKey(new Integer(d))) {
                map.put(new Integer(d), map.get(new Integer(d))  +1);
            }else {
                map.put(new Integer(d), 1);
            }
        }
        int m = in.nextInt();
        for(int i = 0; i < m; i++) {
            int t = in.nextInt();
            if(!map.containsKey(new Integer(t))) {
                System.out.println("NO");
                return;
            }
            int count = map.get(new Integer(t));
            if(count == 0) {
                System.out.println("NO");
                return;
            }
            map.put(new Integer(t), count - 1);
        }
        System.out.println("YES");
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 132680
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265358979323846264338;
string arr[100001];
const int ad = 'A' - 'a';





bool issqt(long long k) {
	if (k <= 3)return true;
	long long s = (long long)sqrt(k);
	//cout<<k<<" "<<s<<endl;
	for (long long i = 2; i <= s; i++)
		if (k % i == 0)return false;
	return true;
}
string s;
bool cmp(string a, string b) {
	int la = a.length();
	int lb = b.length();
	int lnth = min(la, lb);
	for (int i = 0; i < lnth; i++) {
		if (a[i] == b[i])continue;
		int ac, bc;
		for (int j = 0; j < 26; j++) {

			if (a[i] == s[j])ac = j;
			if (a[i] == s[j] + ad)ac = j - ad;
			if (b[i] == s[j])bc = j;
			if (b[i] == s[j] + ad)bc = j - ad;
		}
		return ac < bc;
	}
	if (la < lb)return true;
	return false;
}

int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;

	
	return 0;
}




Measured memory_bytes: 6740
//
//AtCoder Beginner Contest 172
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

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

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);    
    vector<int> b(m);
    REP(i, n) cin >> a[i];
    REP(i, m) cin >> b[i];

    ll asum=0;
    int ai=0;
    REP(i, n){
        if ((asum+a[i])<=k){
            asum+=a[i];
            ai=i+1;
        }else break;
    }
    //MSG(ai);
    //MSG(asum);

    vector<ll> bsum(m, 0);
    bsum[0] = b[0];
    FOR(i, 1, m-1){
        bsum[i]=bsum[i-1]+b[i];
    }
    //REP(i,m) MSG(bsum[i]);
    
    ll ans=0;
    FORD(i, ai, 0){
        ll bi = lower_bound(ALL(bsum), k-asum) - bsum.begin();
        if (bsum[bi]==k-asum) bi++;
        if (bi>m) bi=m;
        //cout << i << " " << bi << " " << k-asum << endl;
        ans = max(ans, i+bi);
        if (i>0) asum-=a[i-1];
    }


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


Measured memory_bytes: 6408
function Main(input) {
	input = input.split("\n").map(function(i){ return Number(i); });
    console.log("%d",(input[0]+input[1])*input[2]*0.5);
};
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys 
sys.setrecursionlimit(1000000)

def dfs(A, i):
    if i > N:
        return A
    if len(str(i)) >= 3:
        if "3" in str(i) and "5" in str(i) and "7" in str(i):
            A.append(i) # 入力をイメージしながらappendの位置を決める
    for v in range(3, 8 , 2):
        i = i * 10 + v
        dfs(A, i)
        i = int(str(i)[:len(str(i))-1])

N = int(input())
B = []
for i in range(3, 8, 2):
    A = []
    dfs(A, i)
    B = B + A
print(len(B))





Measured memory_bytes: 4308
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main() {
   
   long N;
   
   std::cin >> N;
   
   std::vector<long> A(N, 0);
   
   for (long i = 0; i < N; i++) {
      std::cin >> A[i];
   }
   
   long Q;
   
   std::cin >> Q;
   
   std::vector<long> B(Q, 0);
   std::vector<long> C(Q, 0);
   
   for (long i = 0; i < Q; i++) {
      std::cin >> B[i] >> C[i];
   }
   
   std::vector<long> Check(100001, 0);
   
   for (long i = 0; i < N; i++) {
      Check[A[i]]++;
   }
   
   long sum = 0;
   
   for (long i = 0; i < N; i++) {
      sum += A[i];
   }
   
   for (long i = 0; i < Q; i++) {
      sum += (C[i] - B[i])*Check[B[i]];
      std::cout << sum << std::endl;
      if (Check[B[i]] > 0) {
         Check[C[i]] += Check[B[i]];
         Check[B[i]] = 0;
      }
   }
   
   
   return 0;
   
}


Measured memory_bytes: 5936
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, q;
	cin >> n;

	ll sum = 0;
	const int maxn = 2e5 + 5;
	vector<int> freq(maxn);

	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		freq[x]++;
		sum += 1ll * x;
	}

	cin >> q;

	while(q--){
		int x, y;
		cin >> x >> y;
		sum -= 1ll * x * freq[x];
		sum += 1ll * y * freq[x];
		freq[y] += freq[x];
		freq[x] = 0;
		cout << sum << endl;
	}


	return 0;
}

Measured memory_bytes: 4012