akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int w = int.Parse(Console.ReadLine());
            int[] lines = Enumerable.Range(1, w).ToArray();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(',');
                int a = int.Parse(input[0]) - 1;
                int b = int.Parse(input[1]) - 1;

                int temp = lines[a];
                lines[a] = lines[b];
                lines[b] = temp;
            }

            foreach (var num in lines) sb.AppendLine(num.ToString());
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9496
#include "bits/stdc++.h"

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

void binarySearch(int num, deque<int> &dq) {
	int left = -1;
	int right = dq.size();
	int mid = (right + left) / 2;
	while (right - left > 1) {
		mid = (right + left) / 2;
		if (dq[mid] >= num)right = mid;
		else left = mid;
	}
	//cout << dq[left] << "->";
	dq[left] = num;
	//cout << num << endl;
}

int main() {
	int N; cin >> N;
	vector<int> maxes;
	deque<int> dq;
	int preNum = INF;
	rep(i, N) {
		int a; cin >> a;
		if (a <= preNum) {
			if (dq.empty() || dq.front() >= a) {
				dq.push_front(a);
				//cout << "push: " << a << endl;
			}
			else {
				binarySearch(a, dq);
				//cout << "concat: " << a << endl;
			}
		}
		else {
			binarySearch(a, dq);
			//cout << "concat: " << a << endl;
		}
		preNum = a;
	}
	cout << dq.size();
}


Measured memory_bytes: 640
n,m,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
for i in range(1,n):
    arr[i]+=arr[i-1]
for i in range(1,m):
    brr[i]+=brr[i-1]
ans = 0
t = 0
for i in range(n):
    if arr[i]<=k:
        t = i+1
ans = max(ans,t)
for i in range(m):
    if brr[i]<=k:
        t = i+1
ans = max(t,ans)

for i in range(n):
    t = arr[i]
    rem = k-t
    if rem>=0:
        lo = 0
        hi = m-1
        while lo<hi:
            mid = (lo+hi)//2
            if brr[mid]<=rem:
                lo = mid
            else:
                hi = mid
            if hi-lo==1:
                break
        if brr[hi]<=rem:
            ans = max(ans,hi+1+i+1)
        elif brr[lo]<=rem:
            ans = max(ans,lo+1+i+1)
print(ans)


Measured memory_bytes: 111196
n = int(input())
abc  = [[], [], []]

for i in range(n): # DB取得方法のみ違う, 分かればどっちでもok
    tmp_1, tmp_2, tmp_3 = map(int, input().split())
    abc[0].append(tmp_1)
    abc[1].append(tmp_2)
    abc[2].append(tmp_3)
#print(abc)

dp = [[0,0,0] for _ in range(n)]
dp[0] = [abc[0][0], abc[1][0], abc[2][0]]
#print(dp)

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[j][i]) # ここのDB指定方法に影響

print(max(dp[-1]))

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

bool linearSearch(int S[], int numS, int key) {
	int i = 0;
	S[numS] = key;
	while (S[i] != key) i++;

	if (i == numS) return false;
	return true;
}

