akhauriyash/Code-Regression huggingface dataset:
import sys
A=[]

for i in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
b=[]
for _ in range(N):
    b.append(int(input()))

ans=[[0,0,0] for i in range(3)]


for n,a in enumerate(A):
    for i in b:
        if(a[0]==i):
            ans[n][0]=1
        if(a[1]==i):
            ans[n][1]=1
        if(a[2]==i):
            ans[n][2]=1

ans1=ans[0]
ans2=ans[1]
ans3=ans[2]

for a in ans:
    if(a[0]==1 and a[1]==1 and a[2]==1):
        print('Yes')
        sys.exit()

for i in range(3):
    if(ans1[i]==1 and ans2[i]==1 and ans3[i]==1):
        print('Yes')
        sys.exit()

if(ans1[0]==1 and ans2[1]==1 and ans3[2]==1):
    print('Yes')
    sys.exit()
if(ans1[2]==1 and ans2[1]==1 and ans3[0]==1):
    print('Yes')
    sys.exit()

print('No')




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

using namespace std;

int N, a[2][109], dp[2][109];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=2; i++)
    for (int j=1; j<=N; j++)
        scanf ("%d", &a[i][j]);
dp[1][1] = a[1][1], dp[2][1] = a[1][1] + a[2][1];
for (int i=1; i<=2; i++)
    for (int j=2; j<=N; j++)
    {
        dp[i][j] = dp[i][j - 1] + a[i][j];
        if (i == 2) dp[i][j] = max (dp[i][j], dp[i - 1][j] + a[i][j]);
    }
printf ("%d\n", dp[2][N]);
return 0;
}


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

signed main(void)
{
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::marker::*;
use proconio::{fastout, input};
use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        road: [(Usize1, Usize1); m],
    }

    let res = solve(n, &road);
    println!("{}", res);
}

fn solve(n: usize, road: &[(usize, usize)]) -> usize {
    let mut uni = UnionFind::new(n);
    for (a, b) in road {
        uni.unite(*a, *b);
    }

    let mut set = HashSet::with_capacity(n);
    for i in 0..n {
        set.insert(uni.root(i));
    }
    let c = set.len();
    if c == 0 {
        0
    } else {
        c - 1
    }
}

