akhauriyash/Code-Regression huggingface dataset:
/**
*    author:  yuya1234
*    created: 27.06.2020 16:42:53
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n;
  cin>>n;

  int x[101];
  REP(i,n)cin>>x[i];

  int sum,ans=1000000000;

  FOR(i,1,100)
  {
    sum=0;
      REP(j,n)
      {
        sum+=pow(i-x[j],2);
      }
      ans=min(ans,sum);
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int r;
	cin>>r;
	setprecision(20);
	cout<<2*PI*r;
}

Measured memory_bytes: 3800
n = int(input())
a = input()
b = input()
c = input()

ret = 0
for i in range(n):
    cnt = {}
    cnt[a[i]] = 1
    if b[i] not in cnt:
        cnt[b[i]] = 0
    if c[i] not in cnt:
        cnt[c[i]] = 0
    cnt[b[i]] += 1
    cnt[c[i]] += 1
    ret += 3 - max(cnt.values())

print(ret)


Measured memory_bytes: 3064
h,w,t = map(int,input().split())
masume = [list(input()) for _ in range(h)]

ans = 0

for i in range(2 ** h):
    for j in range(2 ** w):
        count = 0
        for k in range(h):
            if ((i >> k) & 1):
                for l in range(w):
                    if ((j >> l) & 1):
                        if masume[k][l]=="#":
                            count += 1
        if count == t:
            ans += 1

print(ans)

                    
        

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N;
  cin >> N;
	vector<int> a(N);
	rep(i,N) cin>>a[i];
	sort(a.rbegin(),a.rend());
	long int ans=0;
	rep(i,N){
	  if (i%2==0)ans+=a[i];
	  else ans-=a[i];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
 
struct node {
 
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
 
typedef struct node* Node;
Node root;
 
Node treeSearch(Node x,int k) {
  if(x == NIL || k == x-> key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else return treeSearch(x->right,k );
}
 
void insert(int k) {
   
  Node y = NIL;
  Node x = root;
  Node z; 
   
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
    
 while(x != NIL) {
    y = x;
  if(z->key < x->key)
    x = x->left;
   
  else x = x->right;
 }
  z->parent = y;
   
  if(y == NIL)
    root = z;
   
  else if(z->key < y->key)
    y->left = z;
   
  else
    y->right = z;
   
}
 
void inorder(Node u) {
   
  if(u->left != NIL)
    inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL) 
    inorder(u->right);
}
 
void preorder(Node u) {
  printf(" %d",u->key);
  if(u->left != NIL)
    preorder(u->left);
  if(u->right != NIL)
    preorder(u->right);
}
 
int main(void) {
   
  int i,n,x;
  char c[5];
   
  scanf("%d",&n);
   
  for(i=0;i<n;i++) {
  scanf("%s",c);
  if(c[0] == 'f') {
    scanf("%d",&x);
    if(treeSearch(root,x) != NIL)
      printf("yes\n");
    else printf("no\n");
  }
  else if(c[0] == 'i') {
    scanf("%d",&x);
    insert(x);
  }
  else if(c[0] == 'p') {
    if(root != NIL)  
      inorder(root);
    printf("\n");
    if(root != NIL)
      preorder(root);
    printf("\n");
     
  }
 }
return 0;
}

Measured memory_bytes: 24040
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;

void mul(int &a,int b)
{
    a=(a*b)%mod;
}

signed main()
{
    int N; cin>>N;
    vector<pair<int,bool> > v(2*N);
    for(int i=0;i<N;i++){
        int a; cin>>a;
        v[i]=make_pair(a,0);
    }       
    for(int i=0;i<N;i++){
        int b; cin>>b;
        v[N+i]=make_pair(b,1);
    }       
    sort(v.begin(),v.end());
/*          
    for(auto p:v){
        cout<<p.first<<' '<<p.second<<endl;
    }
*/  
    vector<int> num(2);
    int ans=1;
    for(auto p:v){
        int t=p.second;
        if(num[t^1]>0){
            mul(ans,num[t^1]);
            num[t^1]--;
        }else{
            num[t]++;
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<int, int>> arr;
    for(int i = 0; i < a; i++) {
        int tmp; cin >> tmp;
        arr.emplace_back(tmp, 1);
    }
    for(int i = 0; i < b; i++) {
        int tmp; cin >> tmp;
        arr.emplace_back(tmp, 2);
    }
    for(int i = 0; i < c; i++) {
        int tmp; cin >> tmp;
        arr.emplace_back(tmp, 0);
    }
    sort(begin(arr), end(arr));
    reverse(begin(arr), end(arr));

    long long ans = 0, sum = 0, cnt = 0;
    for(int i = 0; i < (int)arr.size(); i++) {
        if(x && arr[i].second == 1) {
            x--; ans = ans + arr[i].first;            
        } 
        else if(y && arr[i].second == 2) {
            y--; ans = ans + arr[i].first;
        }
        else if(arr[i].second == 0) {
            cnt++; sum = sum + arr[i].first;
        }
        if(x + y - cnt == 0) {
            ans = ans + sum;
            break;
        }
        else ;// ??? 
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <array>

using namespace std;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  int count = 0;
  for(int i = 0; i < n; i++)
  {
	int t;
	cin >> t;
	if(a <= t && t < b)
	{
	  count++;
	}
  }
  cout << n - count << endl;
}


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

int main() {
	/*
	int a = 0;//整数変数aを作る
	int b = 0;//整数変数bを作る

	cin >> a >> b;//2つの数字を受け取り、a,bに代入

	cout << a * b << endl;//a*bを出力
	*/
	/*
	string S;
	cin >> S;
	if (S[0]=='7'||S[1]=='7'||S[2]=='7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	int a = 0;
	int b = 0;
	int ans = 0;

	cin >> a >> b;

	int apb = a + b;
	int akb = a * b;
	int amb = a - b;
	ans = apb;
	if (ans < a - b) {
		ans = a - b;
	}


	if (ans < a * b) {
		ans = a * b;
	}
	cout << ans << endl;

	int N = 0;
	int R = 0;
	int Ans = 0;
	cin >> N >> R;
	if (N >=10) {
		Ans = R;
	}
	else
	{
		Ans = R + (100 * (10 - N));
	}

	cout << Ans << endl;
	*/
	int A = 0;
	cin >> A;
	cout << A + (A * A) + (A * A * A) << endl;


	return 0;
}



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

bitset<4000005> f;
int n, s, a[2005];

int main() {
	cin >> n;
	f.set(0);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		f |= (f << a[i]);
		s += a[i];
	}
	for(int i = (s+1)/2; i <= s; i++){
		if(f[i]){
			cout << i << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

int main() {
	long long n,m;
	cin >> n >> m;
	long long sum = 0;
	long long ans = 0;
	for (int i = 0; i < m; i++) {
		int data;
		cin >> data;
		sum += data;
	}
	ans = (sum > n) ? -1 : n - sum;
	cout << ans;

	return 0;
}


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

//他人の解答見た

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    ll cnt = 1;
    ll flag = -1;
    for(long long i = 0; i < n-1; i++){
        if(flag == -1){
            if(a[i] < a[i+1]){
                flag = 0;
            }else if(a[i] > a[i+1]){
                flag = 1;
            }
        }else{
            if(flag == 0 and a[i] > a[i+1]){
                flag = -1;
                cnt++;
            }else if(flag == 1 and a[i] < a[i+1]){
                flag = -1;
                cnt++;
            }
        }
    }
    
    put(cnt);
}

Measured memory_bytes: 3952
# -*- coding: utf-8 -*-
n,m,x,y = list(map(int, input().split(' ')));
xn = list(map(int, input().split(' ')));
yn = list(map(int, input().split(' ')));

xmax = max(xn)
ymin = min(yn)

# print('xmax < ymin : {} < {}'.format( xmax, ymin ) )
# print('xmax < y : {} < {}'.format( xmax, y ) )
# print('x < ymin : {} < {}'.format( xmax, y ) )

if ( xmax < ymin and xmax < y and x < ymin ):
    print( 'No War' )
else:
    print( 'War' )

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

int diff(int a,int b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}

int main()
{
    int n,a,d,r,min=1e3;
    int sum=0;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        sum+=a;
        //cout<<sum<<endl;
        arr.push_back(sum);
    }
    //for(int i=0;i<n;i++)
      //  cout<<arr[i]<<" ";
    //cout<<endl;
    int val = arr[n-1];

    for(int i=0;i<n;i++)
    {
        d = val-arr[i];
        //cout<<d<<"d"<<endl;
        r = diff(d,arr[i]);
        //cout<<r<<"r"<<endl;
        if(r<min)
            min = r;
    }
    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N;
    u64 a;
    cin >> N;

    int ans = 0;
    rep (i, N)
    {
        cin >> a;
        while ((a & 1) == 0)
        {
            ++ans;
            a >>= 1;
        }
    }

    cout << ans << "\n";
    return 0;
}



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

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using usize = std::size_t;
using namespace std;

#define rep(i, max) for(i32 i = 0; i < (i32)max; ++i)
#define loop while(true)
#define allOf(collection) collection.begin(), collection.end()

unique_ptr<string> readLine() { unique_ptr<string> line(new string()); getline(cin, *line); return line; }
template<typename T1, typename T2> pair<T1, T2> readPair() { T1 res1; cin >> res1; T2 res2; cin >> res2; readLine(); return make_pair(res1, res2);}
template<typename T> unique_ptr<vector<T>> readVector(usize num) { unique_ptr<vector<T>> list(new vector<T>(num)); rep(i, num) cin >> (*list)[i]; readLine(); return list; }
void readValues() { readLine(); }
template<typename H, typename... T> void readValues(H& head, T&&... tails){ H a; cin >> a; head = a; readValues(forward<T>(tails)...); }
void writeLine() { cout << endl; }
template<typename T> void write(const T& arg) { cout << arg; }
template<typename T> void writeLine(const vector<T>& arg){ if(arg.empty()) { writeLine(); return; } write(arg[0]); for(int i = 1; i < arg.size(); ++i){ write(" "); write(arg[i]); } writeLine(); }
template<typename T> void writeLine(const T& arg) { cout << arg << endl; }
void recursiveCombination(vector<i32>& indexes, i32 s, i32 rest, function<void(vector<i32>&)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursiveCombination(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursiveCombination(indexes, s - 1, rest - 1, f); } }
void foreachWithCombination(i32 n, i32 k, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(k); recursiveCombination(indexes, n - 1, k, f); }
void foreachWithPermutaton(i32 n, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(); indexes.reserve(n); rep(i, (usize)n) indexes.push_back(i); do f(indexes); while (next_permutation(allOf(indexes))); }
void foreachWithPermutaton(i32 n, i32 k, function<void(vector<i32>&)> f){ foreachWithCombination(n, k, [=](vector<i32>& combIndexes){ foreachWithPermutaton(k, [=](vector<i32>& permIndexes){ auto indexes = vector<i32>(); indexes.reserve(k); rep(i, (usize)k){ indexes.push_back(combIndexes[permIndexes[i]]); } f(indexes); }); }); }
void program();
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    program();
}

void program() {
    i64 x, k, d;
    readValues(x, k, d);
    x = abs(x);
    i64 neededMoveCount = x / d;
    if(neededMoveCount >= k) {
        writeLine(x - k * d);
    }
    else{
        writeLine((k - neededMoveCount) % 2 == 0 ? x - neededMoveCount * d : (neededMoveCount + 1) * d - x);
    }
}

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

char *getsn(char *, int );

int main(void)
{
	char instr[1001];
	int number[1000];
	int i=0;
	int n=0;
	int sum = 0;
	while(1){
		getsn(instr, 1001);
		if(instr[0] == '0' && instr[1] == 0) break;
		i=0; sum = 0;
		while(instr[i] != 0){
			sum += instr[i] - 0x30;
			i++;
		}
		number[n] = sum;
		n++;
	}
	
	for(i = 0; i < n; i++){
		printf("%d\n", number[i]);
	}
	
	return 0;
}

char *getsn(char *s, int n){
	if(fgets(s, n, stdin) == NULL) return NULL;
	char *ln = strchr(s, '\n');
	if(ln) *ln = 0;
	else
	while(1){
		int c = getchar();
		if(c == '\n' || c == EOF) 
			break;
	}
	return s;
}



Measured memory_bytes: 2108
import scala.io.StdIn

object Main extends App {
  val Array(n, d)  = StdIn.readLine().split(" ").map(_.toInt)
  var a :Array[Array[Int]] = Array.fill[Array[Int]](n)(Array.empty)
  var ans = 0
  (1 to n).foreach {i =>
    a(i - 1) =  StdIn.readLine().split(" ").map(_.toInt)
  }

  for (i <- 0 until n - 1) {
    for (j <- i + 1 to n - 1) {
      var ret = Math.sqrt((a(i) zip  a(j)).map {l => Math.pow(l._1 - l._2, 2)}.sum)
      if (ret - ret.ceil == 0) ans = ans + 1
    }
  }
  println(ans)


}
  



Measured memory_bytes: 27196
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int INF = 1<<30;

struct data{
    int i, j, dir;
    bool operator<(const data other) const{return true;}
};

#define inRange(x,a,b) (a <= x && x < b)
int di[4] = {0,1,0,-1};
int dj[4] = {1,0,-1,0};

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        char mat[h][w];
        int dp[4][h][w], c[4];
        for(int i = 0; i < h*w; i++){
            cin >> mat[i/w][i%w];
            for(int j = 0; j < 4; j++)  dp[j][i/w][i%w] = INF;
        }
        for(int i = 0; i < 4; i++)  cin >> c[i];
        priority_queue<pair<int,data>> pq;
        pq.push({-0, data({0, 0, 0})});
        int ans;
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            int cost = -p.first, i = p.second.i, j = p.second.j, dir = p.second.dir;
            if(dp[dir][i][j] <= cost)   continue;
            dp[dir][i][j] = cost;
            if(i == h-1 && j == w-1){
                ans = cost;
                break;
            }
            for(int k = 0; k < 4; k++){
                int way = (dir+k)%4;
                int ni = i+di[way], nj = j+dj[way], ncost = cost;
                if(!inRange(ni,0,h)||!inRange(nj,0,w))  continue;
                if(k != mat[i][j]-'0')    ncost += c[k];
                if(dp[way][ni][nj] > ncost)  pq.push({-ncost, data({ni,nj,way})});
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
# -*- coding: utf-8 -*-

list_size = int(input())
num_list = [int(i) for i in input().split()]
# 昇順ソート
num_list2 = sorted(num_list)
# 中央値候補
center_left = num_list2[int(list_size / 2) - 1]
center_right = num_list2[int(list_size / 2)]

for i in range(list_size):
	# 除く値が左寄り(小さい)なら右、右寄り(大きい)なら左
	if num_list[i] <= center_left:
		print(center_right)
	else:
		print(center_left)

Measured memory_bytes: 25228
#include <iostream>
#include <vector>
#include <random>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int a; cin >> a;
    int l = a/100;
    int r = a%100;
    if (1 <= l && l <= 12)
    {
        if (1 <= r && r <= 12)
        {
            cout << "AMBIGUOUS\n";
        } else {
            cout << "MMYY\n";
        }
    } else {
        if (1 <= r && r <= 12)
        {
            cout << "YYMM\n";
        } else {
            cout << "NA\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())
found=[]
now="zzzzzzzzz"

while len(found)<k:
    now="zzzzzzzzzz"
    for i in range(len(s)):
        c=s[i]
        f=1
        while c in found and i+f<len(s):
            c+=s[i+f]
            f+=1
        if not c in found:
            now=min(c,now)
        
    found.append(now)
print(found[-1])

Measured memory_bytes: 9172
#include<iostream>
#include<cstdio>
#define M 1000001
using namespace std;

int main(){
    int n;
    cin >> n;
    int x, max, min;
    max = -M;
    min = M;
    long long sum = 0;

    for(int i = 0; i < n; i ++){
        cin >> x;
        min = (min > x)?x:min;
        max = (max < x)?x:max;
        sum += x;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>

using namespace std;

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

	int prices[101] = {0};
	for (int i = 1; i <= 25; ++i)
		prices[i*4] = 1;
	for (int i = 1; i <= 14; ++i)
		prices[i*7] = 1;
	for (int i = 1; i < 25; ++i)
	{
		for (int j = 1; j < 14; ++j)
		{
			int p = i*4 + j*7;
			if (p <= 100)
				prices[p] = 1;
		}
	}

	if (prices[N] == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main()
{	
	int n;
	string s;
	set<string>S;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		S.insert(s);
	}
	int ans=S.size();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19200
import itertools
n,m,q=map(int,input().split())
abcd=[tuple(map(int,input().split())) for _ in range(q)]
h=[]
for i in range(1,m+1):
    h.append(i)
ans=0
for j in itertools.combinations_with_replacement(h,n):
    temp=0
    for a,b,c,d in abcd:
        if j[b-1]-j[a-1]==c:
            temp+=d 
    ans=max(ans,temp)
print(ans)

Measured memory_bytes: 73412
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int A, B;
    char op;
    cin >> A >> op >> B;

    cout << A + (op=='+' ? B : (-B)) << endl;


    return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;

  vector<vector<char>> vec(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  vector<vector<int>> count(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char cha=vec.at(i).at(j);
      if (cha == '#'){
          int x=i;
          int y=j;
          if (x+1<H) count.at(x+1).at(y)+=1;
          if (x-1>=0) count.at(x-1).at(y)+=1;
          if (y+1<W) count.at(x).at(y+1)+=1;
          if (y-1>=0) count.at(x).at(y-1)+=1;
          if (x+1<H && y+1<W) count.at(x+1).at(y+1)+=1;
          if (x+1<H && y-1>=0) count.at(x+1).at(y-1)+=1;
          if (x-1>=0 && y+1<W) count.at(x-1).at(y+1)+=1;
          if (x-1>=0 && y-1>=0) count.at(x-1).at(y-1)+=1;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char cha=vec.at(i).at(j);
      if (cha == '.'){
          cout << count.at(i).at(j); 
      }
      else{
          cout << "#" ;
      }
      if (j==W-1) cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N-1) cin >> C[i];
	int cnt = 0;
	int prev = N;
	rep(i, N) {
		if (A[i]-1 == prev+1) cnt += C[prev];
		cnt += B[i];
		prev = A[i]-1;
	}
	cout << cnt << endl;




	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    int rot = (x*2 == w && y*2 == h) ? 1 : 0;
    cout << (float)(w * h) / 2.0 << " " << rot << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int N;
    cin >> N;
    vector<ll> AList(N);
    for (int i=0; i<N; i++) {
        ll tmp;
        cin >> tmp;
        if (tmp == 0) {
            cout << 0 << endl;
            return 0;
        }
        AList[i] = tmp;
    }

    // resolve
    ll ans = AList[0];
    int result_flag = -1;
    for (int i=1; i<N; i++) {
        ll tmp = AList[i];
        if (log10(ans)+log10(tmp)>18) {
            cout << -1 << endl;
            return 0;
        }
        ans *= tmp;
    }

    // output
    if (ans > 1000000000000000000 ) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
const int maxn = 2e5 + 10;
int tot, n;
int fa[maxn], g[maxn], dep[maxn], siz[maxn], L[maxn], R[maxn], res[maxn], ans[maxn];
vector<int> E[maxn];
void dfs(int x)
{
	g[x] = max(fa[x], g[fa[x]]);
	dep[x] = dep[fa[x]] + 1;
	siz[x] = 1;
	L[x] = ++tot;
	for(auto v : E[x])
		if(v != fa[x])
		{
			fa[v] = x;
			dfs(v);
			siz[x] += siz[v];
		}
	R[x] = tot;
}
void del(set<int> & s, int x)
{
	auto it = s.find(x);
	if(it == s.end()) return;
	s.erase(it);
	for(auto v : E[x])
		if(v != fa[x])
			del(s, v);
}
void merge(set<int> & sa, set<int> & sb)
{
	if(sa.size() < sb.size()) swap(sa, sb);
	while(!sb.empty())
	{
		sa.insert(*sb.begin());
		sb.erase(sb.begin());
	}
}
set<int> dfs2(int x)
{
	set<int> ret;
	for(auto v : E[x])
		if(v != fa[x])
		{
			auto tmp = dfs2(v);
			merge(ret, tmp);
		}
	ret.insert(x);
	while(!ret.empty() && *ret.rbegin() > g[fa[x]])
		del(ret, *ret.rbegin());
	res[x] = ret.size();
	return ret;
}
void dfs3(int x)
{
	ans[x] = ans[fa[x]] - res[x] + 1;
	for(auto v : E[x])
		if(v != fa[x])
			ans[x] += res[v];
	for(auto v : E[x])
		if(v != fa[x])
			dfs3(v);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i < n; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1);
	dfs2(1);
	dfs3(1);
	for(int i = 2; i <= n; ++i) printf("%d ", ans[i] - 1);
	return 0;
}

Measured memory_bytes: 58376
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

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

int main(){
    int n,k;
    cin >> n >> k;
    set<int> s;

    rep(i,0,k){
	int d;
	cin >> d;
	rep(j,0,d){
	    int a;
	    cin >> a;
	    s.it(a);
	}
    }
    P(n-sz(s));
    return  0;
}


Measured memory_bytes: 3632
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int a, b, ans = -1;
	cin >> a >> b;
	for(int i = b*10; i < b*10+10; i++) {
		if(ans>0) break;
		if(int(double(i*0.08)+EPS)==a) ans=i;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
    int n, m, c;
    int A[100][100], B[100];

    cin >> n >> m >> c;

    for (int i = 0; i < m; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> A[i][j];
        }
    }

    int cnt = 0;

    for (int i = 0; i < n; ++i) {
        int sum = 0;
        for (int j = 0; j < m; ++j) {
            sum += A[i][j] * B[j];
        }
        if (sum+c > 0) { cnt++; }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Data{
	int fee,num_load;
};

struct Info{
	Info(){
		town = rest_count = total_cost = 0;
	}
	Info(int arg_town,int arg_rest_count,int arg_total_cost){
		town = arg_town;
		rest_count = arg_rest_count;
		total_cost = arg_total_cost;
	}
	bool operator<(const struct Info &arg) const{
		return total_cost > arg.total_cost;
	};
	int town,rest_count,total_cost;
};

int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	int** dp;
	dp = new int*[N+1];
	for(int i = 1; i <= N; i++){
		dp[i] = new int[N+1];
		for(int k = 0; k <= N; k++)dp[i][k] = BIG_NUM;
	}

	Data data[N+1];
	for(int i = 1; i <= N; i++){
		scanf("%d %d",&data[i].fee,&data[i].num_load);
	}

	vector<int> V[N+1];
	int from,to;

	for(int i = 0; i < K; i++){
		scanf("%d %d",&from,&to);
		V[from].push_back(to);
		V[to].push_back(from);
	}

	priority_queue<Info> Q;

	for(int i = 0; i < V[1].size();i++){
		if(dp[V[1][i]][data[1].num_load-1] > data[1].fee){
			dp[V[1][i]][data[1].num_load-1] = data[1].fee;
			Q.push(Info(V[1][i],data[1].num_load-1,dp[V[1][i]][data[1].num_load-1]));
		}
	}

	while(!Q.empty()){

		if(Q.top().total_cost > dp[Q.top().town][Q.top().rest_count]){
			Q.pop();
		}else{
			if(Q.top().rest_count > 0){
				for(int i = 0; i < V[Q.top().town].size();i++){
					if(dp[V[Q.top().town][i]][Q.top().rest_count-1] > Q.top().total_cost){
						dp[V[Q.top().town][i]][Q.top().rest_count-1] = Q.top().total_cost;
						Q.push(Info(V[Q.top().town][i],Q.top().rest_count-1,Q.top().total_cost));
					}
				}
			}

			//?????????????????´???
			for(int i = 0; i < V[Q.top().town].size();i++){
				if(dp[V[Q.top().town][i]][data[Q.top().town].num_load-1] > Q.top().total_cost+data[Q.top().town].fee){
					dp[V[Q.top().town][i]][data[Q.top().town].num_load-1] = Q.top().total_cost+data[Q.top().town].fee;
					Q.push(Info(V[Q.top().town][i],data[Q.top().town].num_load-1,dp[V[Q.top().town][i]][data[Q.top().town].num_load-1]));
				}
			}
			Q.pop();
		}
	}

	int ans = BIG_NUM;
	for(int i = 0; i <= N; i++)ans = min(ans,dp[N][i]);

	printf("%d\n",ans);

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;

    vll a(n), b(n);
    REP(i, n)cin >> a[i] >> b[i];

    vll diff;
    ll sum = 0;
    REP(i, n) {
        sum += a[i];
        ll l= a[i] - b[i];
        if (l > 0)
			diff.push_back(b[i]);
	}
    ll ans;
    if (diff.size() != 0) {
        sort(ALL(diff));
        ans = sum - diff[0];
    }
    else
        ans = 0;
    cout << ans << endl;




}




Measured memory_bytes: 3884
#include <cfloat>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N, ans;
	cin >> N;
	vector<double> a(N);
	double b = 0.0, c = DBL_MAX;
	for (double& i : a) {
		cin >> i;
		b += i;
	}
	for (int i = 0; i < N; ++i) {
		if (c > fabs(a[i] - b / N)) {
			ans = i;
			c = fabs(a[i] - b / N);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int n,m;
int k3[22];

int main(void){
  k3[0] = 1;
  for(int i = 1; i <= 15; i++) k3[i] = k3[i-1]*3;

  while(cin >> n >> m && n){
    queue<int> que[3];
    for(int i = 0; i < 3; i++){
      int k;
      cin >> k;
      for(int j = 0; j < k; j++){
	int d;
	cin >> d;
	que[i].push(d);
      }
    }


    int s = 0;
    int c = 0;
    for(int i = n-1; i >= 0; i--){
      int j;
      for(j = 0; que[j].empty() || n-i != que[j].front(); j++);
      que[j].pop();
      int d = abs(j-s);
      if(d == 1){
	c += k3[i];
	s = abs(s-2);
      }else if(d == 2){
	c += k3[i]*2;
      }
    }

    int res = min(c,k3[n]-1-c);
    if(res > m) cout << -1 << endl;
    else cout << res << endl;
  }
}

Measured memory_bytes: 1200
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(){
    
    long long int i,j,n,res = 0;
    cin >> n;
    long long int a[n];
    long long int suff[n];
    for(i = 0;i<n;i++) cin >> a[i];
    for(i = n-1;i>=0;i--){
        if(i == n-1) suff[i] = a[i];
        else suff[i] = suff[i+1] + a[i];
    }
    for(i = 0;i<n-1;i++) res = ((res % MOD) + (((a[i] % MOD) * (suff[i+1] % MOD)) % MOD)) % MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6724
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = scanner.nextInt();
            y[i] = scanner.nextInt();
        }
        double ans = 0.0;
        for (int j = 0; j < N; j++) {
            for (int i = j + 1; i < N; i++) {
                ans += dist(x[j], x[i], y[j], y[i]);
            }
        }
        double n = N / (double)2;

        System.out.println(ans / n);

    }

    private double dist(int x1, int x2, int y1, int y2) {
        return Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
    }
}

Measured memory_bytes: 23764
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = 1
    for ai in a:
        num *= ai

    den = sum([num // a[i] for i in range(n)])

    print(num / den)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38400
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
const int N=1e5+1;
int f[N];

using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n; cin>>n; int a[n],b[n],c[n];
     for(int i=0;i<n;i++){cin>>a[i]>>b[i]>>c[i];}

     long long int f[3][n];
     // 0 - a
     // 1 - b
     // 2 - c

     for(int i=0;i<3;i++)
     {
         for(int j=0;j<n;j++)
         {
             f[i][j]=0;
         }
     }

     f[0][0]=a[0];
     f[1][0]=b[0];
     f[2][0]=c[0];
    for(int i=1;i<n;i++)
    {
        f[0][i] = max(f[1][i-1],f[2][i-1])+a[i];
        f[1][i] = max(f[2][i-1],f[0][i-1])+b[i];
        f[2][i] = max(f[1][i-1],f[0][i-1])+c[i];
    }
    cout<<max(max(f[0][n-1],f[1][n-1]),f[2][n-1])<<"\n";

    return 0;
}

Measured memory_bytes: 3840
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 1e5+5;
const int MOD = 1e9+7;


pair<ll,ll> dp[MSIZE];

pair<ll,ll> solve(int x,vector<vector<int>>& g) {
    if(dp[x].F!=0)    return dp[x];
    dp[x] = {1,1}; // B W
    for(int y:g[x]) {
        //ignore if visited
        if(dp[y].F!=0)  continue;   
        auto p = solve(y,g);
        dp[x].F *= p.S; // B = cw
        dp[x].F %= MOD;
        dp[x].S *= (p.F+p.S)%MOD;   // B = cw + cb
        dp[x].S %= MOD;
    }
    return dp[x];
}
int main(){

    FIO
    int n; cin>>n;
    vector<vector<int>> g(n+1);
    f(i,1,n-1) {
        int x,y; cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    auto p = solve(1,g);
    cout<<(p.F+p.S)%MOD<<endl;
    return 0;

}
    


Measured memory_bytes: 14208
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
static const bool DEBUG = false;

signed main() {
	string w; cin >> w;
	int cnt[256] = {};
	rep(i, 0, w.size()) {
		cnt[w[i]]++;
	}
	bool flag = true;
	rep(i, 0, 256) {
		if (cnt[i] % 2) {
			flag = false;
		}
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; //新しいllという型
const ll mod=1000000007; //constはずっと変更されない
 
ll powmod(ll x,ll y){ //ll型のpowmod関数を作る
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);  
  ans%=mod;
    ans=(ans+mod)%mod;//ansが負の値になった時のためにmodを足す ansが正の時は足したら大きくなりすぎるので、modで割る
    cout<<ans<<"\n";
}


Measured memory_bytes: 3612
import heapq

INF = 100000000000000000000
n, m, s, t = map(int, input().split())
s -= 1
t -= 1
aa = [[] for _ in range(n)]
bb = [[] for _ in range(n)]

for i in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    aa[u].append((a, v))
    aa[v].append((a, u))
    bb[u].append((b, v))
    bb[v].append((b, u))


def dijkstra(graph, s, mins):
    heap = []
    heapq.heappush(heap, (0, s))
    mins[s] = 0
    visited = [False] * n
    while len(heap) > 0:
        cost, cur = heapq.heappop(heap)
        if visited[cur]:
            continue
        visited[cur] = True
        for c, i in graph[cur]:
            if visited[i]:
                continue
            if mins[i] > cost + c:
                mins[i] = cost + c
                heapq.heappush(heap, (cost + c, i))

mins_a = [INF] * n
dijkstra(aa, s, mins_a)
mins_b = [INF] * n
dijkstra(bb, t, mins_b)
maxs = [0] * n
for i in range(n):
    maxs[i] = 1000000000000000 - (mins_a[i] + mins_b[i])
ans = [0] * n
ans[n - 1] = maxs[n - 1]
for i in range(n - 2, -1, -1):
    ans[i] = max(ans[i + 1], maxs[i])
for a in ans:
    print(a)


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int n;
    scanf("%d",&n);
    vector<pii> works(n);
    REP(i,n){
        int a,b;
        scanf("%d%d",&a,&b);
        works[i] = pii(b,a);
    }
    sort(ALL(works));
    int t = 0;
    REP(i,n){
        t += works[i].second;
        if(t>works[i].first){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


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


int main() {
    long long int x;
    cin>>x;
    long long int a=0;
    long long int p=100;
   long long  int y=0;
    while(a<x){
    	a=p+p/100;
    	p=a;
    	y++;
	}
	cout<<y;
    return 0;
}

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


int main(){
  string s;
  cin >> s;
  long long n,sum,migi,hidari;
  n=s.size()+1;
  vector <int> ans(n,0);

  int i;
  migi=0;
  hidari=0;
  sum=0;

  for(i=0;i<n-1;++i){
    if(s[i]=='<'){
      ans[i]=migi;
      migi=migi+1;
      ans[i+1]=migi;
    }else{
      migi=0;
    }
  }

  for(i=n;i>0;--i){
    if(s[i-1]=='>'){
      ans[i]=hidari;
      hidari=hidari+1;
      if(s[i-2]=='<' ){
      ans[i-1]=max(ans[i]+1,ans[i-2]+1);
    }else{
      ans[i-1]=hidari;
    }
  }else if(s[i-1]=='<'){
      hidari=0;
    }
  }

  for(i=0;i<n;++i){
    sum=sum+ans[i];
  }

  cout << sum << endl;
  return 0;


}


Measured memory_bytes: 2820
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  // 2の冪乗？
  // while(!(n & (n-1))){
  //   n--;
  // }
  int num = n; 
  while(num > 1) {
    num /= 2;
    z++;
  }
  for(int i = z; i>0; i--) {
    y += pow(2,i);
  }
  y++;
  OUT(y);
}

Measured memory_bytes: 512
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef unsigned long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[100] = {};
	//ll b[200] = {};
	//ll v[3] = {};
	ll *c, *s, *n;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	
	cin >>N;

	rep(i, 0, N) {
		cin >> a[i];
	}
	
	max = a[0];

	rep(i, 1, N) {
		//if(max != a[i])
		max = gcd(max, a[i]);

		
	}
	
	
		cout << max << endl;
	
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256