int main() {
	int numS, numT;
	int S[100000+1];
	int key;
	int num = 0;

	cin >> numS;
	for (int i = 0; i < numS; i++) {
		cin >> S[i];
	}
	cin >> numT;
	for (int i = 0; i < numT; i++) {
		cin >> key;
		if (linearSearch(S, numS, key)) num++;
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 3128
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
ll mod=1000*1000*1000+7;
int main() {
    cout.precision(10);
    cout<<fixed;
    ll N,K;
    cin >> N >> K;
    ll ans=0;
    for(ll i=K;i<=N+1;++i) {
        ans+=(2*N-i+1)*i/2-(i-1)*i/2+1;
        ans=AS_MOD(ans,mod);
    }
    cout<<ans<<endl;
}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  
  if(a==b&&b==c&&c==a){
  	cout<<"No"<<endl;
  }
  
  else if(a==b||b==c||c==a){
  	cout<<"Yes"<<endl;
  }
  
  else{
  	cout<<"No"<<endl;

  }

}

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

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        Set<String> set = new HashSet();
        for (int i = 0; i < n; i++) {
            String val = sc.next();
            set.add(val);
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 66364
class Node
  include Comparable

  def initialize(id, key)
    @id = id
    @key = key
  end

  def <=>(other)
    @key <=> other.key
  end

  DUMMY = Node.new(-1, -2_000_000_001)

  attr_accessor :id, :key
end

def maxHeapify(array, i)
  left = (i*2 < array.size) ? array[i*2] : Node::DUMMY
  right = (i*2+1 < array.size) ? array[i*2+1] : Node::DUMMY
  max = [array[i], left, right].sort_by{|x| x.key}.pop
  max_key = max.key
  if (left.key == max.key) then
    left.key = array[i].key
    array[i].key = max_key
    maxHeapify(array, left.id)
  elsif (right.key == max.key) then
    right.key = array[i].key
    array[i].key = max_key
    maxHeapify(array, right.id)
  end
end

def buildMaxHeap(array)
  ((array.size-1) / 2).downto(1) do |i|
    maxHeapify(array, i)
  end
end


# main
n = gets.chomp.to_i
input = gets.chomp.split.map(&:to_i)
array = [n]
input.each_with_index do |key, id|
  id += 1
  node = Node.new(id, key)
  array << node
end

buildMaxHeap(array)
array.shift
puts " #{array.map{|x| x.key}.join(' ')}"

Measured memory_bytes: 82116
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
    i64 h1,m1,h2,m2,k,t1,t2;
    cin>>h1>>m1>>h2>>m2>>k;
    t1=h1*60+m1;
    t2=h2*60+m2;
    if(t1+k>t2)cout<<"0";
    cout<<(t2-k-t1);





    return 0;
  }


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<map>
#include<string>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

typedef pair<double,pair<int,int> > pp;

pp p[100000];

int main(){
  int an,bn,r;
  while(scanf("%d%d%d",&an,&bn,&r), an+bn+r){
    int ans = 0;

    REP(i,an){
      int x, y;
      scanf("%d%d", &x, &y);

      p[i].f = sqrt((double)(x*x + y*y));
      p[i].s.f = x; p[i].s.s = y;
    }

    sort(p, p+an);

    REP(i,bn){
      int x, y;
      scanf("%d%d", &x, &y);

      double rmin = sqrt((double)(x*x + y*y)) - r*4 - 0.1;
      double rmax = sqrt((double)(x*x + y*y)) + r*4 + 0.1;
      pp *now = lower_bound(p, p+an, pp(rmin,mp(INT_MIN,INT_MIN)));
      pp *end = upper_bound(p, p+an, pp(rmax,mp(INT_MAX,INT_MAX)));
      while(now != end){
	int xx = now->s.f, yy = now->s.s;
	if((x-xx)*(x-xx) + (y-yy)*(y-yy) <= 4*r * 4*r) ans++;
	now++;
      }
    }

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

Measured memory_bytes: 2440
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input!(N: usize);
    let mut ans = 0.;
    for _ in 0..N {
        input!(x: String, u: String);
        match u.as_str() {
            "JPY" => ans += x.parse::<f64>().unwrap(),
            "BTC" | _ => ans += x.parse::<f64>().unwrap() * 380000.
        }
    }
    println!("{}", ans)
}


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

int main(){
	int n;cin>>n;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		cin>>d.at(i);
	}
	sort(d.begin(),d.end());
	cout<<d.at(n/2)-d.at(n/2-1)<<endl;
	return 0;
}


Measured memory_bytes: 640
n=int(input())

t = list(map(int,input().split()))

ans = 0

sa = [0]*(n+1)

for i in range(n):
    if i+1-t[i] > 0:
        sa[i+1-t[i]] += 1

for i in range(n):
    if 0 < i+1+t[i] < n:
        ans += sa[i+1+t[i]]
    if i+1-t[i] > 0:
        sa[i+1-t[i]] -= 1
print(ans)
        

Measured memory_bytes: 92784
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	int n; cin>>n;
	map<ll,ll> m;
	ll ans{}, sum{};
	m[0]++;
	for(int i=0; i<n; i++){
		int a; cin>>a;
		sum += a;
		m[sum]++;
	}
	for(auto i:m){
		ans += i.second*(i.second-1)/2;
	}
	cout << ans << endl;
	
}


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

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut f = vec![0; N+1];
    for x in 1..=100 {
        for y in 1..=100 {
            for z in 1..=100 {
                if x*x + y*y + z*z + x*y + y*z + z*x <= N {
                    f[x*x + y*y + z*z + x*y + y*z + z*x] += 1;
                }
            }
        }
    }
    for i in 1..=N {
        println!("{}", f[i]);
    }
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string s1,s2;
    cin >> s1 >> s2;
    if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;