struct UnionFind {
    ar: Vec<isize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind { ar: vec![-1; n] }
    }

    fn root(&mut self, x: usize) -> usize {
        if self.ar[x] < 0 {
            return x;
        }
        let root = self.root(self.ar[x] as usize);
        self.ar[x] = root as isize;
        root
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x != y {
            self.ar[x] += self.ar[y];
            self.ar[y] = x as isize;
        }
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.root(x);
        -self.ar[root] as usize
    }
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    int ans = 1000;
    for (char c = 'a'; c <= 'z'; c++) {
        int cnt = 0;
        int now = 0;
        bool flag = false;
        rep(i, n) {
            if (s[i] == c) {
                flag = true;
                chmax(now, cnt);
                cnt = 0;
            } else {
                cnt++;
            }
        }
        chmax(now, cnt);
        if (flag) chmin(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	var T, A int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &T)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &A)

	var hs = make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &hs[i])
	}

	ans := -1
	m := math.MaxFloat64
	for i, h := range hs {
		t := float64(T) - float64(h)*0.006
		diff := math.Abs(t - float64(A))
		if diff < m {
			m = diff
			ans = i + 1
		}
	}
	fmt.Println(ans)
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> height(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> height.at(i);
  }
  vector<int> good(N);

  for(int i = 0 ; i < M ; i++){
    int A,B;
  	A = 0;
  	B = 0;
  	cin >> A >> B;
    A -= 1;
    B -= 1;
  	if(height.at(A) < height.at(B)){
  		good.at(A) = 1;
  	}
    else if(height.at(A) == height.at(B)){
    	good.at(A) = 1;
      	good.at(B) = 1;
    }
    else{
    	good.at(B) = 1;
    }
  }
  int count = 0;
  for(int i = 0 ; i < N ; i++){
  	if(good.at(i) == 0){
    	count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3952
//////////////////////////////////*STRIKER(Devesh Ranjan)*////////////////////////////////////////////////////////////////////

#include<bits/stdc++.h>

using namespace std;
using ull=unsigned long long;
using ll=long long int;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 10000007
#define mod1 1000003
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fr1(i,a,b) for(ll i=a;i<=b;i++)

/*BINARY EXPONENTIATION*/

ll binpow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve()
{
    //Start Here:
    ll n,k;
    cin>>n>>k;
    ll ar[n+1];
    fr(i,0,n)
    {
        cin>>ar[i];
    }
    if(k>=n)
    {
        cout<<abs(ar[n-1]-ar[0])<<endl;
        return;
    }
    ll dp[n+1];
    dp[0]=0;
    fr(i,1,k)
    {
        dp[i]=abs(ar[i]-ar[0]);
    }
    fr(i,k,n)
    {
        ll minn=LLONG_MAX;
        fr(j,i-k,i)
        {
            ll val=dp[j]+abs(ar[i]-ar[j]);
            if(val<minn)
            {
                minn=val;
            }
        }
        dp[i]=minn;
    }
    cout<<dp[n-1]<<endl;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    fastio;
    solve();
}

Measured memory_bytes: 1792
/* Author: Dhruv Rastogi */
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	string s;
	cin>>s;
	int k;
	cin>>k;
	int eq=1;
	rep(i,1,sz(s)){
		if(s[i]!=s[i-1]) eq=0;
	}
	if(eq){
		cout<<(sz(s)*k)/2<<endl;
	}
	else{
		int rl=0;
		vll rlmid,rlwhole;
		int n=sz(s);
		s+=s;
		rep(i,0,sz(s)){
			if(i==0 or s[i]!=s[i-1]){
				if(i==0);
				else if(i-rl<n and i-1>=n){
					rlmid.pb(rl);
				}
				else rlwhole.pb(rl);
				rl=1;
			}	
			else{
				++rl;
			}
		}
		rlwhole.pb(rl);
		int ans=0;
		if(sz(rlmid)==0){
			for(int i:rlwhole){
				ans+=i/2;
			}
			ans/=2;
			ans*=k;
		}
		else{
			rep(i,1,sz(rlwhole)-1){
				ans+=rlwhole[i]/2;
			}
			ans/=2;
			ans*=k;
			ans+=rlwhole[0]/2;
			ans+=rlwhole.back()/2;
			ans+=(rlmid[0]/2)*(k-1);
		}
		cout<<ans<<endl;
	}
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

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

    int N = min(A, B);
    vector<int> D;
    repi(i, 1, N + 1) {
        if(A % i == 0 && B % i == 0) {
            D.push_back(i);
        }
    }

    reverse(all(D));

    cout << D.at(K - 1) << endl;
}

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

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 1e3 + 15;
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1);
const double E = 2.718281828459045;
const int BLOCK = 2000;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod(x, m) ((x) % m + (x < 0 ? m: 0))

inline void IO() {
#ifdef buyolitsez
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}


template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}


