akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    
    int h[1000];
    for(int i = 1; i < 1000;i++){
        h[i] = (i*(i + 1))/2;
    }
    
    int ans = 1;
    for(int i = 1;i < 1000;i++){
        if((h[i] - a) == (h[i + 1] - b)){
            ans = h[i] - a;
            break;
        }
    }
    
    cout << ans << endl;
}


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

bool check(long long a, long long b, long long mid, int &x){
    if (mid == 1 && a == 1) return 1;
    if (mid < a){
        return ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1) < a * b;}
        
    if (mid < b){
        long long rep_1, rep_2;
        if ((mid + 1) / 2 < a) rep_1 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
        else rep_1 = (a - 1)*(mid - a + 2);
        if ((mid + 2) / 2 < a + 1) rep_2 = (a + 1)*(mid - a + 1);
        else if ((mid + 2) / 2 > mid) rep_2 = mid * 2;
        else rep_2 = ((mid + 2) / 2) * (mid - (mid + 2) / 2 + 2);
        if ((mid + 1) < a * b) x++;
        return max(rep_1, rep_2) < a * b;
    }
    if (mid - b > a){
        long long rep_1, rep_2, rep_3;
        if ((mid + 1) / 2 < a) rep_1 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
        else rep_1 = (a - 1)*(mid - a + 2);
        if ((mid + 2) / 2 < a + 1) rep_2 = (a + 1)*(mid - a + 1);
        else if ((mid + 2) / 2 > mid - b) rep_2 = mid * 2;
        else rep_2 = ((mid + 2) / 2) * (mid - (mid + 2) / 2 + 2);
        if ((mid + 1) / 2 < mid - b) rep_3 = (b - 1)*(mid - b);
        else if ((mid + 1) / 2 > mid) rep_3 = mid;
        else rep_3 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
        return max({rep_1, rep_2, rep_3}) < a*b;
    }
    if (mid - b == a){
        long long rep_1, rep_2;
        if ((mid + 1) / 2 < a) rep_1 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
        else rep_1 = (a - 1)*(mid - a + 2);
        if ((mid  + 1) / 2 < a + 1) rep_2 = (a + 1)*(mid - a);
        else if ((mid + 1) / 2 > mid) rep_2 = mid;
        else rep_2 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
        return max(rep_1, rep_2) < a*b;
    }
    long long rep_1, rep_2, rep_3;
    if ((mid + 1) / 2 < mid - b) rep_1 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
    else rep_1 = (b + 1)*(mid - b);
    if (mid / 2 < mid - b + 1) rep_2 = (b - 1)*(mid - b + 1);
    else if (mid / 2 > a - 1) rep_2 = (a - 1)*(mid - a + 1);
    else rep_2 = (mid / 2) * (mid - mid / 2 + 1);
    if ((mid + 1) / 2 < a + 1) rep_3 = (a + 1)*(mid - a);
    else if ((mid + 1) / 2 > mid) rep_3 = mid;
    else rep_3 = ((mid + 1) / 2) * (mid - (mid + 1) / 2 + 1);
    return max({rep_1, rep_2, rep_3}) < a*b;
}