int INF = 1000000005;
using namespace std;

int main() {
    char x, y;
    cin >> x >> y;
    cout << (x<y ? '<' : x>y ? '>' : '=') << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a[100][100];
	int b[100];
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	
	for(int i =0;i<m;i++)
	{
		scanf("%d",&b[i]);
	}
	
	int c[100]={0};
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			c[i]+=a[i][j]*b[j];
		}
	}
	
	for(int i = 0;i<n;i++)
	{
		printf("%d\n",c[i]);
	}
	return 0;
}


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

int main(){

  int n, m, p, x, sum = 0;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    sum += t[i];
  }
  cin >> m;

  int ans[m];

  for (int i = 0; i < m; i++) {
    cin >> p >> x;
    ans[i] = sum - t[p - 1] + x;
  }

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




}


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> l(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
    l[i] = i;
  }

  sort(l.begin(), l.end(), [&x](const auto &a, const auto &b) { return x[a] < x[b]; });
  // for (int i = 0; i < n; ++i) { cout << x[l[i]] << endl; }

  for (int i = 0; i < n; ++i) {
    if (x[i] <= x[l[n / 2 - 1]]) {
      cout << x[l[n / 2]] << endl;
    } else {
      cout << x[l[n / 2 - 1]] << endl;
    }
  }
}


Measured memory_bytes: 3712
n,m = gets.split.map(&:to_i)
a = Array.new(n).map{Array.new(n)}
b = Array.new(m).map{Array.new(m)}
for i in 0..(n-1)
  a[i] = gets.chomp.split("")
end
for i in 0..(m-1)
  b[i] = gets.chomp.split("")
end

ismatch = 0
for x in 0..(n-m)
  for y in 0..(n-m)
    flag = 1
    for i in 0..(m-1)
      for j in 0..(m-1)
        if a[x+i][y+j] != b[i][j]
          flag = 0
          break
        end
      end
      break if flag == 0
    end
    if flag == 1
      ismatch = 1
      break
    end
  end
  break if ismatch == 1
end

ismatch == 1 ? (puts "Yes"):(puts "No")

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

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

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL b(n-1);
	cin >> b;
	VL a(n,0);
	a[0] = b[0];
	LL ans = b[0];
	for (int i = 0; i < n-2; i++) {
		if (b[i+1] >= b[i]) {
			ans += b[i];
			a[i+1] = b[i];
		}
		else {
			ans += b[i+1];
			a[i+1] = b[i+1];
		}
	}
	cout << ans + b[n-2] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int n;
string s;

int main(){
  std::cin >> n;
  if(n==0)s="0";
  while(n){
    if(n%-2 != 0){
      s = "1"+s;
      n--;
    }
    else s="0"+s;
    n /= -2;
  }
  std::cout << s << '\n';
  // reverse(s, s+keta);
  // std::cout << s << '\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
    
    static class Task {
    	public void solve(int TestNumber, InputReader in, PrintWriter out) {
    		int a = in.nextInt();
    		int b = in.nextInt();
    		if(a <= 0  && b >= 0) {
    			out.println("Zero");
    		}
    		else if(a > 0 || (b - a + 1)%2 == 0) {
    			out.println("Positive");
    		}
    		else {
    			out.println("Negative");
    		}
    	}
    }
    
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}