inline void solve() {
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    cin >> a;
    double sum = 0;
    for (auto u : a) {
        sum += u;
    }
    sum /= (4.0 * m);
    int c = 0;
    for (auto u : a) {
        if (u >= sum) {
            c++;
        }
    }
    if (c >= m) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

signed main() {
    IO();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unordered_set<int> uset;

int main( int argc, char* argv[] ){
  ll N;
  cin >> N;
  vector<ll> A(N,0);
  cin >> A[0];
  if( A[0] != 0 ){
    cout << -1 << endl;
    return 0;
  }    
  ll prev = 0;
  ll count = 0;
  for( ll i=1; i<N; ++i ){
    cin >> A[i];
    if( A[i] > i || A[i] > prev+1 ){
      cout << -1 << endl;
      return 0;
    }
    if( A[i] == prev+1 ){
      count++;
    } else {
      count += A[i];
    } 
    prev = A[i];
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1792
s = input()
f = False
l = False
for i in range(len(s)):
    if s[i] == 'C':
        for j in range(i, len(s)):
            if s[j] == 'F':
                print('Yes')
                f = True
                l = True
                break
        if f == False:
            print('No')
            l = True
            break
        else:
            l = True
            break
if l == False:
    print('No')


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

int main(){
    int a,b,c,n,r;

    while(cin>>a>>b>>c,a||b||c){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>r;
            if(min({a*a+b*b,a*a+c*c,b*b+c*c})<4*r*r){
                cout<<"OK"<<endl;
            }else{
                cout<<"NA"<<endl;
            }
        }
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), ans(n, 0);
    rep(i, m) cin >> a[i] >> b[i];

    rep(i, m)
    {
        ans[a[i] - 1]++;
        ans[b[i] - 1]++;
    }

    rep(i, n) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int n;
int f(int a,int b){
	if(a==b)return a;
	if(a<b)return f(b,a);
	if(n==1)return b;
	return f((a+n-2)/n,b);
}
int main(){
	int m,a,b;
	scanf("%d %d",&n,&m);
	while(m--){
		scanf("%d %d",&a,&b);
		printf("%d\n",f(a,b));
	}
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
        int l = -1;
        int r = -1;
        var d = Enumerable.Repeat(-1, N + 1).ToArray();
        for (int i = 0; i < N+1; i++)
        {
            int b = a[i];
            if (d[b] == -1) d[b] = i;
            else
            {
                l = d[b];
                r = i;
                break;
            }
        }
        for (int i = 0; i < N+1; i++)
        {
            Modular ans = Modular.Ncr(N + 1, i + 1) - Modular.Ncr(l + N - r, i);
            WriteLine((int)ans);
        }
    }
}
class Modular
{
    private const int M = 1000000007;
    private long value;
    public Modular(long value) { this.value = value; }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    {
        return a.value + b.value;
    }
    public static Modular operator -(Modular a, Modular b)
    {
        return a.value - b.value;
    }
    public static Modular operator *(Modular a, Modular b)
    {
        return a.value * b.value;
    }
    public static Modular Pow(Modular a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static readonly List<int> facs = new List<int> { 1 };
    private static Modular Fac(int n)
    {
        for (int i = facs.Count; i <= n; ++i)
        {
            facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
        }
        return facs[n];
    }
    public static Modular Ncr(int n, int r)
    {
        return (n < r) ? 0
             : (n == r) ? 1
                        : Fac(n) / (Fac(r) * Fac(n - r));
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}


Measured memory_bytes: 50624
n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
    liars = [0]*n
    check = 1
    for i in range(n):
        if (bit>>i)&1:
            liars[-1-i] = 1
    for i in range(n):
        if not liars[i]:
            continue
        for l in tst[i]:
            if l[1]!=liars[l[0]-1]:
                check = 0
                break
    if check:
        ans = max(ans,sum(liars))
print(ans)

Measured memory_bytes: 9172
N, K = map(int, input().split())
A = {}
for i in range(K):
  d = int(input())
  Ak = list(input().split())
  for j in Ak:
    A[j] = 1

count = 0
for n in range(N):
  if str(n+1) not in A:
    count += 1
print(count)

Measured memory_bytes: 9192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
using namespace std;

int main()
{
    int A, H, attack;
    cin >> A >> H;
    if(A % H == 0) attack = A / H;
    else attack = A / H + 1;
    cout << attack << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll inf=1e18;

int N;
int main(){
    while(cin>>N){
        if(N<1000) p("ABC");
        else p("ABD");

        return 0;
    }

}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int X, Y, Z;

	cin >> X >> Y >> Z;

	cout << Z << " " << X << " " << Y;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
BA = [(b, a) for (b, a) in zip(B, A)]
BA.sort()
B, A = list(map(list, zip(*BA)))  # BA.T
AI = [(a, i) for (i, a) in enumerate(A)]
AI.sort()
C, P = list(map(list, zip(*AI)))  # AI.T

def can_divide_cycle(P):
    start = P[1]
    ncycle = 1
    cur = start
    while P[cur] != start:
        cur = P[cur]
        ncycle += 1
    return ncycle < len(P)

vld = all(c <= b for (c, b) in zip(C, B)) \
    and (can_divide_cycle(P) or any(c <= b for (c, b) in zip(C[1:], B[:-1])))
print('Yes' if vld else 'No')


Measured memory_bytes: 38440
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int w = arr[0];
    int h = arr[1];
    int n = arr[2];
    int L = 0;
    int r = w;
    int b = 0;
    int t = h;
    while (n-- > 0) {
      arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
      int x = arr[0];
      int y = arr[1];
      int a = arr[2];
      switch (a) {
        case 1:
          if (L < x) L = x;
          break;
        case 2:
          if (r > x) r = x;
          break;
        case 3:
          if (b < y) b = y;
          break;
        case 4:
          if (t > y) t = y;
          break;
      }
    }
    Console.WriteLine((L < r && b < t) ? (r - L) * (t - b) : 0);
  }
}

Measured memory_bytes: 13268
/*
[keyence2019] B - KEYENCE String
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

string S;

bool solve() {
    int N = S.length();
    for (int l = 0; l <= N; l++) {
        for (int r = l; r <= N; r++) {
            if (S.substr(0, l) + S.substr(r, N - r) == "keyence") {
                return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> S;

    cout << (solve() ? "YES" : "NO") << endl;

    return 0;
}


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

int a[100000];
bool used[100000];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]), a[i]--;
	int cnt = 0, p = 0;
	while (p != 1) {
		if (used[p]) {
			puts("-1"); return 0;
		}
		used[p] = 1;
		cnt++; p = a[p];
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll


signed main() {
	fast;
	
	ll n;
	cin>>n;
	std::vector<pii > v(n);
	for(int i=0;i<n;i++) cin>>v[i].f>>v[i].s;

	sort(all(v));

	ll ans=n;

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ll x1 = v[j].f-v[i].f;
			ll y1 = v[j].s-v[i].s;
			map<pii,ll> mp1;
			ll cost=0;
			for(int k=0;k<n;k++){
				if(mp1.find(mp(v[k].f-x1,v[k].s-y1))==mp1.end()) cost++;
				mp1[v[k]]=1;
			}
			ans=min(ans,cost);
		}
	}

	reverse(all(v));

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ll x1 = v[j].f-v[i].f;
			ll y1 = v[j].s-v[i].s;

			map<pii,ll> mp1;
			ll cost=0;
			for(int k=0;k<n;k++){
				if(mp1.find(mp(v[k].f-x1,v[k].s-y1))==mp1.end()) cost++;
				mp1[v[k]]=1;
			}
			ans=min(ans,cost);
		}
	}

	cout<<ans;
} 

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	int sum = 0, sum1 = 0;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	reverse(all(a));
	rep(i, n){
		if(i % 2 == 0) sum += a[i];
		else sum1 += a[i];
	}
	cout << sum - sum1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))

const int M = 1500;
ll h[M+5], w[M+5];

void solve(int H, int W) {
    ZERO(h); ZERO(w);
    FOR(i,1,H+1) scanf("%lld", &h[i]);
    FOR(i,1,W+1) scanf("%lld", &w[i]);

    rep(i,H) h[i+1] += h[i];
    rep(i,W) w[i+1] += w[i];

    map<ll,ll> nums;
    FOR(i,1,W+1) rep(j,i) nums[w[i]-w[j]]++;

    ll ans = 0;
    FOR(i,1,H+1) {
        rep(j,i) {
            ll height = h[i] - h[j];
            ans += nums[height];
        }
    }

    cout << ans << endl;
}

int main() {
    int H, W;
    while(cin>>H>>W, H) solve(H,W);
    return 0;
}

Measured memory_bytes: 26912
// AOJ Volume 0 Problem 0055

#include <stdio.h>

int main(void)
{
    double term;
    double sum;
    int i;

    while (scanf("%lf", &term) != EOF){
        sum = term;
        for (i = 1; i < 10; i++){
            if (i % 2 == 1){
                term = term * 2;
            }
            else {
                term = term / 3;
            }
//            printf("<%lf>", term);
            sum += term;
        }
    
        printf("%lf\n", sum);
    }

    return (0);
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
	
	int a,b;
	
	scanf("%d %d",&a ,&b);
	
	if(a>b)
	{
		printf("a > b\n");
	}
	else if (a<b)
	{
		printf("a < b\n");
	}
	else
	{ printf("a == b\n");
	}
	
}



Measured memory_bytes: 2692
import heapq
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

h = []
heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0)))

ans = []
for _ in range(K):
    p, v = heapq.heappop(h)
    i, j, k = v
    ans.append(p)
    if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in h:
        heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k)))
    if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in h:
        heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k)))
    if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in h:
        heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1)))

for a in ans:
    print(-a)

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N,A,B;
   cin>>N;
   if(N==1){
       cout<<"Hello World"<<endl;
   }
   else{
       cin>>A>>B;
       cout<<A+B<<endl;
   }
}

Measured memory_bytes: 3556
import java.io.*;

public class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][][] dormitory = new int[4][3][10]; //??????????????????
		int b,f,r,v;
		
		//?±?????????°?????¨????????????????¨????
		for(int i=0; i<n; i++){
			String[] str = br.readLine().split(" ");
			b = Integer.parseInt(str[0])-1;
			f = Integer.parseInt(str[1])-1;
			r = Integer.parseInt(str[2])-1;
			v = Integer.parseInt(str[3]);
			
			dormitory[b][f][r] += v; //v????????????????????????????????§???????????????
		}
		
		//?????????????±?????????°?????¨???
		for(int i=0; i<4; i++){
			for(int j=0; j<3; j++){
				for(int k=0; k<10; k++){
					System.out.print(" "+dormitory[i][j][k]);
				}
				System.out.println();
			}
			if(i!=3){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 19320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // 一番多いもの、reverseした後一番多いものをずらす、あとはずらすのは一箇所のみ
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> B(N);
    rep(i, N) cin >> B[i];
    vector<int> Acnt(N+1);
    vector<int> Bcnt(N+1);
    rep(i, N) {
        if (Acnt[A[i]] == 0) {
            int x = upper_bound(A.begin(), A.end(), A[i]) - lower_bound(A.begin(), A.end(), A[i]);
            Acnt[A[i]] = x;
        }
        if (Bcnt[B[i]] == 0) {
            int y = upper_bound(B.begin(), B.end(), B[i]) - lower_bound(B.begin(), B.end(), B[i]);
            Bcnt[B[i]] = y;
        }
    }
    int ma = 0;
    int max_cnt = 0;
    bool flag = false;
    for (int i = 1; i <= N; i++) {
        if (Acnt[i] > 0 && Bcnt[i] > 0) flag = true;
        int x = Acnt[i] + Bcnt[i];
        if (x > N) {
            puts("No");
            return 0;
        }
        if (x > max_cnt) {
            max_cnt = x;
            ma = i;
        }
    }
    if (!flag) {
        puts("Yes");
        show(B);
        return 0;
    }
    int A_left = lower_bound(A.begin(), A.end(), ma) - A.begin();
    int A_right = upper_bound(A.begin(), A.end(), ma) - A.begin() - 1;
    reverse(B.begin(), B.end());
    int B_right = (N-1) - (lower_bound(B.rbegin(), B.rend(), ma) - B.rbegin());
    int B_left = (N-1) - (upper_bound(B.rbegin(), B.rend(), ma) - B.rbegin() - 1);
    vector<int> ans(N);
    int cur = (A_right + 1) % N;
    int b = B_left;
    rep(i, N) {
        ans[cur] = B[b];
        cur = (cur+1)%N;
        b = (b+1)%N;
    }
    rep(i, N) {
        if (A[i] == ans[i]) {
            while (ans[i] == ans[A_left]) A_left++;
            swap(ans[i], ans[A_left]);
            A_left++;
        }
    }
    puts("Yes");
    show(ans);
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}


Measured memory_bytes: 7224
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, K, R, S, P;
	cin >> N >> K >> R >> S >> P;
	string t;
	cin >> t;

	vector<char> v(N, 'X');
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (i - K >= 0 && v[i - K] == t[i]) { continue; }
		
		if (t[i] == 'r') { ans += P; }
		if (t[i] == 's') { ans += R; }
		if (t[i] == 'p') { ans += S; }
		v[i] = t[i];
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  string W, T;
  cin >> W >> T;

  for (int i = 0; i < W.size(); i++) {
    W[i] = tolower(W[i]);
  }
  
  int cnt = 0;
  while (T != "END_OF_TEXT") {
    for (int i = 0; i < T.size(); i++) {
      T[i] = tolower(T[i]);
    }
    if (T == W) cnt++;
    cin >> T;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3168
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        long c = 0;

        if (M >= 2 * N) {
            c = N;
            M -= 2 * N;
            c += M / 4;
        } else {
            c = M / 2;
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 21716
n=int(input())
l=[0 for i in range(100003)]
for i in range(n):
    a,b=map(int,input().split())
    l[a]+=1
    l[b+1]-=1
su=1
res=1
for i in range(100003):
    su+=l[i]
    if su>=i:
        res=max(i,res)
print(res-1)



Measured memory_bytes: 6504
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
n_bit = 60
bit_cnt = [0]*n_bit
for i in range(n):
    for d in range(n_bit):
        if (A[i] >> d) & 1:
            bit_cnt[d] += 1

ans = 0
for d, one_cnt in enumerate(bit_cnt):
    ans = ans + one_cnt*(n-one_cnt)*pow(2, d, MOD) % MOD
print(ans % MOD)

Measured memory_bytes: 122936
from math import floor
import sys
from copy import copy

from collections import deque
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353




S = input().strip()
D = deque(S)


n = int(input())
reverse = False
for operation in range(n):
    data = input().strip()
    if data[0] == "1":
        if reverse is False:
            reverse = True
        else:
            reverse = False
    else:
        f = data[2]
        ele = data[4]
        if (f == "1" and reverse is False) or (f == "2" and reverse == True):
            D.appendleft(ele)
        else:
            D.append(ele)
#    print(S)
# print(reverse)
if reverse is True:
    D.reverse()
# print(*D,end="")
print("".join(D))


Measured memory_bytes: 70620
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int x;
  cin >> x;
  for(int i = 111; i <= 999; i+= 111){
    if(x <= i){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}


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

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *nil;

void insert(int k){
    Node *y = nil; // xの親
    Node *x = root; // 現在の節点
    Node *z; // 挿入する節点

    // zの初期化
    z = new Node;
    z->key = k;
    z-> left = nil;
    z-> right = nil;

    // xを一番下まで持っていく
    while(x != nil){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }

    z->parent = y;
    if(y == nil) root = z;
    else{
        if(z->key < y->key) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u){
    if(u == nil) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == nil) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int m, x;
    cin >> m;

    for(int i=0; i<m; ++i){
        string com;
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        
    }

    return 0;
}


Measured memory_bytes: 26620
using System;
using System.Linq;

namespace ABC109
{
    class A
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int A = input[0];
            int B = input[1];

            if (A % 2 == 0 || B % 2 == 0) Console.WriteLine("No");
            else Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13268
# B - Coins
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c==X:
                ans += 1
print(ans)

Measured memory_bytes: 67344
#include <bits/stdc++.h>
using namespace std;
int cnt[26], a[4];
char s[1005];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= m; ++ j) {
			cnt[s[j] - 'a'] ++;
		}
	}
	for (int i = 0; i < 26; ++ i) a[cnt[i] % 4] ++;
	if (n % 2 && m % 2) {
		if (a[2] <= n / 2 + m / 2 && a[3] + a[1] == 1) puts("Yes"); else puts("No");
	}
	else if (n % 2 || m % 2) {
		if (n % 2) swap(n, m);
		if (a[1] == 0 && a[3] == 0 && a[2] <= n / 2) puts("Yes"); else puts("No");
	}
	else {
		if (a[1] + a[2] + a[3] == 0) puts("Yes"); else puts("No");
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <complex>
using namespace std;

int main()
{
    long n;
    
    cin  >> n;
    long count=0;
    for(long i=1;i<=sqrt(n)+1;i++){
        if (i*i <=n)count=i*i;
    }

    cout << count;
    
    return 0;
}






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

int main() {
  int A, B;
  cin >> A;
  cin >> B;
  if (A < 1 || A > 9 ||  B < 1 || B > 9){
    cout << "-1" << endl;
  }else{
    cout << A * B << endl;
  }
}



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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  if(A>B) cout << 0 << endl;
  else if(N==1 && A!=B) cout << 0 << endl;
  else cout << (N-2)*(B-A)+1 << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

typedef pair<ll, ll>P;

ll N;
vector<ll>path[1010];
ll lst[1010];
ll cnt[1010];

ll solve(){
    ll N;
    cin >> N;
    for(ll i = 1; i <= N; i++){
        for(ll j = 0; j < N - 1; j++){
            ll a;
            cin >> a;
            path[i].push_back(a);
        }
    }
    queue<P>Q, q;
    for(ll i = 1; i <= N; i++)Q.push(P(i, 0));
    ll day = 0;
    for(;!Q.empty();){
        day++;
        ll flg = 0;
        while(!Q.empty()){
            ll a = Q.front().first;
            ll a_idx = Q.front().second;
            ll b = path[a][a_idx];
            ll b_idx = cnt[b];
            Q.pop();
            if(cnt[a] > a_idx)continue;
            if(path[b][b_idx] != a){
                q.push(P(a, a_idx));
                continue;
            }
            if(lst[a] == day || lst[b] == day){
                q.push(P(a, a_idx));
                continue;
            }
            // cout << day << " : " << a << ", " << b << endl;
            flg = 1;
            lst[a] = day;
            cnt[a]++;
            lst[b] = day;
            cnt[b]++;
            if(a_idx + 1 < N - 1)q.push(P(a, a_idx + 1));
            if(b_idx + 1 < N - 1)q.push(P(b, b_idx + 1));
        }
        if(flg == 0)return -1;
        swap(Q, q);
    }
    return day;
}


ll A[1010][1010];
ll solve2(){
    cin >> N;    
    for(ll i = 1; i <= N; i++){
        for(ll j = 0; j < N - 1; j++){
            scanf("%lld", &A[i][j]);
        }
    }
    ll day = 0;
    for(ll ct = 0; ct < N * (N - 1) / 2;){
        day++;
        ll flg = 0;
        for(ll i = 1; i <= N; i++){
            if(lst[i] == day)continue;
            if(cnt[i] == N - 1)continue;
            ll to = A[i][cnt[i]];
            if(lst[to] == day)continue;
            if(A[to][cnt[to]] != i)continue;
            ct++;
            flg = 1;
            lst[i] = day;
            lst[to] = day;
            cnt[i]++;
            cnt[to]++;
        }
        if(flg == 0)return -1;
    }
    return day;
}

int main(){

    cout << solve2() << endl;

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
//typedef __int128_t lll;
using namespace std;

#define mod 998244353

struct affine{
  ll a=1, b=0;
  affine(ll A, ll B){a=A,b=B;}
};

affine unit(1, 0);
ll ff(ll a, ll b){return (a+b)%mod;}
ll gg(ll a, affine b){return ((a*b.a)%mod+b.b)%mod;}


affine hh(affine a, affine b){
  return affine((a.a*b.a)%mod, ((a.b*b.a)%mod + (b.b)%mod)%mod);
}
//*499122177
affine pp(affine a, ll len){
  return affine(a.a, a.b*len);
}
template <typename T, typename E> // dat lazy
struct segtree{
  vector<T> dat;vector<E> laz;
  typedef function<T(T, T)> F; //dat - datのマージ
  typedef function<T(T, E)> G; //dat - lazyのマージ
  typedef function<E(E, E)> H; //lazy - lazyの更新
  typedef function<E(E, int)> P; //lazy - lenの関数
  int n;F f;G g;H h;P p;
  T dat_unit;
  E lazy_unit;

  segtree(int m,T dat_unit_,E lazy_unit_, F ff,G gg,H hh,P pp=[](E a,int b){return a;}):dat_unit(dat_unit_),lazy_unit(lazy_unit_){
    f = ff, g = gg, h = hh, p = pp;
    init(m);
  }

  void init(int m){
    n = 1;
    while(n<m) n*=2;
    dat.resize(2*n-1, dat_unit);
    laz.resize(2*n-1, lazy_unit);
  }

  inline void eval(int k, int l, int r){
    if(laz[k].a==1&&laz[k].b==0) return;
    if(r-l>1){
      laz[k*2+1]=h(laz[k*2+1], laz[k]);
      laz[k*2+2]=h(laz[k*2+2], laz[k]);
    }
    dat[k]=g(dat[k], p(laz[k], r - l));
    laz[k]=lazy_unit;
  }

  T update(int a, int b, E x, int k, int l, int r){
    eval(k, l, r);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k] = h(laz[k], x);
      return g(dat[k], p(laz[k], r-l));
    }
    T A = update(a,b,x,k*2+1,l,(l+r)/2);
    T B = update(a,b,x,k*2+2,(l+r)/2,r);
    return dat[k] = f(A, B);
  }

  T query(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(r<=a||b<=l) return dat_unit;
    if(a<=l&&r<=b) return dat[k];
    T vl = query(a, b, k*2+1, l, (l+r)/2);
    T vr = query(a, b, k*2+2, (l+r)/2, r);
    return f(vl, vr);
  }

  T update(int a,int b, E x){return update(a,b,x,0,0,n);}
  T query(int a,int b){return query(a,b,0,0,n);}
};


int main(int argc, char const *argv[]) {
  ll n, q;std::cin >> n >> q;

  segtree<ll, affine> seg(n, 0, unit, ff, gg, hh, pp);
  re(i, n){
    ll a;scanf("%lld", &a);
    seg.update(i, i+1, affine(0, a));
  }
  re(i, q){
    ll a, b, c;scanf("%lld %lld %lld", &a, &b, &c);
    if(a) std::cout << seg.query(b, c) << '\n';
    else{
      ll d, e;scanf("%lld %lld", &d, &e);
      seg.update(b, c, affine(d, e));
    }
  }
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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




int main() {
    cout<<fixed<<setprecision(10);

    ll R,C,K; cin>>R>>C>>K;
    vvint V(R, vint(C, 0));
    rep(i,K){
        ll r,c,v;
        cin>>r>>c>>v; r--; c--;
        V[r][c] = v;
    }

    vector<vvint> dp(R+1, vvint(C+1, vint(4, 0)));

    rep(i,R){
        rep(j,C){
            // 拾う
            repr(k,3){
                chmax(dp[i][j][k+1], dp[i][j][k] + V[i][j]);
            }

            // 移動
            // 次の行
            rep(k,4){
                chmax(dp[i+1][j][0], dp[i][j][k]);
            }

            // 次の列
            rep(k,4){
                chmax(dp[i][j+1][k], dp[i][j][k]);
            }
        }
    }

    cout<<*max_element(ALL(dp[R-1][C-1]))<<endl;

    return 0;

}

Measured memory_bytes: 707116
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>

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


int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans;
    ans = (ll)w * h;
    ans = (double)ans / 2;
    int cnt = 0;
    if (w == x * 2 && h == y * 2)cnt = 1;
    printf("%.16f", ans);
    cout << ' ' << cnt << endl;

    return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define res register
#define ms(a,b,c) memset(a,(c),(b)*sizeof(int))
const int INF=0x3f3f3f3f;
const int MAXN=100010;
template<typename T> inline T read(){
	char ch=getchar();T s=0;int f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*f;
}
int distf[MAXN];
int dists[MAXN];
vector<int> g[MAXN];
void dist_f(int id,int par){
	if(par!=0)distf[id]=distf[par]+1;
	for(res int i=0;i<g[id].size();++i)if(g[id][i]!=par)dist_f(g[id][i],id);
}
void dist_s(int id,int par){
	if(par!=0)dists[id]=dists[par]+1;
	for(res int i=0;i<g[id].size();++i)if(g[id][i]!=par)dist_s(g[id][i],id);
}
int main(){
	ms(distf,MAXN,-1);
	ms(dists,MAXN,-1);
	int n=read<int>();
	for(res int i=0;i<n-1;++i){
		int x=read<int>(),y=read<int>();
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dist_f(1,-1);
	dist_s(n,-1);
	int f=0;
	for(res int i=1;i<=n;++i){
		if(distf[i]<=dists[i])f++;
	}
	if(f>=n/2+1){
		cout<<"Fennec"<<endl;
	}
	else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}

Measured memory_bytes: 11136
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)
ans = 0
mod = 10**9+7
i = 1
while i < (1 << 60):
    count = np.count_nonzero(A & i)
    ans += count * (N-count) * i
    ans %= mod
    i <<= 1
print(ans)


Measured memory_bytes: 49820
#include<bits/stdc++.h>
#define debug(x) cerr<<"\tDEBUG: "<<#x<<" = "<<(x)<<endl
#define debug2(a,b) cerr<<#a<<"\t"<<#b<<" = "<<(b)<<endl
using namespace std;
const int maxn=2e5+100;
bool cur1;
int n,A[maxn],B[maxn];
bool cur2;
int main(){
//	double sz=&cur1-&cur2;
//	cout<<sz/1024/1024<<endl;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	for(int i=n;i>=1;i--){
		int x=i+i,flag=0;
		while(x<=n){
			flag^=B[x];
			x+=i;
		}
		B[i]=flag^A[i];
	}
	int sum=0;
	for(int i=1;i<=n;i++)
		if(B[i])sum++;
	cout<<sum<<endl;
	for(int i=1;i<=n;i++){
		if(B[i])
			printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 2432
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k,q; cin>>n>>k>>q;
    vector<int> p(n,k-q);
    rep(i,q){
        int a; cin>>a;
        p[a-1]++;
    }
    rep(i,n){
        if(p[i]>0) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 3744
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

A=II()
B=II()
print(6-A-B)


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

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k) {
    cout<<k<<endl;
  }
  else if(a+b>=k) {
    cout<<a<<endl;
  }
  else {
    cout<<a-1*(k-a-b)<<endl;
  }
  return 0;
  
}


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

int main(void){
    int n, sum_1 = 0, sum_2 = 0, dif = 100000;
    
    cin >> n;
    
    vector<int> w(n);
    
    rep(i, n){
        cin >> w.at(i);
        sum_1 += w.at(i);
    }
    
    rep(i, n){
        sum_2 += w.at(i);
        if(dif > abs(sum_1 - 2*sum_2)){
            dif = abs(sum_1 - 2*sum_2);
        }
    }
    
    cout << dif << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int n=stdIn.nextInt();
        int k=stdIn.nextInt();
        int a=n;
        int count=0; //桁数
        while(a>0){
            a=a/k;
            count++;
        }
        System.out.print(count);
        
    }

}

Measured memory_bytes: 25172