akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder ABC 141

//d

int main()
{
	int n, m;

	ll check = 0;

	priority_queue<double> pq;
	double temp;

	cin>>n>>m;


	for (int i = 0; i < n; ++i)
	{
		cin>>temp;
		// check+=log2(temp);
		pq.push(temp);
	}

	// check+= n;

	// if(check>=m)
	// {
	// 	cout<<0<<endl;
	// 	cout<<"TES"<<endl;
	// 	return 0;
	// }

	for (int i = 0; i < m; ++i)
	{
		if(pq.empty())
			break;
		temp = pq.top();
		temp/=2.0;
		pq.pop();
		if(temp>0)
		{
			pq.push(temp);
		}
	}

	check = 0;

	while(!pq.empty())
	{
		check+=(int)pq.top();
		pq.pop();
	}

	cout<<check<<endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }



int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 0; i < N/4+1; i++){
    for(int j = 0; j < N/7+1; j++){
      int sum = 4*i + 7*j;
      if(sum == N) ans++;
      if(sum > N) break;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  




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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

using namespace std;

int main() {
  string s;
  cin >> s;

  if (s[0] == s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    int n = Integer.parseInt(r.readLine());

    int f = 0;
    for(int a = n; a > 0; a /= 10)
    {
      f += a % 10;
    }
    
    System.out.println(n % f == 0 ? "Yes" : "No");
  }

}

Measured memory_bytes: 22484
import sys,collections as cl,bisect as bs,heapq as hq
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def search(a,n):
    se = dict()
    data = []
    for i in range(0,len(a)-n+1):
        kkk = a[i:i+n]
        kkk = "".join(kkk)
        if In(kkk,data):
            if se[kkk] <= i-n:
                    return True
        else:
            bs.insort(data,kkk)
            se[kkk] = i
    return False
def solver():
    n = onem()

    s = list(input())
    l = 0
    r = n//2
    for i in range(n):
        mid = -(-(l+r)//2)
        ans = search(s,mid)
        if l == mid:
            break
        if ans:
            l = mid
        else:
            r = mid-1
    print(l)



if __name__ == '__main__':
    solver()




Measured memory_bytes: 10824
#include<stdio.h>

void insertionSort(int*, int);

int main(){
    int N, i= 0;
    
    scanf("%d", &N);
    //printf("%d", N);
    
    int A[N];
    
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
    
    insertionSort(A, N);
    
    return 0;
}

void insertionSort(int* A, int N){
	int i = 0, j = 0, k = 0, temp = 0;
	
	for(i = 0 ;i <= N - 1; i++){
        temp = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > temp){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = temp;
        for(k = 0; k < N; k++){
            if(k == N - 1){
            	printf("%d", A[k]);
            }else{
            	printf("%d ", A[k]);
            }
        }
        printf("\n");
    }	
}



Measured memory_bytes: 2052
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  N = int(readline())
  A = np.array(read().split(), np.int64)
  ans = 0
  for i in range(63):
    B = (A>>i)&1
    x = np.count_nonzero(B)
    y = N - x
    x = x*y
    for _ in range(i):
      x *= 2
      x %= MOD
    ans += x
  ans %= MOD
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

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

int main() {
  int N;
  string S;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> S;
    if (S == "Y"){
      cout << "Four" << endl;
      break;
    }
  }
   if (S != "Y"){
     cout << "Three" << endl;
   }
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int A, B, C, D, ans=0;
    double i;

    cin >> A >> B >> C >> D;

    for(i=0.5; i<=99.5; i+=1.0){
        if(A<i && i<B && C<i && i<D){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[101010];
long long b[101010];
int N;
int main()
{
    scanf("%d", &N);
    for(int i=0; i<N; ++i) scanf("%lld", a+i);
    for(int i=0; i<N; ++i) scanf("%lld", b+i);
    long long sba = 0;
    for(int i=0; i<N; ++i)
        sba += b[i] - a[i];
    long long sbareach = 0;
    for(int i=0; i<N; ++i)
        sbareach += (max(b[i]-a[i], 0ll)+1)/2;
    if(sbareach <= sba)
        puts("Yes");
    else
        puts("No");
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        long n = in.l();
        long count = 0;
        if(n%2 == 0){
            n /= 2;
            long five = 5;
            while(n >= five){
                count += n/five;
                five *= 5;
            }
        }
        out.println(count);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

int main(void)
{

    int k, x;

    cin >> k;
    cin >> x;

    int i;
    int total = 0;

    for(i=0;i<k;i++){
        total += 500;
    }

    if(total >= x){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;

}

Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i, j, n-i-j)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 41068
#include <stdio.h>

int main(void) {
	int a,b;
	char op;

	scanf("%d %c %d",&a,&op,&b);

	if(op=='+') {
		printf("%d",a+b);
	}
	else if(op=='-') {
		printf("%d",a-b);
	}

	return 0;
}


Measured memory_bytes: 128
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, M;
	std::vector<int> A;
	std::cin >> N >> M;
	A.resize(N);
	for (auto& a : A)
		std::cin >> a;

	std::priority_queue<int> P;
	for (auto a : A)
		P.push(a);

	while (M > 0 && !P.empty()) {
		auto p = P.top();
		p >>= 1;
		P.pop();
		if (p != 0)
			P.push(p);
		--M;
	}

	long result = 0;
	while (!P.empty()) {
		auto p = P.top();
		result += p;
		P.pop();
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 1276
#include <cstdio>
int N, E, head[100001], next[199999], to[199999], f[100001], fa[100001], q[100001];
int main()
{
	scanf("%d", &N);
	for (int i = 1, u, v; i < N; i++)
	{
		scanf("%d%d", &u, &v);
		next[++E] = head[u], to[E] = v, head[u] = E;
		next[++E] = head[v], to[E] = u, head[v] = E;
	}
	int H = 0, T = 1, u;
	q[1] = 1;
	while (H < T)
		for (int e = head[u = q[++H]]; e; e = next[e])
			if (to[e] != fa[u])
				fa[q[++T] = to[e]] = u;
	for (int i = N; i > 1; i--)
		f[fa[q[i]]] ^= ++f[q[i]];
	puts(f[1] ? "Alice" : "Bob");
	return 0;
}

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

using namespace std;

int main(void) {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for(int64_t i=0; i<n; i++) {
        cin >> a[i];
    }

    int64_t ans1 = 0;
    int64_t sum1 = 0;
    for(int64_t i=0; i<n; i++) {
        sum1 += a[i];
        if(i%2 == 0) {
            if(sum1 <= 0) {
                ans1 += 1 - sum1;
                sum1 = 1;
            }
        } else {
            if(sum1 >= 0) {
                ans1 += sum1 + 1;
                sum1 = -1;
            }
        }
    }

    int64_t ans2 = 0;
    int64_t sum2 = 0;
    for(int64_t i=0; i<n; i++) {
        sum2 += a[i];
        if(i%2) {
            if(sum2 <= 0) {
                ans2 += 1 - sum2;
                sum2 = 1;
            }
        } else {
            if(sum2 >= 0) {
                ans2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 1024
l = [[['0' for i in range(10)] for j in range(3)] for j in range(4)]
for n in range(int(input())):
    b, f, r, v = map(int, input().strip().split())
    l[b-1][f-1][r-1] = str(v + int(l[b-1][f-1][r-1]))
for k in range(4):
    if bool(k):
        print('#'*20)
    for j in l[k]:
        print(' ' + ' '.join(j))

Measured memory_bytes: 7740
n=int(input())
t=[int(input())for i in range(n)]
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
ans=t[0]
for i in range(n):
    ans=lcm(t[i],ans)
print(ans)


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

int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true)
    {
        c-=b;
        if(c<=0)
        {
            cout<<"Yes\n";
            return 0;
        }
        a-=d;
        if(a<=0)
        {
            cout<<"No\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const long double PI = acosl(-1);
const int MOD = 1e9 + 7;
const long double EPS = 1e-15;

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

    int N;
    cin >> N;

    ll ans = 0;
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> A[i][j];
            ans += A[i][j];
        }
    }

    vector<vector<bool>> isused(N, vector<bool>(N));
    bool isok = true;
    for (int k = 0; k < N && isok; ++k) {
        for (int i = 0; i < N && isok; ++i) {
            for (int j = 0; j < N && isok; ++j) {
                int tmp = A[i][k] + A[k][j];
                if (A[i][j] == tmp && i != k && j != k && !isused[i][j]) {
                    ans -= tmp;
                    isused[i][j] = true;
                }
                if (A[i][j] > tmp)
                    isok = false;
            }
        }
    }
    ans >>= 1;

    cout << (isok ? ans : -1) << endl;
    return 0;
}


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

namespace AtTest.ABC_133
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();
            long deltaSum = 0;
            for(int i = 0; i < n; i++)
            {
                if (i % 2 == 0) deltaSum += array[i];
                else deltaSum -= array[i];
            }

            long[] res = new long[n];
            res[0] = deltaSum;
            res[n - 1] = (array[n - 1] - res[0] / 2) * 2;
            for(int i = n - 2; i > 0; i--)
            {
                res[i] = (array[i] - res[i + 1] / 2) * 2;
            }

            for(int i =0; i < n; i++)
            {
                Write(res[i]);
                if (i + 1 < n) Write(" ");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27484
#include <bits/stdc++.h>
#define MOD 1000000007
 
using namespace std;
typedef long long int lli;
 
 
void solve(){
	int n,w;
	cin>>n>>w;
	int wt[n+1], val[n+1];
	for(int i=1; i<=n; i++){
		cin>>wt[i]>>val[i];
	}
	lli dp[n+1][w+1];
	for(int i=0; i<=n; i++){
		for(int j=0; j<=w; j++){
			if(i==0 || j==0){
				dp[i][j]=0;
				continue;
			}
			if(j-wt[i]>=0){
				dp[i][j]=max(dp[i-1][j], dp[i-1][j-wt[i]]+val[i]);
			}
			else{
				dp[i][j]=dp[i-1][j];
			}
			//cout<<dp[i][j]<<" ";
		}
		
	}
	cout<<dp[n][w]<<endl;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

string q[4]={"dream", "dreamer", "erase", "eraser"};
string s;
int now=0;

bool check(int &x,char c){
  bool ok=true;
 if(c=='m'){
  rep(i,0,5){
    if(s[x]!=q[0][4-i])ok=false;
    //cout<<ok<<endl;
      x++;
  }
 }
  else if(c=='e'){
  rep(i,0,5){
    if(s[x]!=q[2][4-i])ok=false;
      x++;
  }
 }
  else if(c=='r'){
    if(s[x+2]=='s'){
      rep(i,0,6){
    if(s[x]!=q[3][5-i])ok=false;
      x++;
      }
    }
    else{
      rep(i,0,7){
    if(s[x]!=q[1][6-i])ok=false;
      x++;
       }
    }
 }
  else ok=false;
 return ok;
}


int main(){cout<<fixed<<setprecision(20);
		   //
           cin>>s;
           int n=s.size();
           reverse(all(s));
           while(now<n){
               if(!check(now,s[now])){
                cout<<"NO"<<endl;
                 return 0;
               }
            // cout<<now<<endl;
           }
           cout<<"YES"<<endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
using namespace std; using P=pair<int,int>; using ll=long long;

int main() {
  int n,t,a; cin>>n>>t>>a;
  int mx=2e9,id=-1;
  int h[n]; for(int i=0;i<n;i++) cin>>h[i];
  for(int i=0;i<n;i++) {
    if (mx>abs(t*1000-6*h[i]-a*1000)) mx=abs(t*1000-6*h[i]-a*1000), id=i;
  }
  cout<<id+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,k;
    cin>>n>>k;
    long long int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
  	long long int sum=0;
    if(n-k<=0)
    {
        cout<<"0";return 0;
    }
    else
    {
        for(i=0;i<n-k;i++)
        {
           sum+=a[i];
        }
    }
    cout<<sum;
}


Measured memory_bytes: 5132
import java.util.Scanner;

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();

        System.out.println(solve(H, W, h, w));

        sc.close();
    }

    static int solve(int H, int W, int h, int w) {
        return (H - h) * (W - w);
    }
}

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

int main(){
  string a, b;
  long s;
  cin >> a >> b;
  a += b;
  s = atoi(a.c_str());
  if((long)sqrt(s)*(long)sqrt(s)==s){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l+r)/2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6

ii dist[10000000];
bool valid[1000000];

vector<vii> adj;
void dfs(int s, ii d){
	//cout<<s<<" "<<d.F<<" "<<d.S<<endl;
	if(dist[s]!=d && !(dist[s].S==MOD || dist[s].F!=d.F)){
		valid[s] = false;
		return;
	}
	dist[s] = d;
	for(auto v : adj[s]){
		if(dist[v.F].S==MOD || dist[v.F].F!=d.F) dfs(v.F, ii(d.F, d.S+v.S));
		else if(dist[v.F].S!=d.S+v.S) valid[v.F] = false;
	}
}

int main(){
	int n, m;
	cin>>n>>m;
	adj.assign(n+1, vii());
	for(int i=0;i<m;i++){
		int a, b, c;
		cin>>a>>b>>c;
		adj[a].push_back(ii(b,c));
	}
	for(int i=0;i<=n+1;i++){
		dist[i].S = MOD;
		valid[i] = 1;
	}
	for(int i=1;i<=n;i++){
		if(dist[i].S==MOD) dfs(i, ii(i, 0));
	}
	int ans=0;
	//for(int i=1;i<=n;i++) cout<<dist[i].F<<" ";
	//cout<<endl;
	for(int i=1;i<=n;i++){
		//cout<<dist[i].S<<" ";
		if(valid[i]) ans++;
	}
	if(ans==n) cout<<"Yes\n";
	else cout<<"No\n";
}


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

s=[]
for _ in range(n):
    
    s_n=input()
    s.append(s_n)

ac=s.count('AC')
wa=s.count('WA')
tle=s.count('TLE')
re=s.count('RE')

print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Measured memory_bytes: 16128
from collections import defaultdict
b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
  b[input()]+=1
m = int(input())
for i in range(m):
  r[input()]+=1
  
ans = 0
for k, v in b.items():
  ans = max(ans, v - r[k])
for k, v in r.items():
  ans = max(ans, b[k] - v)
print(ans)

Measured memory_bytes: 3316
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for(int i = x-k+1;i <= x+k-1;i++){
            System.out.println(i);
        }
    }
}

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

int main() {
	ll a,b,v,w,t;
  
  	cin>>a>>v>>b>>w>>t;
  
  	ll dist=max(a-b,b-a);
  	ll sekkin=v-w;

  
  	bool kotae=false;
  
   	for(int i=0;i<t;i++){
    	dist -=sekkin;
      	if(dist<=0){
        	kotae=true;
        }
    }

    if(kotae){
    	cout<<"YES"<<endl;
    }
  
  	else{
    	cout<<"NO"<<endl;
    }
  	
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int lenS, n;
char s[5005];

long long pangkat(long long base, long long pang){
    long long ret = 1;
    while(pang){
        if (pang & 1){
            ret = (ret * base) % MOD;
        }
        base = (base*base) % MOD;
        pang >>= 1;
    }
    return ret;
}

long long memo[5005][5005];

long long f(int fixed, int index){
    if (fixed == lenS && index == n)
        return 1;

    if (index == n && fixed != lenS) return 0;

    long long &ret = memo[fixed][index];
    if (ret != -1) return ret;

    if (fixed == 0){
        ret = 2*f(fixed+1, index+1) + f(fixed, index+1);
    }
    else{
        ret = f(fixed-1, index+1) + 2*f(fixed+1, index+1);
    }
    ret %= MOD;
    return ret;
}
int main(){
    scanf("%d", &n);
    scanf("%s", s);
    lenS = strlen(s);
    memset(memo, -1, sizeof(memo));

    printf("%lld\n", (f(0,0)*pangkat(pangkat(2, lenS) % MOD, MOD-2)) % MOD);
}

Measured memory_bytes: 196224
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int N,M,i;
	long long T[105],X,sum=0,P[105],a,c[105];
	cin >> N;
	for(i=0;i<N;i++)
	{
		cin >> T[i];
		sum+=T[i];
	}
	cin >> M;
	for(i=0;i<M;i++)
	{
		cin >> a;
		cin >> P[a-1];
		c[i]=sum+P[a-1]-T[a-1];
	}
	for(i=0;i<M;i++)
	{
		cout << c[i]<<endl; 
	}
	return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string aaa = Console.ReadLine(); //標準入力
        string[] aa = aaa.Split(' ');
        

        decimal a = decimal.Parse(aa[0]);
        decimal b = decimal.Parse(aa[1]);
        decimal c = decimal.Parse(aa[2]);
        decimal d = decimal.Parse(aa[3]);

        decimal Max = Math.Max(a * c, a * d);
        Max = Math.Max(Max, b * d);
        Max = Math.Max(Max, b * c);

        
        Console.WriteLine("{0}", Max);
    }

}

Measured memory_bytes: 27536
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

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

int main() {
  LL N, K; scanf("%lld %lld", &N, &K);
  vector<LL> A = vector<LL>(N, 1);
  rep(i, N) scanf("%lld ", &A[i]);
  // LL cump = 1;
  // LL cump_before = 1;
  // LL recovery = 1;
  // int recovery_count = 0;
  // // cump = A[0]*...*A[K-1]
  // rep(i, K) cump *= A[i];
  // cump_before = cump;
  rep(i, N-K){
    // if(recovery_count>0){
    //   recovery *= A[K+i];
    // }
    // if(A[K+i] ==0){
    //   cump = 0;
    //   recovery = 1;
    //   recovery_count = K;
    // } else{
    //   cump *= A[K+i];
    //   cump = cump/A[i];
    // }
    if (A[i] < A[K+i]) cout << "Yes" << endl;
    else cout << "No" << endl;
    // cump_before = cump;
  }

  return 0;
}



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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll I, O, T, J, L, S, Z; cin >> I >> O >> T >> J >> L >> S >> Z;
    ll ans = 0;
    ans += O;
    if (((I % 2) + (J % 2) + (L % 2) >= 2) && I > 0 && J > 0 && L > 0) {
        ans += 3;
        --I; --J; --L;
    } 
    ans += I / 2 * 2;
    ans += J / 2 * 2;
    ans += L / 2 * 2;
    cout << ans << endl;
}

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

const int MAXF = 10001;

int main() {
  for(int N, A, B, C, X;
      cin >> N >> A >> B >> C >> X && (N|A|B|C|X); ) {
    vector<int> Y(N);
    for(int i = 0; i < N; ++i) cin >> Y[i];
    int f = 0;
    for(int k = 0; k < N && f < MAXF; ) {
      if(Y[k] == X)
        if(++k == N) break;
      X = (A * X + B) % C;
      ++f;
    }
    if(f >= MAXF) f = -1;
    cout << f <<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

ll N,K,cnt = 0,ans = 0LL;

void solve(vector<ll> &V){
    bool flag = 0;
    repp(i,40,0){
        vector<ll> W;
        ll bit = (1LL << (i)); 
        ll Y = 0;
        REP(j,V.size()){
            if((bit & V[j]) == bit){
                ll D = V[j] & ~(1LL<<(i));
                W.pb(D);
                ++Y;
            }
        }
        if(Y >= K){
            ans += bit;
            V.swap(W);
        }
    }
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> N >> K;
    vector<ll> A(N),V;
    REP(i,N){cin >> A[i];}
    REP(i,N){
        ll sum = 0;
        REPP(j,i,N){
            sum += A[j];
            V.pb(sum);
        }
    }
    sort ALL(V);
    reverse ALL(V);
    solve(V);
    cout << ans << endl;
}


Measured memory_bytes: 6384
N = int(input())
A = [int(i) for i in input().split()]

S = min(A)
L = max(A)

c = 0
B = []

if S == L:
    pass

elif S >= 0 and L > 0:
    for i in range(N-1):
        if A[i+1] >= A[i]:
            pass
        else:
            A[i+1] += A[i]
            c += 1
            B.append((i+1, i+2))

elif L <= 0 and S < 0:
    for i in range(N-1):
        if A[-i-2] <= A[-i-1]:
            pass
        else:
            A[-i-2] += A[-i-1]
            c += 1
            B.append((N-i, N-i-1))

else:
    if L >= -S:
        l = A.index(L)
        if A[0] < 0:
            A[0] += L
            c += 1
            B.append((l+1, 1))
        for i in range(N-1):
            if A[i+1] >= A[i]:
                pass
            else:
                if A[i+1] < 0:
                    A[i+1] += L
                    c += 1
                    B.append((l+1, i+2))
                A[i+1] += A[i]
                c += 1
                B.append((i+1, i+2))
                if i+1 == l:
                    L = A[l]
    else:
        s = A.index(S)
        if A[-1] > 0:
            A[-1] += S
            c += 1
            B.append((s+1, N))
        for i in range(N-1):
            if A[-i-2] <= A[-i-1]:
                pass
            else:
                if A[-i-2] > 0:
                    A[-i-2] += S
                    c += 1
                    B.append((s+1, N-i-1))
                A[-i-2] += A[-i-1]
                c += 1
                B.append((N-i, N-i-1))
                if -i-2 == s:
                    S = A[s]

if c == 0:
    print(c)
else:
    print(c)
    for i in range(c):
        print(B[i][0], B[i][1])


Measured memory_bytes: 9184
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

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

	n := scanInt(sc)
	k := scanInt(sc)

	steps := int64(n / k)
	count := steps * steps * steps

	if k%2 == 0 {
		half := k / 2
		if n >= half {
			steps := int64((n-half)/k) + 1
			count += steps * steps * steps
		}
	}

	fmt.Println(count)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    double n, d;
    cin >> n >> d;

    int total = 0;
    while (n--) {
        double x, y;
        cin >> x >> y;
        double dist = sqrt(x * x + y * y);
        if (dist <= d)
            total++;
    }
    cout << total << endl;
}



Measured memory_bytes: 3816
def bellmanford(v,e,s,path):
    inf = float('inf')
    d = [inf for i in range(v)]
    d[s] = 0
    for j in range(v):
        update = False
        for i in range(e):
            if d[path[i][0]] != inf and d[path[i][1]] > d[path[i][0]] + path[i][2]:
                d[path[i][1]] = d[path[i][0]] + path[i][2]
                update = True
                if j == v-1 and path[i][1]==n-1:
                    return -1
        if not update:
            break
    return d


n,m = map(int, input().split())

path = []

for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    c *= -1
    path.append([a,b,c])

d = bellmanford(n,m,0,path)

if d==-1:
    print('inf')
else:
    print(-d[n-1])

Measured memory_bytes: 44780
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int list_input(a, 3);
  sort(a, a + 3);

  int diff = a[1] - a[0];
  int result = diff / 2 + a[2] - a[1];
  if(diff % 2 == 1) {
    result += 2;
  }
  out(result);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

ll n;

void func(ll cur, int use, ll &counter) {
    if (cur > n) return;
    if (use == 0b111) ++counter;

    func(cur * 10 + 7, use | 0b001, counter);

    func(cur * 10 + 5, use | 0b010, counter);

    func(cur * 10 + 3, use | 0b100, counter);
}

int main()
{
    cin >> n;
    ll res = 0;
    func(0, 0, res);
    cout << res << endl;
    
    return 0;
}

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

int main(){
    while(1){
        string str;
        cin>>str;
        if(str=="0")break;
        int result=0;
        for(int i=0;i<str.length();i++){
            if(str[i]!='\0')result+=(int)str[i]-'0';
        }
        cout<<result<<endl;
    }
    return 0;
}


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


int main(){
	int a,b,c,count = 0;
	cin >> a >> b >> c;
	if(a >= c){
		cout << c <<endl;
	}
	else{
		while(1){
			count += a + b;
			if(count%60 <= c && (count%60) + a >= c){
				cout << count - (count%60) + c <<endl;
				break;
			}
			if(count/60 > 60){
				cout << -1 <<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <utility>
#include <algorithm>
#include <iostream>

using namespace std;

int N, M;
pair<int,int> PD[10010];
int main() {
  while (cin >> N >> M && N) {
    int d, p;
    for (int i = 0; i<N; ++i) {
      cin >> d >> p;
      PD[i] = make_pair(-p,-d);
    }
    int S = 0 ;
    for (int i = 0; i < N; ++i) {
      S += PD[i].first * PD[i].second;
    }
    sort(PD,PD+N);
    
    for (int i=0; i<N; ++i) {
      if (M <= 0) break;
      int guarded = min(M , -1*PD[i].second);
      S -= -1*PD[i].first * guarded;
      M -= guarded;
    }
    cout << S << endl;
    
  }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)(998244353);

vvll C;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  string S;
  IN(N);
  IN(S);
  C.resize(N, vll(3, -1));
  ll red = 0, blue = 0, green = 0;
  REP(i,3*N){
    switch(S[i]){
      case 'R':
        C[red][0] = i;
        red++;
        break;
      case 'G':
        C[green][1] = i;
        green++;
        break;
      case 'B':
        C[blue][2] = i;
        blue++;
        break;
    }
  }

  REP(i,N){
    sort(ALL(C[i]));
  }

  mat_print(C);

  vvll C_trans(3, vll(N));
  REP(i,N) REP(j,3) C_trans[j][i] = C[i][j];

  vll dpm(N);
  vll dpl(N);

  REP(i,N){
    dpm[i] = lower_bound(ALL(C_trans[0]), C_trans[1][i]) - C_trans[0].begin() - i;
    dpl[i] = lower_bound(ALL(C_trans[1]), C_trans[2][i]) - C_trans[1].begin() - i;
  }

  vec_print(dpm);
  vec_print(dpl);

  ll ans = 1;
  REP(i,N){
    ans *= dpm[i];
    ans %= MOD;
    ans *= dpl[i];
    ans %= MOD;
  }

  REP(i,N){
    ans *= (i+1);
    ans %= MOD;
  }

  OUT(ans);

  return 0;
}

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

int n, x;
int a[30];
bool b[1000001];
bool p[1000001];

bool input() {
  cin >> n >> x;
  if (!n && !x) {
    return false;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  return true;
}

void solve() {
  for (int i = 0; i <= x; ++i) {
    b[i] = false;
    p[i] = true;
  }

  b[0] = true;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= x - a[i]; ++j) {
      if (b[j]) {
        b[j + a[i]] = true;
      }
    }
  }

  p[0] = p[1] = false;
  for (int i = 2; i * i <= x; ++i) {
    if (!p[i]) {
      continue;
    }
    for (int j = i + i; j <= x; j += i) {
      p[j] = false;
    }
  }

  int ans = -1;
  for (int i = x; i >= 0; --i) {
    if (b[i] && p[i]) {
      ans = i;
      break;
    }
  }

  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
}

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

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

vector<vector<int>> graph, cost;
vector<bool> ans;

void dfs(int u, int pre = -1, int c = 0){

    rep(i, graph[u].size()){
        int v = graph[u][i];
        int w = cost[u][i];
        if(v == pre){
            continue;
        }
        if((w+c) % 2 == 0){
            ans[v] = 0;
        }
        else{
            ans[v] = 1;
        }
        dfs(v, u, w+c);
    }
}

int main() {

    int n;
    cin >> n;
    graph.resize(n);
    cost.resize(n);
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        w %= 2;
        graph[u].push_back(v);
        graph[v].push_back(u);
        cost[u].push_back(w);
        cost[v].push_back(w);
    }

    ans.resize(n);
    dfs(0);
    
    rep(i, n){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 13696
N = int(input())
tList = [int(x) for x in input().split()]
M = int(input())
px = []
for i in range(M):
    p, x = map(int, input().split())
    px.append((p,x))

base = sum(tList)
for p,x in px:
    print(base - tList[p-1] + x)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	int n;
	while(cin >> n){
		int ans = 0;
		rep(i, 0, 10){
			rep(j, 0, 10){
				rep(k, 0, 10){
					rep(l, 0, 10){
						if(i + j + k + l == n) ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll V_I_MAX = 100000;

ll N;
ll v[N_MAX];

void input() {
	scanf("%lld", &N);
	rep(i, N) scanf("%lld", v + i);
}

void solve() {
	ll ans = 0;

	map<ll,ll> m0,m1;
	rep(i,N){
		if(i%2){
			m0[v[i]]++;
		}else{
			m1[v[i]]++;
		}
	}

	vector<pair<ll,ll>> v0,v1;
	for(auto m:m0){
		v0.push_back(make_pair(m.second,m.first));
	}
	for(auto m:m1){
		v1.push_back(make_pair(m.second,m.first));
	}
	sort(all(v0));
	sort(all(v1));

	if(v0[v0.size()-1].second==v1[v1.size()-1].second){
		if(v0.size()==1 && v1.size()==1){
			ans+=(N/2);
		//}else if(v0.size()==1){
		//	ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-2].first);
		//}else if(v1.size()==1){
		//	ans=(N/2-v1[v1.size()-1].first) + (N/2-v0[v0.size()-2].first);
		}else if(v0[v0.size()-2].first>v1[v1.size()-2].first){
			ans=(N/2-v1[v1.size()-1].first) + (N/2-v0[v0.size()-2].first);
		}else{
			ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-2].first);
		}
	}else{
		ans=ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-1].first);
	}


	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 9592
n, k = map(int, input().split())
A = []
D = []

for i in range(n):
    A.append(int(input()))

A.sort(reverse=True)
    
for i in range(n - k + 1):
    diff = A[i] - A[i + k -1]
    D.append(diff)
    
print(min(D))

Measured memory_bytes: 11288
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x, y = M()
print(x + y//2)

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

using namespace std;
int main(){
    
    int H, W;
    cin >> H >> W;
    //H = 2000;
    //W = 2000;
    
    vector<string> S;
    for (int i = 0; i < H; i++) {
        string ss;
        cin >> ss;
        
        /*
        for (int j = 0; j < 2000-1; j++) {
            ss.push_back('.');
        }
        */
        
        S.push_back(ss);
    }
    
    int ans = 0;
    
    int HHH[H][W];
    int WWW[H][W];
    
    
    
    for (int i = 0; i < H; i++) {
       
        int llw = 0;
        
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                WWW[i][j] = 0;
                if (llw != 0) {
                    for (int k = j-1; k >= j-llw; k--) {
                        WWW[i][k] = llw;
                    }
                }
                llw = 0;
            }else{
                llw += 1;
                if (j == W-1) {
                    for (int k = j; k >= j-llw+1; k--) {
                        WWW[i][k] = llw;
                    }
                }
            }
        }
    }
  
    
    
    
    for (int i = 0; i < W; i++) {
        
        int llh = 0;
        
        for (int j = 0; j < H; j++) {
            if (S[j][i] == '#') {
                HHH[j][i] = 0;
                if (llh != 0) {
                    for (int k = j-1; k >= j-llh; k--) {
                        HHH[k][i] = llh;
                    }
                }
                llh = 0;
            }else{
                llh += 1;
                if (j == H-1) {
                    for (int k = j; k >= j-llh+1; k--) {
                        HHH[k][i] = llh;
                    }
                }
            }
        }
    }
   
  
    
    
    
    for (int i = 0; i < H; i++) {
        
        int ansN = 0;
        
        for (int j = 0; j < W; j++) {
         
            ansN = WWW[i][j] + HHH[i][j];
            if (ans < ansN) {
                ans = ansN;
            }
            //cout << WWW[i][j] << " ";
            
        }
        //cout << endl;
    }
    
    
    
    cout << ans-1 << endl;
    
}


Measured memory_bytes: 35584