Measured memory_bytes: 8276
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> E;
typedef long long LL;
LL mat[100][100];
LL ans;
int n, m;
void dfs(vector<int> &v) {
	if (v.size() > 1) {
		LL tmp = 0;
		for (int i : v) {
			LL m = 1 << 30;
			for (int j : v) {
				if (i == j) continue;
				m = min(m, mat[i][j]);
			}
			tmp += m;
		}
		ans = max(ans, tmp);
	}
	for (int i = v.back() + 1; i < n; i++) {
		bool ok = 1;
		for (int j : v) {
			if (!mat[i][j]) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			v.push_back(i);
			dfs(v);
			v.pop_back();
		}
	}
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v, f;
		cin >> u >> v >> f;
		u--; v--;
		mat[u][v] = mat[v][u] = f;
	}
	for (int i = 0; i < n; i++) {
		vector<int> v(1, i);
		dfs(v);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3236
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    string s;
    cin >> s;


    //本文
    if(s =="A") cout << "T";
    else if(s=="T") cout << "A";
    else if(s=="G") cout << "C";
    else cout << "G"; 
    //出力
    //cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3616
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string s1,s2,s3; cin >> s1 >> s2 >> s3;
    int a,b,c;
    a = s1.size();
    b = s2.size();
    c = s3.size();
    int i=0,j=0,k=0;
    char t = 'a';
    while(1){
        if(t=='a'){
            if(i==a){
                cout << 'A' << endl;
                return 0;
            }
            t = s1[i];
            i++;
        }else if(t=='b'){
            if(j==b){
                cout << 'B' << endl;
                return 0;
            }
            t = s2[j];
            j++;
        }else if(t=='c'){
            if(k==c){
                cout << 'C' << endl;
                return 0;
            }
            t = s3[k];
            k++;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int ai = (int)a;
        

        StringBuilder sb = new StringBuilder();

        if(a >= b){
            for(int i = 0; i < a; i++){
                sb.append(b);
            }
        } else {
            for(int i = 0; i < b; i++){
                sb.append(a);
            }
        }

        System.out.println(sb);
    }
}

Measured memory_bytes: 23764
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size

    def add(self, i, w):
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res


n = I()
X = []
Y = []
XY = []
for x, y in LIR(n):
    Y += [y]
    X += [x]

co_to_ind = {e: i for i, e in enumerate(sorted(Y))}
Y = [co_to_ind[k] for k in Y]
Y = [Y[i] for i in sorted(range(n), key=lambda j:X[j])]
pow2 = [1]
for i in range(n):
    pow2 += [pow2[-1] * 2 % mod]


ans = pow2[n - 1] * n % mod
bit = BIT(n)
for i, y in enumerate(Y):
    bit.add(y, 1)
    ld = bit.sum(y - 1)
    lu = i - ld
    rd = y - ld
    ru = n - y - 1 - lu
    ans = ans + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * pow2[lu] % mod * pow2[rd] % mod + (pow2[lu] - 1) * \
          (pow2[rd] - 1) % mod * pow2[ld] % mod * pow2[ru] % mod - (pow2[ld] - 1) * (pow2[ru] - 1) % mod * \
          (pow2[rd] - 1) % mod * (pow2[lu] - 1) % mod


print(ans % mod)






Measured memory_bytes: 120460
function solve(n, nums) {
    var sum = 0, max = 0;
    nums.forEach(function (n) {
        if (max < n) {
            max = n;
        }
        sum += n;
    });
    if (max < sum - max) {
        return 'Yes';
    }
    return 'No';
}

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

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define popb pop_back()
#define lb lower_bound
#define mp make_pair
#define le length()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
typedef unordered_map<ll,ll> ull;
typedef unordered_map<ll,int> uli;
typedef unordered_map<int,int> uii;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0,lim-1);
  return uid(rang);
}
ll mpow(ll base, ll exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);
 
const int mod = 1000000009;
const int N = 3e5, M = N;
//=======================
 
vi g[N];
int a[N];
vector<ll> f(500069,1);
void compute_factorial(){
  for(int i =2;i<500068;i++){
    f[i] = (i*f[i-1])%mod;
  }
}

void rec(string a, vector<char> b,vector<bool> added,unordered_set<string>& m ,vector<string>& ans){
  //cout<<b.size()<<'\n';
  if(b.size() == a.length()){
    string ss;
    for(auto it:b)ss+=it;
    if(m.find(ss) == m.end())ans.pb(ss),m.insert(ss);
  }
  for(int i =0;i<a.le;i++){
    if(!added[i]){
      b.pb(a[i]);
      added[i]  = true;
      rec(a,b,added, m,ans);
      b.popb;
      added[i] = false;
    }
  }
}

ll gcd(ll a, ll b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
}



void solve(){
  string s;
  cin>>s;
  ll ans = 0;
  for(int i =s.le-1;i>=0;i--){
    int d = s[i] - '0';
    ans+=d;
  }
  if(ans%9==0){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }

  


 
 }
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
    #endif
          int t;
          t = 1;
          //cin>>t;
          int tt = t;
   while(t--)solve();
 
    return 0;
}
 


