akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args){
        int A, B, C, X;
        Scanner sc = new Scanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        X = sc.nextInt();
        int count =0;
        for(int i=0;i<=A;i++){
            for(int j=0;j<=B;j++){
                for(int k=0;k<=C;k++){
                    if(500*i+100*j+50*k==X){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }

}


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

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    int n;
    cin>>n;
    long long int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    
    long long int tot=0;
    for(int i=0;i<n;i++)
    tot=tot^arr[i];
    
    for(int i=0;i<n;i++)
    {
        int res=arr[i]^tot;
        cout<<res<<" ";
    }
    cout<<endl;
}


int main()
 {  fast();
   solve();
	return 0;
}

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	map<mp,int> st;
	int n;
	cin>>n;
	vector<mp> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			mp dis = mp( a[i].first-a[j].first, a[i].second-a[j].second);
			st[dis] ++;
		}
	}
	int sum = 0;
	for(auto it:st){
		sum = max(sum,(int)it.second);
	}
	cout<<n-sum<<endl;


	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A, B, M;
  cin >> A >> B >> M;
  vector<i64> a(A);
  for (i64 i = 0; i < A; i++)
    cin >> a[i];
  vector<i64> b(B);
  for (i64 i = 0; i < B; i++)
    cin >> b[i];
  vector<i64> x(M), y(M), c(M);
  for (i64 i = 0; i < M; i++)
    cin >> x[i] >> y[i] >> c[i];
  i64 ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  for (i64 i = 0; i < M; i++)
    ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    string S;
    cin >> S;
    bool clear = true;
    if(S[0] != 'A') clear = false;
    int index = -1;
    for(int i = 2; i + 1 < S.size(); i++) {
        if(S[i] != 'C') continue;
        if(index == -1) index = i;
        else clear = false;
    }
    if(index == -1) clear = false;
    for(int i = 1; i < S.size(); i++) {
        if(i == index) continue;
        if(S[i] < 'a' || S[i] > 'z') clear = false;
    }
    if(clear) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}


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

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

  int ans = 0;
  string te = "";
  for (int i = 0; i < n; i ++) {
    if (t[i] == 'r') {
      if (i - k < 0 || (i - k >= 0 && te[i - k] != 'p')) {
        ans += p;
        te += 'p';
      } else {
        te += 'x';
      }
    } else if (t[i] == 's') {
      if (i - k < 0 || (i - k >= 0 && te[i - k] != 'r')) {
        ans += r;
        te += 'r';
      } else {
        te += 'x';
      }
    } else {
      if (i - k < 0 || (i - k >= 0 && te[i - k] != 's')) {
        ans += s;
        te += 's';
      } else {
        te += 'x';
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
n, m, q = map(int, input().split())

a = []
b = []
c = []
d = []

for _ in range(q):
    ins = list(map(int, input().split()))
    a.append(ins[0])
    b.append(ins[1])
    c.append(ins[2])
    d.append(ins[3])
 
A = [[i] for i in range(1, m+1)]
 
while len(A[0]) != n:
    current = A.pop(0)
    for i in range(current[-1], m+1):
        A.append(current+[i])
 
maxima = 0
for item in A:
    accumulate = 0
    for i in range(q):
        if (item[b[i]-1] - item[a[i]-1]) == c[i]:
            accumulate += d[i]
    if accumulate > maxima:
        maxima = accumulate

print(maxima)


Measured memory_bytes: 22888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const long long mod=1e9+7;

int main(){
  int N, M; cin >> N >> M;
  
  vector<int>oks(N+1, true);
  for(int i=0;i<M;++i){
    int a;cin>>a;
    oks[a]=false;
  }
  vector<long long int>dp(N+1);
  dp[0]=1;
  for(int now=0;now<N;++now){
    for(int next=now+1;next<=min(N,now+2);++next){
      if(oks[next]){
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 4460
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)

int main(){
    ll n;
    scanf("%lld", &n);

    /////素因数分解
    struct ret{
        ll val, cnt;
    };
    struct ret ret[21];
    ll ntmp = n;
    int rcnt = 0;
    for(ll i = 2; i * i <= ntmp; i++) {
        if(ntmp % i == 0){
            ret[rcnt].cnt = 0;
            ret[rcnt].val = i;
            while(ntmp % i == 0) {
                ret[rcnt].cnt++;
                ntmp /= i;
            }
            rcnt++;
        }
    }
    if(ntmp != 1){
        ret[rcnt].val = ntmp;
        ret[rcnt].cnt = 1;
        rcnt++;
    }
    /////

    printf("%lld:", n); 
    rep(i, rcnt){
        rep(j, ret[i].cnt){
            printf(" %lld", ret[i].val);
        }
    }
    printf("\n");
}


Measured memory_bytes: 2104
import numpy as np
from itertools import permutations
from math import hypot

n = int(input())
k = 0
dis = 0

li = []
for _ in range(n):
    i, j = map(int, input().split())
    li.append(np.array([i, j]))

li2 = permutations(li)

re = []
for a in li2:
    k += 1
    for (x1,y1),(x2,y2) in zip(a,a[1:]):
        dis += hypot(x1-x2, y1-y2)

print(dis/k)

Measured memory_bytes: 13792
#include<bits/stdc++.h>
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
typedef long long ll;
inline int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}

inline void file(){
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
}

using namespace std;
const int maxn=1e5+10;
ll a[maxn],b[maxn];

int main(){
	//file();
	ll k,n,h;
	//scanf("%lld%lld",&n,&h);
	cin>>n>>h;
	for(register int i=1;i<=n;++i)
		cin>>a[i]>>b[i];

	sort(a+1,a+n+1);
	for(register int i=1;i<=n;++i)
		b[i]=max(b[i],a[n]);
	sort(b+1,b+n+1);

	ll ovo=0;
	for(register int i=n;i>=1;--i){
		ovo+=b[i];
		if(ovo>=h){
			printf("%lld",n-i+1);
			return 0;
		}
	}
	int ans=n;
	ans+=(h-ovo)/a[n];
	if((h-ovo)%a[n])
		++ans;
	cout<<ans;
	return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
using pii = pair<int, int>;

int h[202020];
int ans;
int32_t main()
{
    usecppio
    int n; cin >> n;
    for (int i = 1; i<=n; i++)
        cin >> h[i];
    for (int i = 1; i<=n; i++)
    {
        ans += (max(0ll, h[i-1]-h[i]));
        h[i] = max(h[i], h[i-1]);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int,int> P;
typedef pair<P,P> PP;
int main(void)
{
	int i,j,k,u,n,flg[10001],v,c,sum,ky[10001],t,min,g;
	PP ke[10001];
	scanf("%d",&n);
	sum=0;
	for(i=0;i<n;i++) ky[i]=M,flg[i]=0;
	ky[0]=0;
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=sum;j<k+sum;j++){
			scanf("%d%d",&v,&c);
			ke[j].ff=u , ke[j].fs=v , ke[j].sf=c;
		}
		sum+=k;
	}
	sort(ke,ke+sum);
	//for(i=0;i<sum;i++) printf("ke[%d].ff=%d ke[%d].fs=%d ke[%d].sf=%d\n",i,ke[i].ff,i,ke[i].fs,i,ke[i].sf);
	for(i=0;i<sum;i++){
		min=M;
		for(j=0;j<sum;j++) if(flg[j]==0&&min>ky[j]) g=j,min=j;
		flg[g]=1;
		if(min==M) break;
		for(j=0;j<sum;j++){
			t=ky[ke[j].ff]+ke[j].sf;
			if(ky[ke[j].fs]>t) g=j,ky[ke[j].fs]=t;
		}
	}
	for(i=0;i<n;i++) printf("%d %d\n",i,ky[i]);
	return 0;
}


Measured memory_bytes: 3392
a=input()
b=input()
c=input()
a=int(a)
c=int(c)
x=b[c-1]
    
ll=list()
for i in b:
    if i == x:
        ll.append(i)
    else:
        ll.append("*")
for i in ll:
    print(i, end="")
    


Measured memory_bytes: 3060
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int a = sc.nextInt();

	if(x < a) {
System.out.println(0);
	} else {
	    System.out.println(10);
	}
	//System.out.println();
    }
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int count10 = 0;
    int count01 = 0;
    int ans = 0;
    for (int i=0; i<n; i++){
        if(i%2==0){
            if(s.at(i) == '1'){
                count10++;
            }
        }
        else if(i%2==1){
            if(s.at(i) == '0'){
                count10++;
            }
        }
    }
    count01 = n - count10;
    ans = min(count01, count10);
    cout << ans << endl;
}

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

using namespace std;

struct UF {
	UF *p;
	int s;
	UF() :p(nullptr), s(1) {}
	UF *Find() {
		if (p == nullptr)
			return this;
		return p = p->Find();
	}
	int Union(UF &n) {
		auto *r = Find(), *nr = n.Find();
		if (r == nr) return 0;
		if (r->s < nr->s) swap(r, nr);
		nr->p = r, r->s += nr->s;
		return 1;
	}
} u[111111];
int a[111111], b[111111];
long r[111111];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		scanf("%d%d", a + i, b + i);
	r[m] = n * long(n - 1) / 2;
	for (int i = m; --i;) {
		long s = u[a[i]].Find()->s, t = u[b[i]].Find()->s;
		r[i] = r[i + 1];
		if (u[a[i]].Union(u[b[i]]))
			r[i] -= s * t;
	}
	for (int i = 0; i < m; i++)
		cout << r[i + 1] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] candidate = {"AKIHABARA",
                                              "AKIHABAR",
                                              "AKIHABRA",
                                              "AKIHABR",
                                              "AKIHBARA",
                                              "AKIHBAR",
                                              "AKIHBRA",
                                              "AKIHBR",
                                              "KIHABARA",
                                              "KIHABAR",
                                              "KIHABRA",
                                              "KIHABR",
                                              "KIHBARA",
                                              "KIHBAR",
                                              "KIHBRA",
                                              "KIHBR",};
        for (int i = 0 ; i < 16 ; i++) {
            if (s.equals(candidate[i])) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
bool compare(string a, string b) 
{ 
    return (a+b < b+a); 
} 
  
string small(string a[], int n) 
{ 
    sort(a, a+n, compare); 
    string ans = ""; 
    for (int i = 0; i < n; i++) 
        ans+= a[i]; 
  
    return ans; 
} 
int main() {

	    long long n,l;
	    cin>>n>>l;
	    string s[102];
	    int i=0;
	    string z="";
	   
	    while(i<n){
	        cin>>s[i];
	     i++;
	    }
	  z=small(s,n);
	  cout<<z<<endl;

	
	
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;



    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        Array.Sort(A);
        List<int> num = new List<int>();
        num.Add(0);
        for (int i = 0; i < A.Length; i++)
        {
            if (i % 2 == 0)
            {
                num.Add(A[i]);
            }
            else num.Add(24 - A[i]);
        }
        num.Sort();
        int diff = 24;
        for (int i = 0; i < num.Count; i++)
        {
            diff = Math.Min(diff, (24 + num[(i + 1) % num.Count] - num[i]) % 24);
        }
        Console.WriteLine(diff);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

public class Main {
    int[][][] memo;

    int solve(int n, int bits, int sum) {
        if (n == 0) {
            if (sum == 0) return 1;
            return 0;
        }
        if (sum > 330) return 0;
        if (sum < 0) return 0;
        if (memo[n][bits][sum] != -1) return memo[n][bits][sum];
        int ans = 0;
        for (int i = 0; i < 10; ++i) {
            if (((bits >> i) & 1) != 0) {
                ans += solve(n - 1, bits & ~(1 << i), sum - i*(10 - Integer.bitCount(bits) + 1));
            }
        }
        return memo[n][bits][sum] = ans;
    }

    void run() {
        memo = new int[11][1024][331];
        for (int i = 0; i < 11; ++i) {
            for(int j = 0; j < 1024; ++j) {
                for (int k = 0; k < 331; ++k) {
                    memo[i][j][k] = -1;
                }
            }
        }
        try {
            while (true) {
                int N = readInt();
                int S = readInt();
                sysout.println(solve(N, (1 << 10) - 1, S));
            }
        } catch (NullPointerException e) {
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = new StringTokenizer("");

    String read() {
        if (!buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = new StringTokenizer("");
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Measured memory_bytes: 35040
n = int(input())
for i in range(n):
    k = input()
    xa, ya, ra, xb, yb, rb = list(map(float, k.split(" ")))
    d = abs(complex(xb-xa, yb-ya))
    if ra + rb < d:
        print("0")
    elif abs(rb-ra) <= d <= ra+rb:
        print("1")
    else:
        print("2" if ra > rb else "-2")

Measured memory_bytes: 7536
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

const int N = 1e5 + 10;

int a[N];

void Main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int A = a[n / 2 - 1], B = a[n / 2];
  cout << (B - A) << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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


    
    cout << n + pow(n, 2) + pow (n, 3);
}

Measured memory_bytes: 4184
import sys
from functools import reduce
def rerooting(N, adj, merge, finalize,identity):
    """
    merge: (T,T) -> T
    This merges two dp results. (T, operator) must be a monoid.

    identity: identity of (T, operator)
    
    finalize: T -> T
    This transforms the merged result to the dp result
    """

    order = [None]*N
    parent = [None]*N
    parent[0] = -1
    stack = [0]
    for i in range(N):
        v = stack.pop()
        order[i] = v
        for u in adj[v]:
            if parent[u] is None:
                parent[u] = v
                stack.append(u)

    # from leaf to parent
    dp_down = [None]*N
    for v in reversed(order[1:]):
        p = parent[v]
        dp_down[v] = finalize(reduce(merge,
            (dp_down[c] for c in adj[v] if c != p),
            identity))

    # from parent to leaf
    dp_up = [None]*N
    dp_up[0] = identity
    for v in order:
        if len(adj[v]) == 1 and adj[v][0] == parent[v]:
            continue
        p = parent[v]
        left = [dp_up[v]]
        for u in adj[v]:
            if u != p:
                left.append(merge(left[-1],dp_down[u]))

        right = [identity]
        for u in reversed(adj[v]):
            if u != p:
                right.append(merge(dp_down[u],right[-1]))
        i = 0
        for u in adj[v]:
            if u != p:
                dp_up[u] = finalize(merge(left[i],right[-i-2]))
                i += 1

    for v,l in enumerate(adj):
        order[v] = reduce(merge,
                    (dp_down[u] for u in adj[v] if u != parent[v]),
                    identity)
        order[v] = finalize(merge(order[v], dp_up[v]))

    return order


def solve(N,edges):
    MOD = 10**9+7

    factorio = [None]*(N+1)
    factorio[0] = 1
    t = 1
    for i in range(1,N+1):
        t *= i
        t %= MOD
        factorio[i] = t

    factorio_inv = [None]*(N+1)
    factorio_inv[0] = 1
    t = pow(factorio[-1],MOD-2,MOD)
    for i in reversed(range(1,N+1)):
        factorio_inv[i] = t
        t *= i
        t %= MOD


    adj = [[] for _ in range(N)]
    for a,b in edges:
        adj[a].append(b)
        adj[b].append(a)

    def func(x,y):
        cx,nx = x
        cy,ny = y
        c = cx*cy*factorio[nx+ny]*factorio_inv[nx]*factorio_inv[ny]
        return c%MOD, nx+ny

    def func2(x):
        c,n = x
        return c,n+1

    identity = (1,0)

    res = rerooting(N, adj, func, func2, identity)

    for k,n in res:
        print(k)


if __name__ == '__main__':
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
     
    N = int(readline())
    m = map(int, read().split())
    edges = tuple((a-1,b-1) for a,b in zip(m, m))

    solve(N, edges)


Measured memory_bytes: 198640
//JSD
#include<iostream>
#define ll long long 
using namespace std;
int main(){	
	ll n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2<<"\n";
	}
	else{
		if(a>b)
			swap(a,b);	
		ll p=a,q=b;
		ll r=(b-a+1)/2+(a-1);
		ll s=(b-a+1)/2+(n-b);
		ll ans=min(r,s);
		cout<<ans<<"\n";
	}	
	return 0;
}

Measured memory_bytes: 256
h, w, d = map(int, input().split())
n = h*w
paths = [[]for _ in range(d)]
for i in range(n):
    paths[i % d].append(i)


class P:
    def __init__(self, x, y):
        self.x, self.y = x, y

    def __sub__(self, p):
        return P(self.x-p.x, self.y-p.y)

    def _abs(self):
        return P(abs(self.x), abs(self.y))

    def _sum(self):
        return self.x+self.y

    def to(self, p):
        return (self-p)._abs()._sum()


coodinates = [None]*n
for i in range(h):
    for j, a in enumerate(map(lambda x: int(x)-1, input().split())):
        coodinates[a] = P(i, j)

costs = [[0]for _ in range(d)]
for i in range(d):
    for x, y in zip(paths[i], paths[i][1:]):
        p, q = coodinates[x], coodinates[y]
        costs[i].append(costs[i][-1]+p.to(q))

q = int(input())
for _ in range(q):
    L, R = map(lambda x: int(x)-1, input().split())
    print(costs[L % d][R//d]-costs[L % d][L//d])


Measured memory_bytes: 42032
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
    SPEED;
    string s;
    cin>>s;
    int n=s.length();
    int res=0;
    for(int i=0;i<n;i++)
    {
           res+=s[i]!=s[n-1-i];
    }
    cout<<res/2<<endl;
    time();
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int main() {
	string s;
	cin >> s;
	
	int len = s.length();

	int found = 0;
	REP(i, len) {
		if (s[i] == 'C') found = 1;
		else if (found == 1) {
			if (s[i] == 'F') {
				found = 2;
				break;
			}
		}
	}

	cout << (found==2?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
ll inf=1LL<<60;
double eps=1e-14;

int main()
{
    int n ,x;
    cin >> n >> x;
    int L[n];
    rep(i,0,n) cin >> L[i];
    rep(i,0,n-1) L[i+1] += L[i];
    int tmp = 0;
    rep(i,0,n)
    {
        if(x < L[i])
        {
            tmp = i+1;
            break;
        }
        tmp = n+1;
    }
    cout << tmp << endl;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

vector<lint> fact, inv;

long long power(long long x, long long n){
    long long res = 1;
    x %= MOD;
    while(n > 0LL){
        if(n & 1LL){
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

long long moddiff(long long a, long long b){
    long long res = a - b;
    if(res < 0LL){
        long long t = (abs(res) - 1LL) / MOD + 1LL;
        res += MOD * t;
    }
    res %= MOD;
    return res;
}

lint comb(int n, int r){
    if(n < r){
        return 0LL;
    }
    return (((fact[n] * inv[r]) % MOD) * inv[n - r]) % MOD;
}

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

    int n;
    cin >> n;

    fact.resize(n + 2);
    inv.resize(n + 2);
    fact[0] = 1;
    inv[0] = 1;
    REP(i, 1, n + 2){
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    int left, right;
    vector<int> id(n, -1);
    rep(i, n + 1){
        int a;
        cin >> a;
        --a;
        if(id[a] >= 0){
            left = id[a];
            right = n - i;
        }
        id[a] = i;
    }

    REP(i, 1, n + 2){
        lint ans = comb(n + 1, i);
        ans = moddiff(ans, comb(left + right, i - 1));
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair <int, int> P;
typedef pair <int, P> Q;

int main() {
	int n, m, a;
	while (cin >> n >> m >> a) {
		if (n == 0 && m == 0 && a == 0) {
			break;
		}
		vector< vector<P> > kuji(n+1, vector<P>(0));
		int h, p, q;
		priority_queue<Q> pq;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			Q qq;
			qq.first = h;
			(qq.second).first = p;
			(qq.second).second = q;
			pq.push(qq);
		}
		while (!pq.empty()) {
			Q data = pq.top();
			pq.pop();
			P pp;
			pp.first = data.first;
			pp.second = (data.second).second;
			kuji[(data.second).first].push_back(pp);
			pp.second = (data.second).first;
			kuji[(data.second).second].push_back(pp);
		}
		if ((kuji[a]).size() == 0) {
			cout << a << endl;
		} else {
			int b = (kuji[a][0]).second;
			int s = (kuji[a][0]).first;
			while (1) {
				bool hantei = true;
				for (int i = 0; i < kuji[b].size(); i++) {
					if ((kuji[b][i]).first < s) {
						s = (kuji[b][i]).first;
						b = (kuji[b][i]).second;
						hantei = false;
						break;
					}
				}
				if (hantei) {
					cout << b << endl;
					break;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
	//input
	ll N,A,B,C,D; cin>>N>>A>>B>>C>>D;
	N--;
	
	//solve
	ll L=-(D*N);
	bool ans=false;
	rep(i,N+1){
		ll tmp=L+i*(C+D); //端
		if(tmp<=B-A && B-A<=tmp+N*(D-C)) ans=true;
	}

	//output
	if(ans) cout<<"YES";
	else cout<<"NO";
}

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

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

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

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

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

void IN(void){
  return;
}

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

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

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

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

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

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

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

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

  ll N;
  IN(N);
  vector<ull> A(N);
  REP(i,N) IN(A[i]);
  sort(ALL(A));
  ull ans = 1;

  REP(i,N){
    if(ans>0){
      if(A[i]>(ull)(1E18/ans)+1){
        OUT(-1);
        return 0;
      }
    }
    ans *= A[i];
    if(ans>(ull)1E18){
      OUT(-1);
      return 0;
    }
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 3992
(let* ((h (read))
       (w (read))
       (k (read))
       (cl (make-array `(,(1+ h), (1+ w)) :initial-element nil))
       (r (make-array `(,(1+ h)) :initial-element nil))
       (c (make-array `(,(1+ w)) :initial-element nil))
       (b 0)
       (ans 0))
  ;;
  (loop :for i :from 1 :to h
        :for s := (read-line)
        :do (loop :for j :from 1 :to w
                  :do (let ((ch (aref s (1- j))))
                        (when (char= ch #\#)
                          (incf b)
                          (setf (aref cl i j) t)))))
  ;;
  (loop :for i :from 0 :to h
        :do (setf (aref r i) (loop :for j :from 1 :to w :if (aref cl i j) :sum 1)))
  (loop :for j :from 0 :to w
        :do (setf (aref c j) (loop :for i :from 1 :to h :if (aref cl i j) :sum 1)))
  ;
  (loop :for in :from 0 :to (1- (expt 2 h))
        :do (loop :for jn :from 0 :to (1- (expt 2 w))
                  :for acc := 0
                  :do (loop :for i :from 1 :to h
                            :if (/= 0 (logand in (expt 2 (1- i))))
                            :do (incf acc (- (aref r i)
                                             (loop :for j :from 1 :to w
                                                   :if (/= 0 (logand jn (expt 2 (1- j))))
                                                   :sum (if (aref cl i j) 1 0)))))
                  ;:do (format t "~B ~B ~A~%" in jn acc)
                  :do (loop :for j :from 1 :to w
                            :if (/= 0 (logand jn (expt 2 (1- j))))
                            :do (incf acc (aref c j)))
                  ;:do (format t "~B ~B ~A~%" in jn acc)
                  :do (incf ans (if (= k (- b acc)) 1 0))))
  (format t "~A~%" ans))


Measured memory_bytes: 24692
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
char s[10]; 
int main()
{
	scs(s);
	if(s[2]==s[3]&&s[4]==s[5])pf("Yes\n");
	else pf("No\n");
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, N = 3e6 + 5;

template <int MOD=1000000007>
struct Modular {
  int value;
  static const int MOD_value = MOD;

  Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend Modular mexp(Modular a, long long e) {
    Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }

  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
Modular<M> ans = 0, fact[N];

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  fact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = fact[i-1] * i;
  }

  for (int i = c1; i <= c2; ++i) {
    Modular<M> l = fact[i + r1] / (fact[i+1] * fact[r1-1]);
    Modular<M> r = fact[r2+i+1] / (fact[i+1] * fact[r2]);
    ans += r - l;
  }

  cout << ans << '\n';
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++) cin >> d[i];
  vector<int> v;
  for(int i=0;i<n;i++){
    int k=0;
    for(int j=i;j<n;j++){
      k=k*10+d[j];
      v.push_back(k);
      if(k>10000000) break;
    }
  }
  sort(v.begin(),v.end());
  int now=0;
  for(int i=0;i<v.size();i++){
    if(v[i]==now) now++;
    else if(v[i]>now){
      cout << now << endl;
      return 0;
    }
  }
  return 0;
}



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

int main() {
  int N,K;
  
  int b=1;
  cin >> N >> K;
  for (int i=0; i<N; i++){
    if(b*2 <= b+K){
      b*= 2;
    }
    else
      b+= K;
  }
  cout << b << endl;
    
    
}
   

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <array>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#define MOD 1000000007
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int H, W, A, B;
LL fac[212345], ans;

LL mul(LL x, LL y)
{
	return (x * y) % MOD;
}

LL inv(LL n)
{
	LL res = 1, m = MOD - 2;
	while (true) {
		if (m & 1)
		{
			res = mul(res, n);
		}
		if (m >>= 1)
		{
			n = mul(n, n);
		}
		else
		{
			break;
		}
	}
	return res;
}

LL comb(int n, int m)
{
	--n, --m;
	return (fac[n + m] * inv((fac[n] * fac[m]) % MOD)) % MOD;
}

int main()
{
	in >> H >> W >> A >> B;

	fac[0] = 1;
	for (int i = 1; i < 212345; ++i)
	{
		fac[i] = fac[i - 1] * i;
		fac[i] %= MOD;
	}
	for (int i = B + 1; i <= W; ++i)
	{
		ans += (comb(H - A, i)*comb(A, W - i + 1)) % MOD;
		ans %= MOD;
	}

	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;


int main(void)
{
	int N; cin >> N;
	vector<lli> A(N); rep(i, 0, N)cin >> A[i];
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	vector<lli> a(2, 0);
	int j = 0;
	rep(i, 1, N) {
		if (A[i - 1] == A[i]) {
			a[j++] = A[i];
			if (j >= 2)break;
			i++;
		}
		if (i >= N)break;
	}
	cout << a[0] * a[1] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	int y = 1;
	long long r = 0;
	for (int x : A) {
		int n = (x-1) / y;
		//cerr << x << " " << y << " " << n << endl;
		r += n;
		if (y == 1) {
			y = 2;
		} else {
			if (n == 0 && x == y) ++ y;
		}
	}
	cout << r << endl;
}


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

using namespace std;

int main(){
    int a , b , c , x; cin >> a >> b >> c >> x;
    
    int cnt = 0;
    
    for(int i = 0 ; i <= a ; i ++){
        for(int j = 0 ; j <= b ; j ++){
            for(int k = 0 ; k <= c ; k ++){
                if(500 * i + 100 * j + 50 * k == x) cnt ++;
            }
        }
    }
    cout << cnt << endl;
}


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

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

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

  int sum=0;
  vector<int> s(n);
  rep(i,n){cin >> s.at(i); sum+=s.at(i);}
  
  if(sum%10!=0) {cout<<sum; return 0;}

  sort(s.begin(), s.end());
  rep(i,n){
    if((sum-s.at(i))%10!=0) {cout<<sum-s.at(i); return 0;}
  }

  cout << 0;
  
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B; cin >> A >> B;
    cout << (A+B)%24 << endl;
    return 0;
}


Measured memory_bytes: 3652
r, c = gets.chomp.split.map(&:to_i)

arr = []

r.times do
  temp = gets.chomp.split.map(&:to_i)
  temp << temp.sum
  arr <<  temp
end

add_arr = Array.new(c + 1)
for i in 0..c do
  temp = 0
  arr.each do |c_arr|
    temp += c_arr[i]
  end
  add_arr[i] = temp
end
arr << add_arr

arr.each do |c_arr|
  puts c_arr.join(" ")
end


Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    int a[2][n],rui[n+1] = {},rui2[n+1] = {};

    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    if(n == 1){
        cout << a[0][0]+a[1][0] << endl;
        return 0;
    }

    for(int i = 0;i < n;i++){
        rui[i+1] = rui[i] + a[0][i];
    }

    for(int i = 0;i < n;i++){
        rui2[i+1] = rui2[i] + a[1][n-1-i];
    }

    int ans = 0;
    for (int i = 1; i < n; ++i) {
        int tmp;
        tmp = rui[i]+rui2[n+1-i];
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]
S = [0 for i in range(N)]
S[0] = H[0]
for i in range(1,N):
    S[i] = H[i] + S[i-1]
left = 0
right = 2
D = S[N-1]
for center in range(1,N-2):
    while  abs(S[center]/2-S[left+1]) <= abs(S[center]/2-S[left]) :
        if left+1 == center:
            break
        else:
            left += 1
    if center == right:
        right += 1
    while  abs(S[N-1]+S[center]-2*S[right+1]) <= abs(S[N-1]+S[center]-2*S[right]) :
        if right == N-2:
            break
        else:
            right += 1 
    D = min(
            max(S[left],S[center]-S[left],S[right]-S[center],S[N-1]-S[right])-
            min(S[left],S[center]-S[left],S[right]-S[center],S[N-1]-S[right])
            ,D)
print(D)

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

int main() {
    string S;
    cin >> S;
    
   
        if(S.at(0)==S.at(1) &&S.at(2)==S.at(3) &&S.at(0) != S.at(2)){
                 cout << "Yes" << endl;
        }
        else if(S.at(0)==S.at(2) && S.at(1)==S.at(3) && S.at(0) != S.at(1)){
            cout << "Yes" << endl;
        }
        else if(S.at(0)==S.at(3) && S.at(1)==S.at(2) && S.at(0) != S.at(1)){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    
    
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    VI k(M);
    VI s[M];
    REP(i,M){
        cin >> k[i];

        REP(j,k[i]){
            int x; cin >> x;
            x--;
            s[i].eb(x);
        }
    }
    VI p(M);
    REP(i,M) cin >> p[i];
    LL ans = 0;
    for(int i = 0; i < (1 << N); i++){

        VI lamp(M,0);
        for(int j = 0; j < N; j++){
            if(1 & (i >> j)){
                REP(k,M){
                    for(auto p : s[k]){
                        if(p == j) lamp[k]++;
                    }
                }
            }
        }
        bool ok = 1;
        dump(i)
        for(int j = 0; j < M; j++){
            dump(j)
            dump(lamp[j])
            if(lamp[j]%2 != p[j]) ok = 0;
        }
        if(ok) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256