int main(){
    int q;
    cin >> q;
    long long a, b;
    int x;
    for (int i = 0; i < q; i++){
        cin >> a >> b;
        if (a * b <= 2){
            cout << 0 << endl;
            continue;
        }
        if (a > b) swap(a, b);
        long long ng = a + b;
        long long ok = - 1;
        while (abs(ok - ng) > 1){
            long long mid = (ok + ng) / 2;
            if (check(a, b, mid, x)) ok = mid;
            else ng = mid;
        }
        x = 0;
        check(a, b, ok, x);
        if (ok > a) ok--;
        cout << ok + x << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> r(h,vector<int>(w)),d(h,vector<int>(w)),u(h,vector<int>(w)),l(h,vector<int>(w));
    vector<string> s(h);
    rep(i,h){
        cin >> s[i];
    }

    rep(i,h){
        rep(j,w){
            if( s[i][j] == '#')continue;
            if(i == 0){
                u[i][j] = 1;
            }
            else{
                u[i][j] = u[i-1][j]+1;

            }

            if(j == 0){
                l[i][j] = 1;

            }
            else{
                l[i][j] = l[i][j-1]+1;
            }
                
            
            
            

        }
    }
    for(int i = h-1;i>=0;i--){
        for(int j = w-1;j >= 0;j--){
            if(s[i][j] == '#')continue;
            if(i == h-1){
                d[i][j] = 1;
            }
            else{
                d[i][j] = d[i+1][j]+1;

            }
            if(j == w-1){
                r[i][j] = 1;
            }
            else{
                r[i][j] = r[i][j+1]+1;

            }
            
           
            
            
            
        }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            ans = max(ans,r[i][j]+l[i][j]+u[i][j]+d[i][j]-3);
       
        }

    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 67200
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
    
        if ((a + b) - c >= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22356
program V1002;
 var
  a:array[0..100001] of longint;
  i,n:longint;
  s,s1:int64;
 procedure haha(l,r:longint);
  var
   o,p,m,t:longint;
  begin
   o:=l;
   p:=r;
   m:=a[(l+r) div 2];
   repeat
    while a[o]<m do inc(o);
    while a[p]>m do dec(p);
    if o<=p then
     begin
      t:=a[o];
      a[o]:=a[p];
      a[p]:=t;
      inc(o);
      dec(p);
     end;
   until o>p;
   if o<r then haha(o,r);
   if l<p then haha(l,p);
  end;
 begin
  readln(n);
  for i:=1 to n do
   read(a[i]);
  readln;
  haha(1,n);
  i:=n;
  while i>=2 do
   if a[i]=a[i-1] then
    begin
     if s=0 then s:=a[i]
            else if s1=0 then s1:=a[i];
     dec(i,2);
    end
                  else dec(i,1);
  writeln(s*s1);
 end.


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

int main(){

  int N,M;
  int T[100],P[100],X[100],S[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >>  T[i];
  }
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> P[i] >> X[i];
    //cout << P[i] <<  X[i]<< endl;
  }

  for(int i=0; i<M; i++){
    int c = 0;
    for(int j=0; j<N; j++){
      //cout << S[i] << T[j]<<P[i] << endl;
      if(j+1 == P[i]){
        c += X[i];
      }
      else{
        c += T[j];
      }
    }
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  long long map[100003];
  long long br[100003];
  for (int i = 0; i < N + 1; i ++) cin >> map[i];
  for (int i = 0; i < N; i ++) cin >> br[i];
  long long ans = 0;
  ans += min(map[0], br[0]);
  long long x = min(map[0], br[0]);
  for (int i = 1; i < N; i ++) {
    x = min(map[i], br[i - 1] - x);
    ans += x;
    x = min(map[i] - x, br[i]);
    ans += x;
  }
  x = min(map[N], br[N - 1] - x);
  ans += x;
  cout << ans << endl;
}


Measured memory_bytes: 1792
# C - GeT AC
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
	t[i + 1] = t[i] + (1 if s[i : i + 2] == 'AC' else 0)
for i in range(q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
using namespace std;

void test() {
    int s, w;
    cin >> s >> w;
    cout << (s > w ? "safe\n" : "unsafe\n");
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


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



int main() {
   int x;
   cin >> x;
   for (int i=0; i<=5000; i++) {
      for (int j=-2500; j<=2500; j++) {
         if (pow(i,5) - pow(j,5) == x) {
            cout << i << " " << j << endl;
            return 0;
         }
      }
   }
   return 0;
}

Measured memory_bytes: 4180
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	lli n,m; cin >> n >> m;
	lli s = n;
	lli c = m;

	lli  ans = 0;
	if (n * 2 < m){
		ans += n;
		m -= 2 * n;
		ans += m / 4;
	}else{
		ans += m / 2;	
	}
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 100010;
int n, a[maxn], dp[maxn];
int main()
{
    read(n);
    rep(i, 1, n) read(a[i]);
    memset(dp, 0x3f, sizeof(dp));
    dp[1] = 0;
    rep(i, 1, n) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
    printf("%d\n", dp[n]);
    return 0;
}

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

#define MOD 1000 
typedef long long ll;

int n;
ll a[100005][3]; //points
ll dp[100005][3];

int main()
{
	cin>>n;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	
	for(int j=0;j<3;j++){
		dp[0][j]=a[0][j];
	}
	
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k){
					dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
				}
			}
		}
	}
	
	ll ans=0;
	for(int j=0;j<3;j++){
		ans=max(ans,dp[n-1][j]);
	}
	
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long  ll ;
#pragma GCC optimize "trapv"
#define     endl                        '\n'
#define     fi                          first
#define     sec                         second
#define     pb                          push_back
#define 	fio 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define 	sz(x) 						(int)x.size()
void solve(){
    fio;
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
    return;

}
int main(){
    fio;
    
    int test;
    // cin>>test;
    test=1;
    while(test--){
        solve();
    }
    return 0;
}
 


Measured memory_bytes: 3656
def check(n, H, A, B):
    s = 0
    for h in H:
        s += max(-(-(h - n*B) // (A-B)), 0)
    if s <= n:
        return True
    else:
        return False


def main():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    left = 0
    right = int(1e9)
    while left < right:
        center = (left + right) // 2
        if check(center, H, A, B):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()


Measured memory_bytes: 49752
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

hw = raw_input()
hw = hw.split()
h,w = map(int,hw)

c = np.zeros([10,10],int)
for i in range(10):
    line = raw_input()
    line = line.split()
    c[i] = map(int,line)

#a = np.zeros([h,w],dtype=int)
#for i in range(h):
#    line = raw_input()
#    line = line.split()
#    a[i] = map(int,line)

suji_num = np.zeros([10],int)
for i in range(h):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    for j in range(10):
        num = line.count(j)
        suji_num[j] += num

maryoku = np.zeros([10],int)

for i in range(10):
    maryoku[i] = c[i,1]

i = 1
while i < max(maryoku)-1:
    #print maryoku
    for j in range(10):
        if maryoku[j] == i:
            for k in range(10):
                keiyum = c[k,j]+i
                if keiyum < maryoku[k]:
                    maryoku[k] = keiyum
    i += 1

ans = 0
for i in range(10):
    ans += suji_num[i] * maryoku[i]

print ans


Measured memory_bytes: 19436
# -*- coding: utf-8 -*-
n = map(int, input().split())
L = list(map(int,input().split()))

sum = 0
for m in range(len(L)):
  if m >= 2 and m <= len(L)-1:
    if (L[m-2] < L[m-1] < L[m]) or (L[m-2] > L[m-1] > L[m]):
      sum += 1
print(sum)

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


int main(){
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 1; i <= N; i += 2){
    int sum = 0;
    for(int j = 1; j <= i; j += 2){
      if(i % j == 0){ sum++; }
    }
      if(sum == 8){ ans++; }
  }

  cout << ans << endl;
 return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, m;
    int k[10];
    int s[10][10];
    int p[10];

    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
            cin >> s[i][j];
    }
    for (int i = 0; i < m; i++)
        cin >> p[i];

    int cnt = 0;
    for (int i = 0; i < pow(2, n); i++)
    {
        int tmp[10] = {};
        for (int j = 0; j < n; j++)
        {
            for (int kk = 0; kk < m; kk++)
            {
                for (int l = 0; l < k[kk]; l++)
                {
                    if (s[kk][l] == j + 1)
                    {
                        // cout << kk << "," << l << endl;
                        tmp[kk] += (i >> j) & 1;
                    }
                }
            }
        }
        // cout << "-" << endl;
        // for (int j = 0; j < m; j++)
        // cout << tmp[j] << " ";
        // cout << endl;
        bool f = true;
        for (int j = 0; j < m; j++)
        {
            if (tmp[j] % 2 != p[j])
                f = false;
        }
        if (f)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
//
// Created by karayuu on 2018-12-24.
//

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;

        if (h == 0 && w == 0) {
            break;
        }

        string s;
        for (int i = 1; i <= w; i++) {
            s += "#";
        }
        cout << s << endl;

        for (int i = 1; i <= h - 2; i++) {
            string _s;
            _s += "#";
            for (int j = 1; j <= w - 2; j++) {
                _s += ".";
            }
            _s += "#";
            cout << _s << endl;
        }

        cout << s << endl;
        cout << endl;
    }
}


Measured memory_bytes: 3160
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;
const int maxn = 21;
int n,G[maxn][maxn], dp[maxn][1<<maxn];

int dfs(const int i, const int mask)
{
    if (i == n)
        return 1;
    int& ans = dp[i][mask];
    if (-1 == ans) {
        ans = 0;
        FOR(j,0,n) if (G[i][j] && !(mask&(1<<j))) {
            ans += dfs(i+1,mask|(1<<j));
            ans %= mod;
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,n) FOR(j,0,n)
            cin >> G[i][j];
        const int ans = dfs(0,0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 172416
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  string strs[n];
  for(int i=0;i<n;i++){
  	string s;
  	cin>>s;
  	sort(s.begin(),s.end());
  	strs[i]=s;
  }
  ll c=1;
  ll ans=0;
  sort(strs,strs+n);
  for(i=1;i<n;i++){
  	if(strs[i]==strs[i-1]){
  		c++;
  	}
  	else{
  		if(c>1){
  			ans+=((c*(c-1))/2);
  			c=1;
  		}
  	}
  }
  if(c>1)
  	ans+=((c*(c-1))/2);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 5760
from collections import deque
p = 10**9+7
N,K = map(int,input().split())
G = {i:[0,[]] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a][1].append(b)
    G[b][1].append(a)
que = deque([1])
hist = [0 for _ in range(N+1)]
hist[1] = 1
A = [0 for _ in range(N+1)]
while que:
    x = que.popleft()
    for y in G[x][1]:
        if hist[y]==0:
            A[y] = 1+G[x][0]
            G[x][0] += 1
            G[y][0] += 1
            que.append(y)
            hist[y] = 1
cnt = 1
for i in range(1,N+1):
    cnt = (cnt*(K-A[i]))%p
print(cnt)

Measured memory_bytes: 85260
import java.util.Scanner;
import java.util.stream.Stream;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] list = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int N = list[0]; 
		int K = list[1]; 
		String[] S = sc.nextLine().split("");
		
		for(int i=0;i<N;i++) {
			if(i==K-1) {
				System.out.print(S[i].toLowerCase());
			}
			else {
				System.out.print(S[i]);
			}
		}
	}
}


Measured memory_bytes: 28112
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

#define pb 					push_back

template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}

template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";

	return os;
}