Measured memory_bytes: 14564
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int x1,y1,x2,y2;
	cin >> x1 >>y1 >> x2 >> y2;
	int dx,dy;
	dx = x2 - x1;
	dy = y2 - y1;
	cout << x2 - dy << ' ' << y2 + dx << ' ' <<  x1 - dy << ' ' << y1 + dx <<endl;; 
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

int ans = inf;
int n, A, B, C;
vector<int> s;
void solve(int k, int a, int b, int c, int w)
{
    if(k == n+1){
        if(a == 0 || b == 0 || c == 0)
            return ;
        ans = min(abs(a-A)+abs(b-B)+abs(c-C)+w-30,ans);
        return  ;
    }
    solve(k+1, a, b, c, w);
    solve(k+1, a+s[k], b, c, w+10);
    solve(k+1, a, b+s[k], c, w+10);
    solve(k+1, a, b, c+s[k], w+10);
}
int main()
{
    cin >> n >> A >> B >> C ;
    rep(i, 0, n){
        int t;
        cin >> t;
        s.push_back(t);
    }
    solve(0, 0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

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

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int maxn = 1e6 + 10;
int a[maxn];
int main(){
    IOS;
    int n;
    cin >> n;
    n *= 3;
    for(int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    ll sum = 0;
    for(int i=0; i*3<n; i++){
        sum += a[n - 2*(i + 1)];
        //cout << ":P" << a[n - 2*(i + 1)];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
   int X,Y;
   scanf("%d %d",&X,&Y);
   int i;
   for(i=0;i<=X;i++){

    int a = i * 2 + (X - i) * 4;
    if (a == Y) {
     
printf("Yes");
break;
    }
}
   if(i>X){
printf("No");
   }
   return 0;
}

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

int main() {
	int N, NQ;
  	std::cin >> N;
  	std::cin >> NQ;
  	std::string str;
  	std::cin >> str;
  
  
	std::vector<int> cnts(str.size(), 0);
  	for (size_t i = 1; i < str.size(); ++i) {
  		if (str[i] == 'C' && str[i - 1] == 'A') {
          	cnts[i] = cnts[i - 1] + 1;
        } else {
        	cnts[i] = cnts[i - 1];
        }
    }
  
  	for (int i = 0; i < NQ; ++i) {
    	int s = 0;
      	int e = 0;
      	std::cin >> s;
      	std::cin >> e;
      
        std::cout << cnts[e - 1] - cnts[s - 1]  << std::endl;
    }
	return 0;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int,input().split()))
 
dp = [[0]*2 for _ in range(n+1)]
dp[1] = [0,a[0]]
dp[2] = [0,max(a[0],a[1])]
for i in range(3,n+1):
    if i%2 == 0:
        dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i-1])
        dp[i][1] = max(dp[i-1][1],dp[i-2][1]+a[i-1])
    else:
        dp[i][0] = max(dp[i-1][1],dp[i-2][0]+a[i-1])
        dp[i][1] = dp[i-2][1]+a[i-1]
        
if n%2 == 0:
    print(dp[n][1])
else:
    print(dp[n][0])

Measured memory_bytes: 54108
#include<iostream>

int main(void)
{
  int n = 0;
  std::cin >> n;
  int k = 0;
  std::cin >> k;
  int height = 0;
  int number = 0;
  for(int count = 0; n > count; ++count)
  {
    std::cin >> height;
    if(k <= height)
    {
      number += 1;
    }
  }
  std::cout << number;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <math.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const int inf = 1000000000;
const double eps = 1e-7;

void solve() {
	string s;
	cin >> s;
	int n = s.size(), k = s.size() / 2;
	
	bool ans = true;
	for (int i = 0; i < n / 2; ++i)
		ans &= (s[i] == s[n - 1 - i]);
	for (int i = 0; i < k / 2; ++i)
		ans &= (s[i] == s[k - 1 - i]);
	
	cout << (ans ? "Yes" : "No") << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; ++i)
		solve();
	return 0;
}

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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

const int N = 270000, djq = 1e9 + 7;

int h, n, p[N], f[N], inv[N], a[N], ai[N], ans;

void init(int p)
{
	if (p >= n) return;
	a[p] = 1ll * a[p >> 1] * p % djq;
	ai[p] = 1ll * ai[p >> 1] * inv[p] % djq;
	init(p << 1); init(p << 1 | 1);
}

void jjd(int u, int w)
{
	if (u >= (1 << h - 1))
	{
		for (int v = p[u]; v; v >>= 1) f[v] = (1ll * w * a[p[u]]
			% djq * a[u] + f[v]) % djq;
		return;
	}
	jjd(u << 1, w); jjd(u << 1 | 1, w);
}

void jdj(int u, int w)
{
	if (u >= (1 << h - 1))
	{
		for (int v = p[u]; v > 1; v >>= 1)
			ans = (1ll * (f[v >> 1] - f[v] + djq) * ai[v >> 2] % djq * ai[v >> 1]
				% djq * a[p[u]] % djq * w % djq * a[u] + ans) % djq;
		return;
	}
	jdj(u << 1, w); jdj(u << 1 | 1, w);
}

void djj(int u)
{
	if (u >= (1 << h - 1))
	{
		for (int v = p[u]; v; v >>= 1) f[v] = 0;
		return;
	}
	djj(u << 1); djj(u << 1 | 1);
}

int main()
{
	read(h); n = 1 << h; inv[1] = a[0] = ai[0] = 1;
	for (int i = 2; i < n; i++) inv[i] = 1ll * (djq - djq / i) * inv[djq % i] % djq;
	for (int i = 1 << h - 1; i < n; i++) read(p[i]), p[i] += 1 << h - 1, p[i]--;
	init(1);
	for (int i = 1; i < (1 << h - 1); i++)
		jjd(i << 1, ai[i >> 1]), jdj(i << 1 | 1, ai[i]), djj(i << 1);
	return std::cout << ans << std::endl, 0;
}

Measured memory_bytes: 8164
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
struct gdata {
    int to; long long len;
};
struct ansdata {
    int from; int odd;
};

vector< vector<gdata> > graph(100100, vector<gdata>());
vector<int> ans(100100, -1);

int main() {
    cin >> n;
    for(int i = 0; i < n-1; ++i) {
        int u, v; long long w;
        cin >> u >> v >> w;
        u--; v--;
        gdata indata;
        indata.to = v; indata.len = w;
        graph.at(u).emplace_back(indata);
        indata.to = u;
        graph.at(v).emplace_back(indata);
    }

    queue<ansdata> que;
    ansdata first;
    first.from = 0; first.odd = 0;
    ans.at(0) = 0;
    que.push(first);

    while(!que.empty()) {
        ansdata now = que.front();
        que.pop();
        for(int i = 0; i < graph.at(now.from).size(); ++i) {
            int nfrom = graph.at(now.from).at(i).to;
            if(ans.at(nfrom) == -1) {
                long long nlen = graph.at(now.from).at(i).len;
                // cout << "nlen " << nlen << " ";
                int nodd = 0;
                if(now.odd == 0) {
                    if(nlen % 2 == 0) ans.at(nfrom) = 0;
                    else { 
                        ans.at(nfrom) = 1;
                        nodd = 1;
                    }
                }else {
                    if(nlen % 2 == 0) { 
                        ans.at(nfrom) = 1;
                        nodd = 1;
                    }else ans.at(nfrom) = 0;
                }
                // cout << "n " << nfrom << " " << nodd << endl;
                ansdata next;
                next.from = nfrom; next.odd = nodd;
                que.push(next);
            }
        }
    }

    for(int i = 0; i < n; ++i) {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 8320
<?php
fscanf(STDIN, "%d %d", $a,$b);
function gcd($a, $b) {
   while ($a % $b != 0) {
   $temp = $b;
   $b = $a % $b;
   $a = $temp;
   }
   return $b;
   }
   
   //最小公倍数を求める
   function lcm($a, $b) {
   return $a * $b / gcd($a, $b); 
   }
   echo lcm($a, $b);
?>

Measured memory_bytes: 4856
import java.math.BigInteger;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
	// TODO 自動生成されたメソッド・スタブ
	Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	int m=sc.nextInt();
	long mH=m/2;
	long nH=n/2;
	long mH1=(m+1)/2;
	long nH1=(n+1)/2;
	if(n == 1 || m == 1) {
		System.out.println(1);
		return;
	}
		System.out.println(mH*nH+mH1*nH1);
	}
}

Measured memory_bytes: 21844
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
# n=int(input())
# a=readints()
n = int(input())
t = []
for _ in range(n):
    t.append(int(input()))
# print(t)
ans = t[0]
for i in range(1, n):
    ans = ans * t[i] // fractions.gcd(ans, t[i])
print(ans)


Measured memory_bytes: 60268
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<int> a(m);
	int tot = 0;
	for (auto &i : a) {
		cin >> i;
		tot += i;
	}
	if (tot > n) cout << -1;
	else cout << n-tot;

}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k,a,b,c,d,s,ct;
    cin>>a>>b>>c;
    s=(a+b+c)/2;
    n=sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<n<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <queue>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x  = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, x, y, z, s[N], a[N], b[N];
