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

int main() {
	int n, d; cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
	for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    int cnt=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int dis=0;
            for(int k=0; k<d; k++){
                dis += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(int k=1; k*k<16000; k++){
                if(k*k==dis){
                    cnt++;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, a, b;
  scanf("%d", &n);
  if(n==1){
    printf("Hello World\n");
  }else{
    scanf("%d", &a);
    scanf("%d", &b);
    printf("%d\n", a+b);
  }

  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	s := nextString()

	f := true
	for i, c := range s {
		if i%2 == 0 {
			if string(c) != "R" && string(c) != "U" && string(c) != "D" {
				f = false
			}
		} else {
			if string(c) != "L" && string(c) != "U" && string(c) != "D" {
				f = false
			}
		}
	}

	if f {
		_, _ = fmt.Fprint(writer, "Yes")
	} else {
		_, _ = fmt.Fprint(writer, "No")
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
import heapq

n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))
q, k = map(int, input().split())
qs = [tuple(map(int, input().split())) for i in range(q)]

INF = float('inf')
dist = [INF for i in range(n)]
dist[k-1] = 0
hq = [(0, k-1)]
while hq:
    cost, node = heapq.heappop(hq)
    for n_node, n_cost in g[node]:
        d = dist[node] + n_cost
        if d < dist[n_node]:
            dist[n_node] = d
            heapq.heappush(hq, (dist[n_node], n_node))

for i in range(q):
    print(dist[qs[i][0]-1] + dist[qs[i][1]-1])

Measured memory_bytes: 59708
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]||s[2]==s[1]||s[2]==s[3]){
    cout<<"Bad";
  }else{
    cout<<"Good";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
 
using namespace std;
const int MAX = 500005;
const int MAX1 = 1e6 + 5;
int tree[MAX], p[MAX1], ans[MAX], a[MAX];
pair <int, pair<int, int> > pr[MAX];
 
void update(int idx, int val)
{
    while(idx < MAX)
    {
        tree[idx] += val;
        idx += (idx & -idx);
    }
}
 
int read(int idx)
{
    int sum = 0;
    while(idx > 0)
    {
        sum += tree[idx];
        idx -= (idx & -idx);
    }
    return sum;
}
 
int main()
{
    int n, q, x;
    
    scanf("%d", &n);
    scanf("%d", &q);
    for(int i = 1;i <= n;++i)
        scanf("%d", &a[i]);
    for(int i = 0;i < q;++i)
    {
        scanf("%d %d", &pr[i].second.first, &pr[i].first);
        pr[i].second.second = i;
    }
    sort(pr, pr + q);
    memset(p, -1, sizeof(p));
    memset(tree, 0, sizeof(tree));
    x = 0;
    for(int i = 1;i <= n;++i)
    {
        if(p[a[i]] != -1)
            update(p[a[i]], -1);
        p[a[i]] = i;
        update(i, 1);
        while(x < q and pr[x].first == i)
        {
            ans[pr[x].second.second] = read(pr[x].first) - read(pr[x].second.first-1);
            x++;
        }
    }
    for(int i = 0;i < q;++i)
        printf("%d\n", ans[i]);
    return 0;
}
 

Measured memory_bytes: 19384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B,C;
    cin >>A>>B>>C;
    if(A==B){
        cout<<C<<endl;
    }else if(A==C){
        cout<<B<<endl;
    }else{
        cout<<A<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long long
using namespace std;

signed main() {
 	int A,B,C,D;
 	cin >> A >> B >> C >> D;
 	int N;
 	int Ca = C;
 	int Da = D;
 	if(C < D) {
 		N = Ca;
 		Ca = Da;
 		Da = N;
 	}
  	N = Ca % Da;
 	while(N != 0) {
 		Ca = Da;
      	Da = N;
 		N = Ca % Da;
 	}
  	int S = C * D / Da;
 	cout << ( B - A + 1 ) - ( B / C - (A - 1) / C) - ( B / D - (A - 1) / D) + (B / S - (A - 1) / S) << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = 998244353;

int f[N], a[N];

long long power(long long b, long long p, long long MOD = 998244353) {
    long long res = 1;
    b %= MOD;
    for (; p; p >>= 1LL) {
        if (p & 1)res = (res * b) % MOD;
        b = (b * b) % MOD;
    }
    return res % MOD;
}

class BCountingOfTrees {
public:
    void solve(istream &cin, ostream &cout) {
        int n;
        cin >> n;
        int mx = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            f[a[i]]++;
            mx = max(mx, a[i]);
        }
        if (f[0] != 1 || a[0] != 0)
            return (void) (cout << 0 << el);
        for (int i = 0; i < mx; i++)
            if (!f[i]) {
                cout << "0\n";
                return;
            }
        int ans = 1;
        for (int i = 1; i <= mx; i++)
            ans = (ans * power(f[i - 1], f[i])) % MOD;

        cout << ans << el;
        clr(f, 0);
    }
};

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    BCountingOfTrees solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

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

int H,W;
string S[2222];

int U[2222][2222],D[2222][2222],L[2222][2222],R[2222][2222];

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>S[i];
    
    
    rep(i,H){
        rep(j,W){
            L[i+1][j+1]=L[i+1][j]+1;
            if(S[i][j]=='#')L[i+1][j+1]=0;
        }
        for(int j=W-1;j>=0;j--){
            R[i+1][j+1]=R[i+1][j+2]+1;
            if(S[i][j]=='#')R[i+1][j+1]=0;
        }
    }
    
    rep(j,W){
        rep(i,H){
            U[i+1][j+1]=U[i][j+1]+1;
            if(S[i][j]=='#')U[i+1][j+1]=0;
        }
        for(int i=H-1;i>=0;i--){
            D[i+1][j+1]=D[i+2][j+1]+1;
            if(S[i][j]=='#')D[i+1][j+1]=0;
        }
    }
    
    int ans=0;
    rep(i,H)rep(j,W)if(S[i][j]!='#')chmax(ans,U[i+1][j+1]+D[i+1][j+1]+L[i+1][j+1]+R[i+1][j+1]-3);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 149760
import           Data.List                      ( foldl' )

solve [l           ] [r           ] = [gcd l r]
solve (l0 : l1 : ls) (r0 : r1 : rs) = gcd l0 r1 : solve (l1 : ls) (r1 : rs)

main :: IO ()
main = do
    n  <- read <$> getLine :: IO Int
    as <- map read . words <$> getLine :: IO [Int]
    let ls = foldl' (\b a -> gcd (head b) a : b) [0] as
        rs = foldr (\a b -> gcd (head b) a : b) [0] as
        ms = solve (reverse ls) rs
    print (maximum ms)


Measured memory_bytes: 98684
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, a[MAX];

  scanf("%d", &n);
  rep(i, n)
  {
    scanf("%d", &a[i + 1]);
  }

  long long int dp[MAX][2];
  dp[1][0] = a[1];
  dp[1][1] = -a[1];
  for (int i = 2; i <= n; i++)
  {
    dp[i][0] = max(dp[i - 1][0] + a[i], dp[i - 1][1] - a[i]);
    dp[i][1] = max(dp[i - 1][0] - a[i], dp[i - 1][1] + a[i]);
  }

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


Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static int N;
	public static int[] stair;
	public static long[] count;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int M = sc.nextInt();
		List<Integer> broken = new ArrayList<>();
		boolean impossible = false;
		int tmp = -1;
		stair = new int[N + 1];
		count = new long[N + 1];
		for(int i = 0; i < N + 1; i++) {
			stair[i] = 0;
		}
		for(int i = 1; i < M + 1; i++) {
			int tmp2 = sc.nextInt();
			if(tmp + 1 == tmp2) {
				impossible = true;
				break;
			} else {
				stair[tmp2] = 1;
				tmp = tmp2;
			}
		}
		if(!impossible) {
			for(int i = 0; i < N + 1; i++) {
				count[i] = 0;
			}
			count[N] = 1;
			for(int i = N; i > 0; i--) {
				if(i > 1) {
					if(stair[i - 1] == 0) {
						count[i - 1] += count[i] % 1000000007;
					}
					if(stair[i - 2] == 0) {
						count[i - 2] += count[i] % 1000000007;
					}
				} else if(i == 1) {
					count[0] += count[i] % 1000000007;
				}
			}
			System.out.println(count[0] % 1000000007);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 47764
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        while(a[i]%2==0)ans++,a[i]/=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll N;
int main() {
	while (cin >> N) {
		if (N == 0){
			break;
	}
			ll cnt = 0;
		for (ll i = N + 1; i <= 2 * N; i++) {
			if (prime(i))cnt++;
		}
		cout << cnt << endl;
	}
}


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

Measured memory_bytes: 128
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var t = 0;
        for (int i = 0; i < sL; i++)
            t += s[i] - '0';
        Console.WriteLine(t % 9 == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 26620
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll n,i,j,cc=0,k;
   cin>>n;
   ll p[n],q[n];for(i=0;i<n;i++)cin>>p[i];
   for(i=0;i<n;i++)cin>>q[i];
   vector<ll>a;
   for(i=0;i<n;i++)a.pb(i+1);
   ll pp=0,qq=0,x=0,y=0;
   while(1){
     ll cc=0;
      for(i=0;i<n;i++){
        if(p[i]!=a[i]){cc=1;break;}
      }
      if(cc==1 && x==0)pp++;
      else x=1;
      ll dd=0;
      for(i=0;i<n;i++){
        if(q[i]!=a[i]){dd=1;break;}
      }
      if(dd==1 && y==0)qq++;
      else y=1;
      if(x && y)break;
      next_permutation(a.begin(),a.end());
   }
   cout<<abs(pp-qq)<<endl;
return 0;
}


Measured memory_bytes: 4992
// B - Trick or Treat
#include <bits/stdc++.h>
using namespace std;
int in(){int x;cin>>x;return x;}

int main(){
	int N,K; cin>>N>>K;
	set<int> ok;
	for(int i=0; i<K; ++i)
		for(int d=in(), j=0; j<d; ++j) ok.insert(in());
	cout<< N-ok.size() <<endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int get(int x)
{
	int ret=0;
	while (!(x&(1<<ret)))
	ret++;
	return ret+1;
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		printf("%d ",get(j-i));
		printf("\n");
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <typeinfo>

#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]){

  int A, B, C, D;
  string S;

  cin >> S;
  string s;
  A = stoi(s = S[0]);
  B = stoi(s = S[1]);
  C = stoi(s = S[2]);
  D = stoi(s = S[3]);


  int opt = 0;
  while(opt < 9){
    //printf("in while\n");
    int sum = A; // 初期化
    sum += ((opt&1)?1:-1)*B;
    sum += (((opt>>1)&1)?1:-1)*C;
    sum += (((opt>>2)&1)?1:-1)*D;
    //printf("%d%c%d%c%d%c%d=7\n", A, ((opt&1)?'+':'-'), B, (((opt>>1)&1)?'+':'-'), C, (((opt>>2)&1)?'+':'-'), D);
    //printf("sum  = %d\n", sum);
    if(sum == 7){
      printf("%d%c%d%c%d%c%d=7\n", A, ((opt&1)?'+':'-'), B, (((opt>>1)&1)?'+':'-'), C, (((opt>>2)&1)?'+':'-'), D);
      break;
    }else{
      opt++;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#define ll long long 
using namespace std;
string s[10],t[10];
int cnt;
int n,m,k,res,vis_row[7],vis_col[7];
void dfs(int r,int c)
{
	if(r<n)
	{
		vis_row[r]=1;
		dfs(r+1,c);
		vis_row[r]=0;
		dfs(r+1,c);
	}
	else if(c<m)
	{
		vis_col[c]=1;
		dfs(r,c+1);
		vis_col[c]=0;
		dfs(r,c+1);
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			t[i][j]=s[i][j];
		}
		for(int i=0;i<n;i++)
		{
			if(vis_row[i])
			for(int j=0;j<m;j++)
			t[i][j]='.';
		}
		for(int i=0;i<m;i++)
		{
			if(vis_col[i])
			for(int j=0;j<n;j++)
			t[j][i]='.';
		}
		int cnt=0;
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		if(t[i][j]=='#')cnt++;
		
		if(cnt==k)res++;
		return ;
	}
}
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		cin>>s[i][j];
	}
	dfs(0,0);
	cout<<res<<"\n";
	return 0;
 } 

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;cin >> h >> w >> k;
    char c[h][w];
    REP(i,h){
        REP(j,w){
            cin >> c[i][j];
        }
    }
    int ans=0;
    REP(i,1<<h){
        REP(j,1<<w){
            int cnt=0;
            REP(a,h){
                REP(b,w){
                    if((i&(1<<a))||(j&(1<<b))){
                        continue;
                    }
                    if(c[a][b]=='#'){
                        cnt++;
                    }
                }
            }
            if(cnt==k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int N, C;
    cin >> N >> C;

    int D[C + 1][C + 1];
    for (int i = 1; i <= C; i++)
    {
        for (int j = 1; j <= C; j++)
        {
            cin >> D[i][j];
        }
    }

    int c[N + 1][N + 1];
    vector<vector<int>> x(3);
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            cin >> c[i][j];
            x[(i + j) % 3].push_back(c[i][j]);
        }
    }

    vector<vector<int>> cost(3, vector<int>(C + 1, 0));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 1; j <= C; j++)
        {
            for (int k = 0; k < x[i].size(); k++)
            {
                cost[i][j] += D[x[i][k]][j];
            }
        }
    }

    int ans = INT_MAX;
    for (int i = 1; i <= C; i++)
    {
        for (int j = 1; j <= C; j++)
        {
            if (i == j)
            {
                continue;
            }
            for (int k = 1; k <= C; k++)
            {
                if (i == k || j == k)
                {
                    continue;
                }
                ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2416
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int mx = n*(n-1)/2;
  mx -= n-1;
  if(mx < k){
    cout << -1 << endl;
    return 0;
  }
  // cerr << mx << endl;
  vector<pair<int, int>> ans;
  rep(i, n-1){
    ans.push_back({1, i+2});
  }
  int co = 0;
  rep2(i, 2, n+1){
    rep2(j, i+1, n+1){
      if(co == mx-k) goto SKIP;
      ans.push_back({i, j});
      co++;
    }
  }
  SKIP:
  cout << ans.size() << endl;
  rep(i, ans.size()){
    cout << ans.at(i).first << " " << ans.at(i).second << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <stack>

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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> b;
  int tmp;
  rep(i, N){
    cin >> tmp;
    b.push_back(tmp);
  }
  // 入力終了

  stack<int> ans;

  // 問題ではj番目にjを挿入しているので，
  // 数列bの左からj番目がjなら取り除けると考える．
  // 先頭から取り除いていくと，k番目のkがk-1番目のkになって
  // 取り除けなくなるので，末尾から取り除いていく
  
  // 末尾から見ていく
  for(int i=N-1; i>=0; i--){
    for(int j=i; j>=0; j--){
      // j番目がjなら取り除き，
      // 答えのスタックに追加
      if(b[j] == j+1){
	ans.push(b[j]);
	b.erase(b.begin() + j);
	break;
      }
    }
  }

  // スタックに入ってる個数が数列の長さと一致しなければNG
  if(ans.size() != N){
    cout << -1 << endl;
    return 0;
  }
  
  // スタックの上から順に表示
  while(!ans.empty() ){
    cout << ans.top() << endl;
    ans.pop();
  }

  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path, D;
//***********//
int main() {
	cin >> H >> W;
	vs A(H);
	vll C(H, vl(W));
	for (i = 0; i < H; i++) {
		cin >> A[i];
		for (j = 0; j < W; j++) {
			if (A[i][j] == '#') C[i][j] = 0;
			else C[i][j] = INF;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W-1; j++) {
			C[i][j + 1] = min(C[i][j + 1], C[i][j] + 1);
		}
		for (j = W-1; j > 0; j--) {
			C[i][j - 1] = min(C[i][j - 1], C[i][j] + 1);
		}
	}
	for (j = 0; j < W; j++) {
		for (i = 0; i < H - 1; i++) {
			C[i+1][j] = min(C[i+1][j], C[i][j] + 1);
		}
		for (i = H - 1; i > 0; i--) {
			C[i-1][j] = min(C[i-1][j], C[i][j] + 1);
		}
	}
	ans = 0;
	for (i = 0; i < H; i++) {
		//debug(C[i]);
		for (j = 0; j < W; j++) {
			ans = max(ans, C[i][j]);
		}
	}
	cout << ans;
}

Measured memory_bytes: 9088
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main()
{
    // 整数の入力
    long long N,i,tempD;
    set<long long> mochi;
    cin >> N;
    for (i=0;i<N;i++){
        cin >> tempD;
        mochi.insert(tempD);
    }
    cout << mochi.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;

int main()
{
    long long x,k,d;
    cin>>x>>k>>d;
    if(x<0)x=-x;
    if(x/d>=k) cout<<x-k*d;
    else
    {
        int dk=x/d;
        k-=dk;
        x-=dk*d;
        if(k%2==0) cout<<x;
        else cout<<d-x;

    }
    return 0;
}


Measured memory_bytes: 3628
from fractions import gcd
from math import sqrt,asin,degrees
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from itertools import accumulate,permutations
from bisect import bisect_left,bisect_right

N, K = map(int,input().split())
A = [int(i) for i in input().split()]

MOD = 10**9 + 7

B = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            B += 1

C = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            C += 1

tmp = (K * (K - 1)) // 2 % MOD

ans = (K * B) % MOD
ans = (ans + tmp * C) % MOD

print(ans)

Measured memory_bytes: 5344
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	string str;
	cin>>str;
	int ans = 0;
	for(int i =0;i <=str.length();i++){
		if(str[i]=='0')continue;
		int a =atoi(str.substr(0,i).c_str());
		int b =atoi(str.substr(i).c_str());
		if(b-a>=0&&(a+b)%2==0&&(b-a)%2==0){
			ans++;
		}
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 1200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
using ld = long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class BStringPalindrome {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string s;
	    in >> s;
        int n = s.length();

        string bufs = s;
        reverse(s.begin(), s.end());

        string t = s.substr(0, (n-1)/2);
        string buft = t;
        reverse(t.begin(), t.end());

        string u = s.substr((n+3)/2-1, n);
        string bufu = u;
        reverse(u.begin(), u.end());

        ans(bufs == s && buft == t && bufu == u, out);

//        cout << s sp t sp u << endl;
//        cout << bufs sp buft sp bufu << endl;
	}
};


int main() {
	BStringPalindrome solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())

if H%3 == 0 or W%3 == 0:
  print(0)
else:
  h2 = [H//2,H//2+1]
  h3 = [H//3,H//3+1,H//3+2]  
  w2 = [W//2,W//2+1]
  w3 = [W//3,W//3+1,W//3+2]
  ans = float("inf")
  #最初に縦切り
  for i in range(3):
    for j in range(2):
      a = H*w3[i]
      b = (W-w3[i])*h2[j]
      c = H*W - a - b 
      ans = min(ans , max(a,b,c) - min(a,b,c) )    
  #横  
  for i in range(3):
    for j in range(2):
      a = W*h3[i]
      b = (H-h3[i])*w2[j]
      c = H*W - a - b 
      ans = min(ans , max(a,b,c) - min(a,b,c) ) 
  #縦横の完全三等分パターン
  for i in range(3):
    for j in range(2):
      a = h3[i]
      b = (H-h3[i])//2
      c = H-a-b
      ans = min(ans , W*(max(a,b,c) - min(a,b,c)) )
      a = w3[i]
      b = (W-w3[i])//2
      c = W-a-b
      ans = min(ans , H*(max(a,b,c) - min(a,b,c)) )    
  print(ans)

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	arr := make([][]int, m)
	for i := 0; i < m; i++ {
		var k int
		fmt.Scan(&k)
		arr[i] = make([]int, k)
		for j := 0; j < k; j++ {
			var s int
			fmt.Scan(&s)
			arr[i][j] = s
		}
	}
	ps := make([]int, m)
	for i := 0; i < m; i++ {
		var p int
		fmt.Scan(&p)
		ps[i] = p
	}
	count := 0
	for i := 0; i < 1 << uint(n); i++ {
		switches := make([]int, 0)
		for j := 0; j < n; j++ {
			if 1 & (uint(i) >> uint(j)) == 1 {
				switches = append(switches, j + 1)
			}
		}
		isAllLightUp := true
		for j := 0; j < m; j++ {
			isAllLightUp = isAllLightUp && isLightUp(arr[j], switches, ps[j])
		}
		if isAllLightUp {
			count++
		}
	}
	fmt.Println(count)
}

func isLightUp(lamp, switches []int, ps int) bool {
	count := 0
	for _, i := range lamp {
		for _, j := range switches {
			if i == j {
				count++
				break
			}
		}
	}
	return count % 2 == ps
}

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

int main(){
  int n, m;
  int64_t k;
  cin >> n >> m >> k;
  
  vector<int64_t> a(n+1);
  vector<int64_t> b(m+1);
  
  for (int i=0; i<n; i++){
    cin >> a.at(i+1);
    a.at(i+1) += a.at(i);
  }
  
  for (int i=0; i<m; i++){
    cin >> b.at(i+1);
    b.at(i+1) += b.at(i);
  }
  
  int ans = 0;
  
  for (int i=0, j=m; i<=n; i++){
    if (a.at(i) >k) break;
    while (a.at(i)+b.at(j) >k) j--;
    ans = max(i+j, ans);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 1;

    rep(i, n) {
        ans *= 10;
        ans %= mod;
    }

    ll minus = 1, minus2 = 1;
    rep(i, n) {
        minus *= 9;
        minus %= mod;

        minus2 *= 8;
        minus2 %= mod;
    }
    minus *= 2;
    minus %= mod;

    cout << (ans - minus + minus2 + mod) % mod << "\n";

    /*cout << ans << endl;
    cout << minus << endl;
    cout << minus2 << endl;*/
    return 0;
}

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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

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

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 200000;

int n, x;
ll s[N + 5];

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

    read(n), read(x);
    for(int i = 1; i <= n; ++i) {
        read(s[i]), s[i] += s[i-1];
    }

    ll ans = (ll) 1e18;
    for(int i = 1; i <= n; ++i) {
        ll res = 1ll * (i + n) * x;

        int cost = 5;
        for(int j = n; j >= 1 && res < ans; j -= i) {
            int lst = std::max(j-i, 0);
            res = res + 1ll * cost * (s[j] - s[lst]);
            if(j != n) cost += 2;
        }
        chkmin(ans, res);
    }
    printf("%lld\n", ans);

    return 0;
}


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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

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

map<int,int> primeFactorization(int n){
    map<int,int> ret;
    int i=2;
    while(i*i<=n){
        if(n%i){
            i++;
            continue;
        }
        n/=i;
        ret[i]++;
    }
    if(n!=1)ret[n]++;
    return ret;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;

    int n;
    cin>>n;

    map<int,int> mp=primeFactorization(n);
    int ans=0;
    for(auto it:mp){
        int cnt=1;
        while(it.second>=cnt){
            it.second-=cnt;
            cnt++;
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const LL INF = 123456789012345;

int N;
LL p[123456];
vector<int>G[123456];
int par[123456];
vector<int>child[123456];
void dfs(int x,int las){
	par[x] = las;
	for(int nx : G[x]){
		if(nx != las){
			dfs(nx,x);
			child[x].push_back(nx);
		}
	}
}

bool visit[123456][2];
LL memo[123456][2];
vector<LL>diff[123456];
LL dp(int x,int f){
	if(visit[x][f])return memo[x][f];
	visit[x][f]=true;
	LL res=p[x];
	//dp(x,0) dp(x,1) 共通
	for(int ch:child[x]){
		res+=max(dp(ch,0)-2,0LL);
		if(f){
			//dp(x,1)のみ
			diff[x].push_back(max(dp(ch,1)-1,0LL) - max(dp(ch,0)-2,0LL));
		}
	}
	if(f){
		sort(diff[x].rbegin(),diff[x].rend());
		if(!diff[x].empty()){
			res += diff[x][0];
		}
	}
	return memo[x][f] = res;
}

bool visit2[123456][2];
LL memo2[123456][2];
LL ep(int x,int f){
	if(visit2[x][f])return memo2[x][f];
	visit2[x][f] = true;
	//dp(親,f) without x を取得
	if(x == 0){
		return memo2[x][f] = 0;
	}
	LL rawsum = dp(par[x],0);
	LL ep0=ep(par[x],0);
	LL ep1=ep(par[x],1);
	LL pdif = max(ep1-1,0LL)-max(ep0-2,0LL);
	//diff[par[x]].push_back(max(ep1,0)-max(ep0,0));
	//sort(diff[par[x]].rbegin(),diff[par[x]].rend());
	rawsum += max(ep0 - 2,0LL);
	if(f){
		if(pdif >= diff[par[x]][0]){
			//親へのdifが一番の時、それを足す。この時、これが削除されることはあり得ない
			rawsum += pdif;
			rawsum -= max(dp(x,0) - 2,0LL);
		}else if(max(dp(x,1)-1,0LL)-max(dp(x,0)-2,0LL) == diff[par[x]][0]){
			//自分が不幸にして一番になってしまった場合、難しいことをする
			if(diff[par[x]].size()==1){
				//自分しかいないので、max(ep(par[x],1)-2,0LL) + p[par[x]]が答え
				rawsum = max(ep1-1,0LL) + p[par[x]];
			}else{
				rawsum -= max(dp(x,0)-2,0LL);
				rawsum += diff[par[x]][1];
			}
		}else{
			//一番ではないときは難しくないのでうれしい
			rawsum -= max(dp(x,0)-2,0LL);
			rawsum += diff[par[x]][0];
		}
	}else{
		rawsum -= max(dp(x,0)-2,0LL);
	}
	return memo2[x][f] = rawsum;
}

int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>p[i];
	}
	for(int i=0;i<N-1;++i){
		int u,v;
		cin>>u>>v;
		--u;--v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	for(int i=0;i<N;++i){
		for(int f=0;f<2;++f){
			dp(i,f);
		}
	}
	vector<LL>zero,diffs;
	for(int i=0;i<N;++i){
		LL ep0=ep(i,0);
		LL ep1=ep(i,1);
		zero.push_back(max(ep0-2,0LL));
		diffs.push_back(max(ep1-1,0LL)-max(ep0-2,0LL));
	}
	LL ans = -INF;
	for(int i=0;i<N;++i){
		//diff[i].push_back(diffs[i]);
		//sort(diff[i].rbegin(),diff[i].rend());
		LL rawsum = dp(i,0);
		rawsum += zero[i];
		LL DPi0 = rawsum;//この時のrawsumがDP(i,0)
		LL chmax = (diff[i].size() > 0) ? diff[i][0] : 0;
		LL almax = max(chmax,diffs[i]);
		rawsum += almax;
		LL DPi1 = rawsum;//この時のrawsumがDP(i,1)
		ans = max(ans,DPi0);
		ans = max(ans,DPi1);
		//cerr <<dp(i,0)<<" " <<dp(i,1) <<" "<<ep(i,0) << " " << ep(i,1) << endl;
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 39936
#include<stdio.h>

int A[100000],n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while ( left < right ) {
    mid = (left + right) / 2;
    if (key == A[mid] ) return 1;
    if ( key > A[mid] ) left = mid + 1;
    else if ( key < A[mid] ) right = mid;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;

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

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &k);
    if ( binarySearch( k ) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2080
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {


	string s;
	cin >> s;

	rep(i, 0, s.size()) {
		if (i % 2 == 0) {
			cout << s[i];
		}
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 512
n, m , c = map(int, input().split())
b = [int(i) for i in input().split()]
a = [[int(x) for x in input().split()] for _ in range(n)]
ans = 0
for i in a:
    su = 0
    for j in range(len(i)):
        su += i[j] * b[j]
    su += c
    if su > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
while True:
    line = list(map(int,input().split()))
    Vertical = line[0]
    Horizontal = line[1]
    if Vertical ==0:
        break
    print("#"*Horizontal)
    for i in range(line[0]-2):
        print("#",end = "")
        print("."* (line[1]-2),end="" )
        print("#")
    print("#"*Horizontal)
    print()


Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;

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

    if( S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
         cout << "Bad" << endl;
         return 0;
    }
    else{
        cout << "Good" << endl;
        return 0;
    }
}
   


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner cin = new Scanner(System.in);
		long N = cin.nextLong();
		long K = cin.nextLong();
		
		long min = N;
		
		if(N<K) {
			if(min>Math.abs(min-K)) min = Math.abs(min-K);
		}
		else {
			if(N%K==0) {
				min = 0;
			}else{
				min = N%K;
				if(min>Math.abs(min-K)) min = Math.abs(min-K);
			}
		}
		
		System.out.println(min);

	}

}


Measured memory_bytes: 23764
#include <stdio.h>


int main(void){
    int a, b, k, i;
    scanf("%d %d %d", &a, &b, &k);
    for(i = k ; i > 1 ; i -= 2){
        if(a % 2 == 1){
            a--;
        }
        a = a / 2;
        b += a;
        if(b % 2 == 1){
            b--;
        }
        b = b / 2;
        a += b;
    }
    if(i == 1){
        if(a % 2 == 1){
            a--;
        }
        a = a / 2;
        b += a;
    }
    printf("%d %d\n", a, b);

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int n;
  cin>>n;
  while(n--){
    double ax,bx,cx,ay,by,cy;
    cin>>ax>>ay>>bx>>by>>cx>>cy;
    P a(ax,ay),b(bx,by),c(cx,cy);
    double i,j,k;
    i = abs(b-c);
    j = abs(c-a);
    k = abs(a-b);
    double r = i*j*k/sqrt( (i+j+k)*(-i+j+k)*(i-j+k)*(i+j-k) );
    double ii = i*i, jj=j*j,kk=k*k;
    double s = imag(conj(b-a)*(c-a))/2.0;
    P p = (ii*(jj+kk-ii)*a + jj*(kk+ii-jj)*b + kk*(ii+jj-kk)*c) / (16.0*s*s);
    printf("%.3lf %.3lf %.3lf\n",p.real()+0.0, p.imag()+0.0, r);
  }
  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> d)
{
    SORT(d);
    cout << d[N/2] - d[N/2-1] << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> d(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int a, b;
	int d, r;
	double f;

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

	d = a / b;
	r = a % b;
	f = (double) a / b;

	printf("%d %d %5lf\n", d, r, f);

	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    vector<lint> x(n), l(n);
    for(lint i=0; i<n; i++)  cin >> x[i] >> l[i];

    vector<lint> left(n), right(n);
    for(lint i=0; i<n; i++) {
        left[i] = x[i] - l[i];
        right[i] = x[i] + l[i];
    }

    vector<pair<lint, lint>> rl(n);
    for(lint i=0; i<n; i++) {
        rl[i] = make_pair(right[i], left[i]);
    }

    sort(begin(rl), end(rl));

    lint prev = -1e18;
    lint ans = 0;
    for(lint i=0; i<n; i++) {
        if(prev <= rl[i].second) {
            prev = rl[i].first;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner cs = new Scanner(System.in);
    int n,k;
    String s;
    n=cs.nextInt();
    k=cs.nextInt();
    cs.nextLine();
    s=cs.nextLine();
    char[] c = s.toCharArray();
    c[k-1] = Character.toLowerCase(c[k-1]);
	System.out.println(String.valueOf(c));
    
  }
}

Measured memory_bytes: 21716