long long int MOD;

vector<int > adj[100002];
long long down[100002];
long long up[100002];
int par[100002];

long long dfsDown(int s,int p){
	par[s] = p;
	long long ans = 1;
	for(int node: adj[s]) {
		if(node == p)
			continue;
		ans*=(1 + dfsDown(node, s));
		ans%=MOD;
	}

	return down[s] = ans;
}


long long solveUp(int s){

	if(up[s]!=-1)
		return up[s];
	if(s == 0 || s==1)
		return up[s]=0;

	int p= par[s];
	vector<long long> a, pref, suff;
	for(int node : adj[p]) {
		if(node == par[p])
			continue;
		a.push_back(1 + down[node]);
	}

	pref.push_back(a[0]%MOD);
	for(int i =1; i<a.size(); i++ )
		pref.push_back( (pref.back() * a[i])%MOD );
	suff.push_back(a.back()%MOD);
	for(int i= (int)a.size()-2; i>=0;i--)
		suff.push_back( (suff.back() * a[i])%MOD );
	reverse(suff.begin(), suff.end());
	// cout << "s: "<<s<<", p: "<<p<<"\n";
	// cout << a<<": "<<a<<"\n";
	// cout << pref<<": "<<pref<<"\n";
	// cout << suff<<": "<<suff<<"\n";
	int in = 0;
	for(int node : adj[p]) {
		if(node == par[p])
			continue;
		long long ans = 1 + solveUp(p);
		long long l = 1;
		long long r= 1;
		if(in-1>=0)
			l = pref[in-1];
		if(in +1 <=(int)suff.size() - 1)
			r =suff[in +1];
		long long m = (l*r)%MOD;
		// cout  << node<<", :" << m<<"\n";
		ans*=m;
		ans%=MOD;
		up[node] = ans;
		in++;
	}
	return up[s];

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

	int n;
	cin >> n >> MOD;
	for(int i=1 ;i <=n-1;i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	dfsDown(1, 0);

	memset(up, -1, sizeof up);

	for(int i = 1;i<=n;i++) {
		long long ians = down[i]*(1 + solveUp(i))%MOD;
		assert(ians>=0 && ians <MOD) ;
		cout << ians << "\n";
	}


	


	return 0;
}

Measured memory_bytes: 21248
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  // 入力
  ll D; cin >> D;
  ll N = 26;
  vector<ll> c(N); rep(i,N) cin >> c[i];

  vector<vector<ll> > s(D , vector<ll>(N));
  rep(i,D) rep(j,N) cin >> s[i][j];

  rep(i,D){
    rep(j,N){
      s[i][j] -= (D - i - 1) * c[j];
    }
  }

  rep(i,D){
    ll choice = 0;
    ll tmp = 0;
    rep(j,N){
      if(tmp < s[i][j]){
        choice = j;
        tmp = s[i][j];
      }
    }
    cout << choice + 1 << endl;
  }

}


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

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

  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }

  int sum = 1;
  for (int i = 1; i < N; i++) {
    bool flg = true;
    for (int j = 0; j < i && flg; j++) {
      if (v.at(j) > v.at(i)) flg = false;
    }
    if (flg) sum++;
  }

  cout << sum << endl;
}
/*
  4
  6 5 6 8
 */

 


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