int64 ans = 0xcfcfcfcfcfcfcfcf, sum, f[N], g[N];
bool cmp(int i, int j) { return a[i]-b[i] > a[j]-b[j]; }
priority_queue<int> h;
int main()
{
    x = read(), y = read(), z = read(), n = x+y+z;
    for(int i = 1, c = 0; i <= n; ++i) 
        a[i] = read(), b[i] = read(), c = read(), 
        a[i] -= c, b[i] -= c, sum += c, s[i] = i;
    sort(s+1, s+1+n, cmp);
    for(int i = 1; i <= n; ++i)
    {
        f[i] = f[i-1]+a[s[i]], h.push(-a[s[i]]);
        if(h.size() > x) f[i] += h.top(), h.pop();
    }
    while(h.size()) h.pop();
    for(int i = n; i; --i)
    {
        g[i] = g[i+1]+b[s[i]], h.push(-b[s[i]]);
        if(h.size() > y) g[i] += h.top(), h.pop();
    }
    for(int i = x; i+y <= n; ++i) ans = max(ans, f[i]+g[i+1]);
    printf("%lld\n", ans+sum);
    return 0;
}

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

template <typename T>
class imos2 {
	int n, m;
	vector<vector<T>> v;
public:
	imos2(int n, int m) : n(n), m(m), v(n + 1, vector<T>(m + 1)) {}
	T& val(int i, int j) { assert(0 <= i && i < n && 0 <= j && j < m); return v[i + 1][j + 1]; }
	void add(int li, int lj, int ri, int rj, T x) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		val(li, lj) += x;
		if (ri < n) val(ri, lj) -= x;
		if (rj < m) val(li, rj) -= x;
		if (ri < n && rj < m) val(ri, rj) += x;
	}
	void build() {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) v[i][j] += v[i - 1][j];
		for (int i = 0; i <= n; i++) for (int j = 1; j <= m; j++) v[i][j] += v[i][j - 1];
	}
	T sum(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		return v[ri][rj] - v[ri][lj] - v[li][rj] + v[li][lj];
	}
};

int main()
{
	int N, K;
	cin >> N >> K;
	imos2<int> wcnt(K * 4, K * 4), bcnt(K * 4, K * 4);
	for (int i = 0; i < N; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		x %= K * 2;
		y %= K * 2;
		if (c == 'W') {
			wcnt.val(x, y) += 1;
			wcnt.val(K * 2 + x, y) += 1;
			wcnt.val(x, K * 2 + y) += 1;
			wcnt.val(K * 2 + x, K * 2 + y) += 1;
		}
		else {
			bcnt.val(x, y) += 1;
			bcnt.val(K * 2 + x, y) += 1;
			bcnt.val(x, K * 2 + y) += 1;
			bcnt.val(K * 2 + x, K * 2 + y) += 1;
		}
	}
	wcnt.build();
	bcnt.build();
	int res = 0;
	for (int i = 0; i < K * 2; i++) {
		for (int j = 0; j < K * 2; j++) {
			int val = wcnt.sum(i, j, i + K, j + K)
				+ bcnt.sum(i + K, j, i + K * 2, j + K)
				+ wcnt.sum(i + K, j + K, i + K * 2, j + K * 2)
				+ bcnt.sum(i, j + K, i + K, j + K * 2);
			res = max(res, val);
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for(int i = 1;i < n;i++) {
    if(a.at(i-1) == a.at(i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024