using namespace std;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {

	string s;
	int a, b, c, e;
	cin >> s;
	a = ctoi(s[1]);
	b = ctoi(s[2]);
	c = ctoi(s[3]);
	e = 7 - ctoi(s[0]);

	FOR(i, 2) {
		FOR(j, 2) {
			FOR(k, 2) {
				int A = 0;
				if (i == 0)A += a;
				else A -= a;
				if (j == 0)A += b;
				else A -= b;
				if (k == 0)A += c;
				else A -= c;
				if (A == e) {
					cout << s[0];
					if (i == 0)cout<<"+";
					else cout<<"-";
					cout << a;
					if (j == 0)cout << "+";
					else cout << "-";
					cout << b;
					if (k == 0)cout << "+";
					else cout << "-";
					cout << c << "=7" << endl;
					goto END;
				}
			}
		}
	}

END:

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int A, B;
	cin >> A >> B;
	if (A+B>=10)
		cout << "error";
	else
		cout << A+B;
}

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

using namespace std;

int main(){

  long long int n;
  cin>>n;

  long long int A[n];
  long long board=0;

  for(int i=0; i<n; i++) cin>>A[i];

  for(int i=0; i<n-1; i++){
    if(A[i]>A[i+1]){
      board+=A[i]-A[i+1];
      A[i+1]+=A[i]-A[i+1];
    }
  }

  cout<<board<<endl;
  

}


Measured memory_bytes: 5136
#include <bits/stdc++.h>
#define INF 10000000
using namespace std;

int main() {

  int n,t,minc=INF;
  cin>>n>>t;
  vector<pair<int,int>>A(n);
  for(int i=0;i<n;i++){
    cin>>A[i].first>>A[i].second;}
  for(int i=0;i<n;i++){
    if(A[i].second<=t&&minc>A[i].first) minc=A[i].first;}
  
  minc != INF ? cout<<minc<<endl :cout<<"TLE"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>

using namespace std;

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

const int MX = 200005;
const int MM = 1000000007;

pii operator-(const pii &l, const pii &r){
	return pii(l.first - r.first, l.second - r.second);
}

ll operator/(const pii &l, const pii &r){
	return (ll)l.first * r.second - (ll)l.second * r.first;
}

struct line{
	pii d;
	int a, b, c;
	bool operator<(const line &l)const{
		return d/l.d < 0;
	}
} D[MX];

int N;

struct Tree{
	int t[MX];
	int read(int x){
		int r = 0;
		while(x) r += t[x], x -= x&-x;
		return r;
	}
	void update(int x, int v){
		while(x < MX) t[x] += v, x += x&-x;
	}
} tree;

double value(line X, double v){
	return (X.c - X.b*v) / X.a;
}

double solve(line D[MX]){
	sort(D+1, D+N+1);
	double s = -1e9, e = 1e9, m;
	for(int t = 0; t < 100; t++){
		for(int i = 1; i < MX; i++) tree.t[i] = 0;
		vector<double> X;
		m = (s+e) / 2;
		for(int i = 1; i <= N; i++){
			X.push_back(value(D[i], m));
		}
		sort(X.begin(), X.end());
		ll ans = 0;
		for(int i = 1; i <= N; i++){
			int v = lower_bound(X.begin(), X.end(), value(D[i], m)) - X.begin() + 1;
			ans += tree.read(v);
			tree.update(v, 1);
		}
		if( ans < ((ll)N*(N-1)/2+1)/2 ) s = m;
		else e = m;
	}
	return e;
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d%d%d", &D[i].a, &D[i].b, &D[i].c);
	}
	for(int i = 1; i <= N; i++){
		if( D[i].a < 0 ) D[i].a *= -1, D[i].b *= -1, D[i].c *= -1;
		D[i].d = pii(-D[i].b, D[i].a);
	}
	double x = solve(D);
	for(int i = 1; i <= N; i++){
		swap(D[i].a, D[i].b);
		if( D[i].a < 0 ) D[i].a *= -1, D[i].b *= -1, D[i].c *= -1;
		D[i].d = pii(-D[i].b, D[i].a);
	}
	double y = solve(D);
	printf("%.10lf %.10lf\n", y, x);
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
            #include<iostream>
            #include<cstdio>
            #include<vector>
            #include<queue>
            #include<map>
            #include<cstring>
            #include<string>
            #include <math.h>
            #include<algorithm>
        //    #include <boost/multiprecision/cpp_int.hpp>
            #include<functional>
     #define int long long
            #define mod  1000000007
            #define pa pair<int,int>
            #define ll long long
            #define pal pair<double,int>
            #define ppa pair<int,pa>
            #define ssa pair<string,int>
            #define  mp make_pair
            #define  pb push_back
            #define EPS (1e-10)
            #define equals(a,b) (fabs((a)-(b))<EPS)
     
            using namespace std;
     //priority_queue<int, vector<int>, greater<int> > que;
            class Point{
            	public:
            	double x,y;
            	Point(double x=0,double y=0):x(x),y(y) {}
            	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
            	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
            	Point operator * (double a) {return Point(x*a,y*a);}
            	Point operator / (double a) {return Point(x/a,y/a);}
            	double absv() {return sqrt(norm());}
            	double norm() {return x*x+y*y;}
            	bool operator < (const Point &p) const{
            		return x != p.x ? x<p.x: y<p.y;
            	}
            	bool operator == (const Point &p) const{
            		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
            	}
            };
            typedef Point Vector;
     
            struct Segment{
            Point p1,p2;
            };
     
        double hen(Vector a){
        if(fabs(a.x)<EPS && a.y>0) return acos(0);
        else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
        else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
        else if(fabs(a.y)<EPS && a.x>0) return 0.0;
        else if(a.y>0) return acos(a.x/a.absv());
        else return 2*acos(0)+acos(-a.x/a.absv());
     
        }
     
string itos( int i ) {
ostringstream s ;
s << i ;
return s.str() ;
}

int gcd(int v,int b){
	if(v>b) return gcd(b,v);
	if(v==b) return b;
	if(b%v==0) return v;
	return gcd(v,b%v);
}
            double dot(Vector a,Vector b){
            	return a.x*b.x+a.y*b.y;
            }
            double cross(Vector a,Vector b){
            	return a.x*b.y-a.y*b.x;
            }
        
double distans(double x1,double y1,double x2,double y2){
	double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	return sqrt(rr);
	
}
            //----------------kokomade tenpure------------
int a[200000]={0};
int n;
bool b;
    signed  main(){
cin>>n;
    	int sum=0;
    	for(int i=1;i<=n;i++) {
    		cin>>a[i];
    		sum +=a[i];
    	}
    	int m;
    	cin>>m;
    	for(int gg=0;gg<m;gg++){
    		int p,x;
    		cin>>p>>x;
    		cout<<sum-a[p]+x<<endl;
    	}
    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<deque>
using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int main(void) {
    int i,j;
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    deque<int> dq;
    dq.push_back(a[0]);
    i = 1, j = n-1;
    while(i <= j){
        int f = dq.front();
        int b = dq.back();
        if(i==j){
            if(abs(f-a[j]) < abs(b-a[j]))dq.push_back(a[j]);
            else dq.push_front(a[j]);
            break;
        }else{
            if(abs(f-a[j-1])+abs(b-a[j]) < abs(f-a[j])+abs(b-a[j-1])){
                dq.push_back(a[j-1]);
                dq.push_front(a[j]);
            }else{
                dq.push_back(a[j]);
                dq.push_front(a[j-1]);
            }
            j-=2;
        }
        if(i>j)break;
        if(i==j){
            if(abs(f-a[i]) < abs(b-a[i]))dq.push_back(a[i]);
            else dq.push_front(a[i]);
            break;
        }else{
            if(abs(f-a[i+1])+abs(b-a[i]) < abs(f-a[i])+abs(b-a[i+1])){
                dq.push_back(a[i+1]);
                dq.push_front(a[i]);
            }else{
                dq.push_back(a[i]);
                dq.push_front(a[i+1]);
            }
            i+=2;
        }
    }
    ll ans = 0;
    rep(i,n-1) ans += abs(dq[i] - dq[i+1]);

    dq.erase(all(dq));
    dq.push_back(a[n-1]);
    i = 0, j = n-2;
    while(i <= j){
        int f = dq.front();
        int b = dq.back();

        if(i==j){
            if(abs(f-a[i]) < abs(b-a[i]))dq.push_back(a[i]);
            else dq.push_front(a[i]);
            break;
        }else{
            if(abs(f-a[i+1])+abs(b-a[i]) < abs(f-a[i])+abs(b-a[i+1])){
                dq.push_back(a[i+1]);
                dq.push_front(a[i]);
            }else{
                dq.push_back(a[i]);
                dq.push_front(a[i+1]);
            }
            i+=2;
        }
        if(i>j)break;

        if(i==j){
            if(abs(f-a[j]) < abs(b-a[j]))dq.push_back(a[j]);
            else dq.push_front(a[j]);
            break;
        }else{
            if(abs(f-a[j-1])+abs(b-a[j]) < abs(f-a[j])+abs(b-a[j-1])){
                dq.push_back(a[j-1]);
                dq.push_front(a[j]);
            }else{
                dq.push_back(a[j]);
                dq.push_front(a[j-1]);
            }
            j-=2;
        }
    }
    ll t = 0;
    rep(i,n-1) t += abs(dq[i] - dq[i+1]);
    cout << max(ans, t) << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		
		for(int i = 0 ; i<n ; i++){
			a[i]=scan.nextInt();
		}

		
		int min = a[0];
		int max = a[0];
		long sum = 0;
		
		for(int i = 0 ; i<n ; i++){
			sum = sum + a[i];
			if(a[i]<min)min=a[i];
			if(a[i]>max)max=a[i];
		}
	
		System.out.println(min+" "+max+" "+sum);
	
	
	}
	
	

	
	
	
	static void swap(int[] a,int[] b,int i){
		int tmp =a[i];
		a[i]=b[i];
		b[i]=tmp;
		return;
	}

}

Measured memory_bytes: 42392
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(s: chars);
    let mut ans = "Good";
    for i in 0..3 {
        if s[i] == s[i + 1] {
            ans = "Bad";
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }

            boolean win1 = false;
            for (int i = 0; i < N; i++) {
                win1 |= a[i] % 2 == 1;
            }
            System.out.println(win1 ? "first" : "second");
        }
    }
}


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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int N,W,H;
	int S,T;
	cin >> N;

	while (N != 0){
		int max_count = 0;
		cin >> W;
		cin >> H;
		std::vector< std::vector<int> > tree(N, std::vector<int>(2));
		for (int i = 0; i < N; i++) {
			cin >> tree[i][0];
			cin >> tree[i][1];
		}
		cin >> S;
		cin >> T;
		for (int i = 1; i < (W-S+2); i++) {
			for (int j = 1; j < (H-T+2); j++) {
				int count_tree = 0;
				for (int t = 0; t < N; t++) {
					if (tree[t][0] >= i && tree[t][0] <= (i+S-1)) {
						if (tree[t][1] >= j && tree[t][1] <= (j+T-1)) {
							count_tree++;
						}
					}
				}
				if (count_tree > max_count) {
					max_count = count_tree;
				}
			}
		}
		cout << max_count << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

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

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

  vector<int> Nums;
  int now = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == (char)('0' + now))
    {
      cnt++;
    }
    else
    {
      now = 1 - now;
      Nums.push_back(cnt);
      cnt = 1;
    }
  }
  Nums.push_back(cnt);
  if (Nums.size() % 2 == 0)
  {
    Nums.push_back(0);
  }

  int ans = 0;
  int Add = 2 * k + 1;

  int left = 0;
  int right = 0;
  int tmp = 0; // [left, right)のsum
  for (int i = 0; i < Nums.size(); i += 2)
  {
    int Nextleft = i;
    int Nextright = min(i + Add, (int)Nums.size());

    while (Nextleft > left)
    {
      tmp -= Nums[left];
      left++;
    }

    while (Nextright > right)
    {
      tmp += Nums[right];
      right++;
    }

    ans = max(ans, tmp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1020
def main():
    n = int(input())
    p = list(map(int,input().split()))
    cnt = 0

    for i in range(1,len(p)-1):
        if p[i] < p[i+1] and p[i] > p[i-1]:
            cnt += 1
        elif p[i] > p[i+1] and p[i] < p[i-1]:
            cnt += 1

    print(cnt)

main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

const ll MOD = 1000000007;

int main(){
    ll n, k; cin >> n >> k;
    vector<pair<ll,ll>> data(n);
    vector<ll> pl, mi;
    rep(i,n){
        ll x; cin >> x;
        if(x > 0) data[i] = make_pair(x,1), pl.pb(x);
        else if(x < 0) data[i] = make_pair(-x,-1), mi.pb(-x);
        else if(x == 0) data[i] = make_pair(0,0);
    }
    sort(all(data),greater<pair<ll,ll>>());
    sort(all(pl),greater<ll>()); ll pp = pl.size();
    sort(all(mi),greater<ll>()); ll mm = mi.size();

    ll ans = 1, num = 1;

    if(n == k){
        rep(i,k) ans *= data[i].first, ans %= MOD, num *= data[i].second;
        cout << (num >= 0 ? ans : MOD - ans) << endl; return 0; 
    }

    if(pp == 0 && k%2 == 1){
        if(mm < n){ cout << 0 << endl; return 0; }
        rep(i,k) ans *= mi[n-1-i], ans %= MOD;
        cout << MOD - ans << endl; return 0; 
    }

    ll ppc = 0, mmc = 0;
    rep(i,k){
        ans *= data[i].first, ans %= MOD;
        num *= data[i].second;
        if(data[i].second == 1) ppc++;
        else if(data[i].second == -1) mmc++;
    }
    if(num >= 0){ cout << ans << endl; return 0; }

    if(pp == ppc && mm == mmc){ cout << 0 << endl; return 0; }

    ll ans2 = 1;

    if(ppc == 0){
        rep(i,mmc-1) ans2 *= mi[i], ans2 %= MOD;
        cout << ans2*pl[0]%MOD << endl; return 0;
    }

    rep(i,ppc-1) ans2 *= pl[i], ans2 %= MOD;
    rep(i,mmc-1) ans2 *= mi[i], ans2 %= MOD;

    ll save1 = 0, save2 = 0;
    if(pp > ppc) save1 = pl[ppc-1]*pl[ppc];
    if(mm > mmc) save2 = mi[mmc-1]*mi[mmc];

    if(save1 > save2) ans2 *= (pl[ppc-1]*pl[ppc]%MOD), ans2 %= MOD;
    else ans2 *= (mi[mmc-1]*mi[mmc]%MOD), ans2 %= MOD;
    cout << ans2 << endl; return 0;  
}

Measured memory_bytes: 8444
times = int(input())
n = []
for i in range(2):
	n.append(list(map(int, input().split()))) 
    
answer = 0
for j in range(times):
  if (n[0][j] - n[1][j]) > 0:
    answer += (n[0][j] - n[1][j])

print(answer)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

int main() {
    int a, b;  cin >> a >> b;
    int c = 0;
    while (a > 0){
        a /= b; c++;
}
    cout << c; 
            return 0; 
 }
    
        
    
    


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_168_Therefore
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string a = Console.ReadLine();

            if (a.EndsWith("3"))
            {
                a = "bon";
            }
            else if (a.EndsWith("2")|| a.EndsWith("4") || a.EndsWith("5") || a.EndsWith("7") || a.EndsWith("9"))
            {
                a = "hon";
            }
            else if (a.EndsWith("0") || a.EndsWith("1") || a.EndsWith("6") || a.EndsWith("8"))
            {
                a = "pon";
            }

            string result = a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 26124
n,k = (int(a) for a in input().split())
A =  [-1] + list(map(int,input().split()))
t = [1]
flag =[0,1] + [0]*(n-1)
x = A[1]
while flag[x] == 0 :
    t.append(x)
    flag[x] = 1
    x = A[x] 

if k <= len(t) -1 :
    print(t[k])
else :
    l = t[t.index(x):]
    k = k - (len(t) - 1)
    k %= len(l)
    print(l[k-1])


Measured memory_bytes: 32336
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX / 10000;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	int n;
	cin >> n;
	Vi A(n);
	rep(i, n) cin >> A[i];

	int s = A[0];
	lrep(i, 1, n) {
		s ^= A[i];
	}
	rep(i, n) {
		cout << (A[i] ^ s) << endl;
	}
}


Measured memory_bytes: 4040
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){        swap(a,b);
    }
    if(b>c){        swap(b,c);
    }
    if(a>b){        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3116
import sys
readline = sys.stdin.readline

def main():
    A, B, C, K = map(int, readline().rstrip().split())
    if A >= K:
        print(K)
    elif A + B >= K:
        print(A)
    else:
        print(A - (K - A - B))


if __name__ == '__main__':
    main()

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

const int INF = 1001001001;

int a[12][12];

int main() {
 int A,B,C,D,E;
 cin>>A>>B>>C>>D>>E;
 int ans=(A+9)/10*10+(B+9)/10*10+(C+9)/10*10+(D+9)/10*10+(E+9)/10*10;
 ans-=max({(A+9)/10*10-A,(B+9)/10*10-B,(C+9)/10*10-C,(D+9)/10*10-D,(E+9)/10*10-E});
 cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char s[16];

    scanf("%s", s);

    int len = strlen(s);

    char t[len];
    int c = 0;

    for(int i = 0; i < len; i++){
        if(s[i] == '0'){
            t[c] = '0';
            c++;
        }else if(s[i] == '1'){
            t[c] = '1';
            c++;
        }else{
            if(c != 0){
                t[c-1] = '\0';
                c--;
            }
        }
    }
    t[c] = '\0';

    printf("%s\n", t);

    return 0;
}

Measured memory_bytes: 1656
s = str(input())
t = str(input())
n = len(s)
m = len(t)
mx = 0
for i in range(n-m+1):
    cnt = 0
    for j in range(m):
        if s[i+j] == t[j]:
            cnt += 1
    if cnt > mx:
        mx = cnt
print(m-mx)

Measured memory_bytes: 9112
n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)

ans = l[0]
num = 1

if len(l) == 2:
  print(ans)
else:
  for i in range(1, n):
    ans += l[i]
    num += 1
    if num == n-1:
      break
    ans += l[i]
    num += 1
    if num == n-1:
      break
  print(ans)
  



Measured memory_bytes: 31632