akhauriyash/Code-Regression huggingface dataset:
# ABC079C - Train Ticket
A, B, C, D = list(map(int, list(input())))
for b in (+B, -B):
    for c in (+C, -C):
        for d in (+D, -D):
            if A + b + c + d == 7:
                ans = str(A)
                ans += str(b) if b < 0 else "+" + str(b)
                ans += str(c) if c < 0 else "+" + str(c)
                ans += str(d) if d < 0 else "+" + str(d)
                ans += "=7"
                print(ans)
                break
        else:
            continue
        break
    else:
        continue
    break

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

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	char x; cin >> x;
	if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') cout << "vowel\n";
	else cout << "consonant\n";
	
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
//#include <atcoder/all>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static _T tp_modpow(_T base, _T exp, _T mod = (_T)1) {
	_T ans = 1;
	while (exp > 0) {
		if (exp & 1) {
			ans = (ans * base) % mod;
		}
		base = (base * base) % mod;
		exp >>= 1;
	}
	return ans;
}
template <class _T> static _T tp_modinv(_T a, _T mod) {
	return tp_modpow<_T>(a, mod - 2, mod);
}

static void C();

int main()
{
	C();
	fflush(stdout);
	return 0;
}

static void C()
{
	LLONG N;
	get(N);

	LLONG ans = tp_modpow(10LL, N, MOD_NUM) % MOD_NUM;
	LLONG mi = ((tp_modpow(9LL, N, MOD_NUM) * 2LL) - tp_modpow(8LL, N, MOD_NUM)) % MOD_NUM;
	if (mi < 0LL) mi += MOD_NUM;
	ans = ans - mi;
	if (ans < 0LL) ans += MOD_NUM;
	printf("%lld\n", ans % MOD_NUM);
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
ll num=1, ans=0, count=0, sum=0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  rep2(i, N) {
    if(i%3!=0 && i%5!=0) sum += i;
  }
  cout << sum << '\n';
  return 0;
}


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

namespace ABC134A
{
    class Program
    {
        static void Main(string[] args)
        {
            int r, s;

            var word = Console.ReadLine().Split(' ');
            r = int.Parse(word[0]);

            s = 3 * (r * r);

            Console.WriteLine(s);

            Console.ReadLine();


        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int f(int n){int s=0;while(n!=0){s+=n%10;n/=10;}return s;}

signed main() {
  cout << fixed << setprecision(15);
  int n,a,b;
  cin >> n >> a >> b;
  int q1=0,q2=0,q3=0,memo;
  rep(i,0,n){
    cin >> memo;
    if(memo<=a) q1++;
    else if(memo>a&&memo<=b) q2++;
    else q3++;
  }
  cout << min({q1,q2,q3}) << endl;
  return 0;
}


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

int main(void) {
    int N, M, L;
    cin >> N >> M >> L;
    long tmpSum, matrix1[N][M], matrix2[M][L];

    for(int i=0; i < N; i++)
        for(int j=0; j < M; j++)
            cin >> matrix1[i][j];

    for(int i=0; i < M; i++)
        for(int j=0; j < L; j++)
            cin >> matrix2[i][j];

    for(int i=0; i < N; i++) {
        for(int j=0; j < L; j++) {
            tmpSum = 0;
            for(int k=0; k < M; k++)
                tmpSum += matrix1[i][k] * matrix2[k][j];
            cout << tmpSum << (j == L-1 ? "" : " ");
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------

int main()
{
    double r;
    cin>>r;
    cout<<setprecision(10)<<2*M_PI*r<<endl;
}

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

int main() {
    int64_t a, b, c;
    std::cin >> a >> b >> c;

    if (c <= (a + b)) {
        std::cout << "No\n";
        return 0;
    }

    int64_t l = a * b * 4;
    int64_t r = (c - a - b) * (c - a - b);   

    if (l < r) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())

    Co = Counter(A)
    # print(Co)
    SUM = sum(A)
    for _ in range(Q):
        b,c = map(int,input().split())
        SUM += (c-b) * Co[b]
        Co[c] += Co[b]
        Co[b] = 0
        # print(Co)
        print(SUM)



main()


Measured memory_bytes: 24120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC165B()
{
	ll x;
	cin >> x;
	ll c = 100;
	ll i = 0;
	while (c < x)
	{
		c *= 1.01;
		++i;
	}
	cout << i << endl;
}

int main()
{
	ABC165B();
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100;

int N;
ll T[MAX_N];

ll GCD(ll a, ll b){
	if(a < b) swap(a, b);
	if(b == 0) return a;
	else return GCD(b, a % b);
}

ll LCM(ll a, ll b){
	return a / GCD(a, b) * b;
}

void solve(){
	ll ans = 1LL;
	for(int i = 0; i < N; i++){
		ans = LCM(ans, T[i]);
	}
	printf("%lld\n", ans);
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld", &T[i]);
	solve();
	return 0;
}


Measured memory_bytes: 764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        scanner.close();

        if (H == 1 || W == 1) {
            System.out.println(1);
            return;
        }

        int h = (H + 1) / 2;
        long ans = 0;
        for (int i = 1; i <= W; i++) {
            if (i % 2 == 0 && H % 2 != 0) {
                ans += h - 1;
            } else {
                ans += h;
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
def main():
    H, W = map(int, input().split())
    S = [["*" for _ in range(W + 2)] for _ in range(H + 2)]
    for i in range(1, H + 1):
        S[i][1: W + 1] = input()
    dx = [-1, 0, 1, -1, 1, -1, 0, 1]
    dy = [-1, -1, -1, 0, 0, 1, 1, 1]

    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if S[i][j] == "#":
                continue

            cnt = 0
            for k in range(8):
                if S[i + dx[k]][j + dy[k]] == "#":
                    cnt += 1

            S[i][j] = str(cnt)

    for i in range(1, H + 1):
        print("".join(S[i][1: W + 1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
n,k = map(int,input().split())

s=list(input())

memo = [0]

for i in range(1,n):
  if s[i] != s[i-1]:
    memo.append(i)

ans = 0

kyoukai_math = len(memo)

for i in range(kyoukai_math):
  if s[memo[i]] == '1':
    hasi = i+k*2+1
  else:
    hasi = i+k*2
    
  if hasi < kyoukai_math:
    ans = max(ans,memo[hasi]-memo[i])
  else:
    ans = max(ans,n-memo[i])
print(ans)

Measured memory_bytes: 49804
#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>;

int main()
{
  ll a, b, n;
  cin >> a >> b >> n;

  ll ans;

  ll x = b - 1 <= n ? b - 1 : n;
  long double first = a * x / b;
  long double second = x / b;
  ans = floorl(first) - a * floorl(second);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int A,B,C,n;
char ans[N];
string s[N];
void dfs(int num,int a,int b,int c)
{
	if(a<0||b<0||c<0) return;
	if(num==n+1){
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
		exit(0);
	}
	if(s[num]=="AB"){
		if(a) ans[num]='B',dfs(num+1,a-1,b+1,c);
		if(b) ans[num]='A',dfs(num+1,a+1,b-1,c); 
	}else if(s[num]=="BC"){
		if(b) ans[num]='C',dfs(num+1,a,b-1,c+1);
		if(c) ans[num]='B',dfs(num+1,a,b+1,c-1);
	}else{
		if(a) ans[num]='C',dfs(num+1,a-1,b,c+1);
		if(c) ans[num]='A',dfs(num+1,a+1,b,c-1);
	}
}
int main()
{
	cin>>n>>A>>B>>C;
	for(int i=1;i<=n;i++) cin>>s[i];
	dfs(1,A,B,C);
	cout<<"No";
}


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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  int nx, ny;
  nx = x + r;
  ny = y + r;
  if (x - r  < 0 || y - r < 0 || nx > W || ny > H) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 3096
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

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

const int N = 0, mod = 0;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int last = 0, odd = 0, cnt = 0;
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        res += x;
        if (x & 1)
            odd++;
        if (x == 0 || i == n - 1) {
            cnt += odd & 1;
            odd = 0;
        }
    }
    cout << (res - cnt) / 2 << '\n';





}




Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

class D {
    static class Node extends ArrayList<Node> {
        final int id;
        int depth = -1;
        boolean visited = false;
        int parent = -1;

        public Node(int id) {
            this.id = id;
        }
    }

    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        final Node[] ns = new Node[N];
        for (int i = 0; i < N; i++)
            ns[i] = new Node(i);
        for (int i = 0; i < N + M - 1; i++) {
            final int A = sc.nextInt() - 1;
            final int B = sc.nextInt() - 1;
            ns[A].add(ns[B]);
        }
        final ArrayDeque<Node> topological = new ArrayDeque<>();
        final ArrayDeque<Node> stack = new ArrayDeque<>();
        for (int i = 0; i < N; i++)
            if (!ns[i].visited) {
                stack.offerFirst(ns[i]);
                while (!stack.isEmpty()) {
                    final Node n = stack.pollFirst();
                    if (n.visited) {
                        topological.offerFirst(n);
                    } else {
                        n.visited = true;
                        stack.offerFirst(n);
                        for (final Node child : n)
                            stack.offerFirst(child);
                    }
                }
            }
        topological.peekFirst().depth = 0;
        while(!topological.isEmpty()) {
            final Node n = topological.pollFirst();
            for(final Node child : n)
                if(child.depth < n.depth + 1) {
                    child.depth = n.depth + 1;
                    child.parent = n.id;
                }
        }
        final PrintWriter pw = new PrintWriter(System.out, false);
        for (int i = 0; i < N; i++)
            pw.println(ns[i].parent + 1);
        pw.flush();
    }
}
public class Main {
    public static void main(String... args) {
        D.main();
    }
}


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

int main(){
  ll k;
  cin >> k;
  ll kd = k % 50;
  vector<ll> ans(50, k/50+49);
  rep(i, kd){
    rep(j, 50){
      if(j == i) ans.at(j) += 50;
      else ans.at(j)--;
    }
  }

  cout << 50 << endl;
  rep(i, 50){
    if(i != 0) cout << " ";
    cout << ans.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

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

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

#define int ll
signed main(void) {
	int N, A; cin >> N >> A;
	vector<int> X(N); for(auto &a:X) cin >> a;
	int maxX = *max_element(ALL(X));
	if(maxX < A){
		cout << 0 << endl;
		return 0;
	}
	vector<int> x(N);
	REP(i,N){
		x[i] = X[i] - A;
	}

	int dp[51][5001] = {};
	memset(dp, 0, sizeof(dp));

	dp[0][N*maxX] = 1;
	FOR(i,0,N){
		RFOR(j,0,2*N*maxX+1){
			if(0 <= j-x[i] and j-x[i] <= 2*N*maxX){
				dp[i+1][j] = dp[i][j-x[i]] + dp[i][j];
			}
			else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	cout << dp[N][N*maxX] - 1 << endl;
	return 0;
}


Measured memory_bytes: 2176
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    n = in_n()
    v = in_nl()
    c1 = Counter(v[::2]).most_common()
    c2 = Counter(v[1::2]).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1) == 1 and len(c2) == 1:
            count = n // 2
        elif len(c1) == 1:
            count = n // 2 + c2[1][1]
        elif len(c2) == 1:
            count = n // 2 + c1[1][1]
        else:
            count = max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    else:
        count = c1[0][1] + c2[0][1]
    print(n - count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25308
import bisect

N=int(input())
A=[int(input()) for i in range(N)]

DP=[float("inf")]*N

for a in A:
    pos=bisect.bisect_left(DP,a)
    DP[pos]=a

ANS=0
for i in range(N):
    if DP[i]!=float("inf"):
        ANS=i

print(ANS+1)


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

def main():
    import math
    LIST=[0,0,math.radians(90)]
    while True:
        a,b=map(float,input().split(","))
        if a==0 and b==0:
            break
        else:
            b=math.radians(b)
            LIST[0]+=a*math.sin(LIST[2])
            LIST[1]+=a*math.cos(LIST[2])
            LIST[2]-=b

    print(int(LIST[1]))
    print(int(LIST[0]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 7744
N,M=map(int,input().split())
es=[]
for _ in range(N-1+M):
    i,o=map(int,input().split())
    es.append((i-1,o-1))

from collections import defaultdict, deque
ins=defaultdict(int)
outs=defaultdict(list)

for i, o in es:
    outs[i].append(o)
    ins[o]+=1

q=deque()
for i in range(N):
    if ins[i]==0:
        q.append(i)
rank=[0]*N
while q:
    i=q.popleft()
    for o in outs[i]:
        ins[o]-=1
        if ins[o]==0:
            q.append(o)
            rank[o]=rank[i]+1
    
ans=[0]*N
for i in range(N):
    for x in outs[i]:
        if rank[x]-rank[i]==1:
            ans[x]=i+1

for i in range(N):
    print(ans[i])

Measured memory_bytes: 48868
//#include <fstream>

#include <iostream>
#include <algorithm>

using namespace std;

const int NMAX = 105;
const int WMAX = 100005;
int w[NMAX], v[NMAX];
long long dp[2][WMAX];
long long n, wtot;

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n >> wtot;
	for (int i = 1;i <= n;++i)
		cin >> w[i] >> v[i];
	for (int i = 1;i <= n;++i)
	{
		for (int j = 0;j <= wtot;++j)
		{
			dp[1][j] = dp[0][j];
			if (w[i] <= j && dp[1][j] < dp[0][j - w[i]] + v[i])
				dp[1][j] = dp[0][j - w[i]] + v[i];
		}
		for (int j = 0;j <= wtot;++j)
			dp[0][j] = dp[1][j];
	}
	long long ans = 0;
	for (int j = 0;j <= wtot;++j)
		ans = max(ans, dp[1][j]);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
typedef long long ll; typedef long double db;

vector<int> road, railway;
map<pair<int, int>, int> ans;

int find(int x, vector<int>&fa)
{
	if (x != fa[x])
		fa[x] = find(fa[x], fa);
	return fa[x];
}
void merge(int x, int y, vector<int>&fa)
{
	x = find(x, fa);
	y = find(y, fa);
	if (x == y) return;
	else fa[x] = y;
}

int main()
{
	int n, k, l;
	cin >> n >> k >> l;

	road.assign(n + 5, -1);
	railway.assign(n + 5, -1);

	for (int i = 1; i <= n; ++i)
	{
		road[i] = i;
		railway[i] = i;
	}

	while (k--)
	{
		int a, b;
		cin >> a >> b;
		merge(a, b, road);
	}
	while (l--)
	{
		int a, b;
		cin >> a >> b;
		merge(a, b, railway);
	}

	for (int i = 1; i <= n; ++i)
		++ans[make_pair(find(i, road), find(i, railway))];

	for (int i = 1; i <= n; ++i)
	{
		cout << ans[make_pair(find(i, road), find(i, railway))];
		if (i != n) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 15988
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
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;
}

int main() {
	char a;
	cin >> a;
	if ('a'<= a && a <= 'z') {
		cout << 'a';
	}
	else {
		cout << 'A';
	}
}

Measured memory_bytes: 3592
class Rmq:
    # 平方分割
    # 値を変更すると元のリストの値も書き換わる
    # 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990652#1
    def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
        self.sqrt_n = sqrt_n
        if hasattr(a, "__iter__"):
            from itertools import zip_longest
            self.n = len(a)
            self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
            self.layer1 = a
        elif isinstance(a, int):
            self.n = a
            self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
            self.layer1 = [inf] * a
        else:
            raise TypeError

    def get_min(self, l, r):
        sqrt_n = self.sqrt_n
        parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
        if parent_l < parent_r:
            return min(min(self.layer0[parent_l:parent_r]),
                       min(self.layer1[l:parent_l*sqrt_n]),
                       min(self.layer1[parent_r*sqrt_n:r]))
        else:
            return min(self.layer1[l:r])

    def set_value(self, idx, val):
        self.layer1[idx] = val
        idx0 = idx // self.sqrt_n
        idx1 = idx0 * self.sqrt_n
        self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])

    def chmin(self, idx, val):
        if self.layer1[idx] > val:
            self.layer1[idx] = val
            idx //= self.sqrt_n
            self.layer0[idx] = min(self.layer0[idx], val)

    def debug(self):
        print("layer0=", self.layer0)
        print("layer1=", self.layer1)

    def __getitem__(self, item):
        return self.layer1[item]

    def __setitem__(self, key, value):
        self.set_value(key, value)


def main():
    N, Q, *queries = map(int, open(0).read().split())
    seg = Rmq(N)
    Ans = []
    for com, x, y in zip(*[iter(queries)]*3):
        if com==0:
            seg.set_value(x, y)
        else:
            Ans.append(seg.get_min(x, y+1))
    print("\n".join(map(str, Ans)))


main()



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

using db  = double;
using ll  = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;

#define F                  first
#define S                  second
#define MP                 make_pair
#define PB                 push_back
#define deb(X)             cout << (X) << endl
#define ASH(X)             cout << (X) << " "
#define aLL(X)             X.begin(),X.end()
#define vLL(X)             array<ll,X>
#define s(X)               ((ll)(X).size())
#define deb1(x)            cout << #x << " " << x << endl;
#define deb2(x,y)          cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x,y,z)        cout << #x << " " << x << " " << #y << " " << y <<" "<< #z << " " << z << endl;
#define FOR(I,A,B)         for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A)        for(ll I = (B); I >=(A); I--)
#define mem0(X)            memset((X), 0, sizeof((X)))
#define mem1(X)            memset((X), -1, sizeof((X)))
#define BS(v,x)            binary_search(v.begin(),v.end(),x)
#define SORT(c)            (sort(c.begin(),c.end()))
#define Time               cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "sec \n"
#define SORT_UNIQUE(c)     (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x)       (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T;    cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define IOS                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const ll INF   = 1e18;
const int mod  = 1000000007;
const ll L_inf = 9223372036854775807;
const int inf  = 2147483647;
const int mx   = 32000;
bool isprime[mx];

ll POWER(ll y,ll z){ll res=1;while(z){if(z%2==1){res=(res*y)%mod;}y=(y*y)%mod;z>>=1LL;}return res;}
void SIEVE(){for(ll i=2; i<=mx; i++)isprime[i]=true;for(ll i=3; i<=mx; i+=2){if(isprime[i]==true)
{for(ll J=i*i; J<=mx; J+=i)isprime[J]=false;}}}

/************************************************/

void Execute()
{
      ll n, nb, val, q, a, b, k, c, l, r, d, x, y, p, m;
      cin >> x;
      if(x>=400 && x<=599) deb(8);
      else if(x>=600 && x<=799) deb(7);
      else if(x>=800 && x<=999) deb(6);
      else if(x>=1000 && x<=1199) deb(5);
      else if(x>=1200 && x<=1399) deb(4);
      else if(x>=1400 && x<=1599) deb(3);
      else if(x>=1600 && x<=1799) deb(2);
      else if(x>=1800 && x<=1999) deb(1);
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif

    IOS
    //CASES
   // {
        Execute();
        Time;
   // }
}
/**< 🤣🤣🤣 */



Measured memory_bytes: 3804
using System;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            string[] str = (Console.ReadLine()).Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            if (a < b && b < c)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8916
fun read(d:String = " ") = readLine()!!.split(d)
fun <T> readList(d:String = " ",f:String.()->T) = read(d).map {f(it)}

fun main() {
	val (n,m) = readList {toInt()}
	val neighbor = Array(n) {mutableSetOf<Int>()}

	for(i in 1..m) {
		val (a,b) = readList {toInt()-1}
		neighbor[a].add(b)
		neighbor[b].add(a)
	}

	val parent = IntArray(n) {-1}
	parent[0] = 0

	val o = mutableSetOf(0)
	while(o.isNotEmpty()) {
		val p = o.toSet()
		o.clear()
		for(i in p) {
			for(e in neighbor[i]) {
				if(parent[e]<0) {
					parent[e] = i+1
					o.add(e)
				}
			}
		}
	}

	println("Yes")
	parent.drop(1).forEach(::println)
}


Measured memory_bytes: 111144
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define M 998244353

ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        if(n%2==0)
        {
            ll res=fast(n/2,a);
            return (((res%M)*(res%M))%M);
        }
        else
        {
            ll res=fast(n/2,a);
            return (((((res%M)*a)%M)*res)%M);
        }
    }

}
const int N=1e6+5;
int d[N]={0};
void calc()
{
    int i,j;
    for(i=1;i<N;i++)
    {
        for(j=i;j<N;j+=i)
        {
            d[j]++;
        }
    }
}
int main()
{
    calc();
    int n;
    cin>>n;
    int i;
    int ans=0;
    for(i=1;i<n;i++)
    {
        ans+=d[n-i];
    }
    cout<<ans;


}


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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif


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

	vector<long long> items(n);

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

	long long mul = items[0];

	long long sum = 0;

	long long md = 1e9 + 7;

	for (int i = 1; i < n; i++) {

		long long persum = mul * items[i];
		persum = persum % md;

		mul = mul+ items[i];
		mul = mul % md;

		sum += persum;

		sum = sum % md;
	}

	cout << sum << nl;
}

int main()
{


	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}

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

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << B * (T/A) << endl;
    return 0;
}



Measured memory_bytes: 256
/* minimum_spanning_tree.cpp
    クラスカル法で最小全域木とそのコストを求める
    計算量: O(|E|log|V|)

    verified: AOJ GRL_2_A
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=ja
 */

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

/* UnionFind：素集合系管理の構造体(union by rank)
    isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
    unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
*/
struct UnionFind {  // The range of node number is u 0 v n-1
    vector<int> rank, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        rank.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        rank[x] = 0;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    void unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (rank[x] > rank[y]) {
            parents[y] = x;
        } else {
            parents[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
    int findRoot(int x) {
        if (x != parents[x]) parents[x] = findRoot(parents[x]);
        return parents[x];
    }
};

// 辺の定義
struct Edge {
    long long u;
    long long v;
    long long cost;
};
bool comp_e(const Edge &e1, const Edge &e2) { return e1.cost < e2.cost; }

/* Kruskal :クラスカル法で minimum spanning tree を求める構造体
    入力: 辺のvector, 頂点数V
    最小全域木の重みの総和: sum
    計算量: O(|E|log|V|)
*/
struct Kruskal {
    UnionFind uft;
    long long sum;  // 最小全域木の重みの総和
    vector<Edge> edges;
    int V;
    Kruskal(const vector<Edge> &edges_, int V_) : edges(edges_), V(V_) { init(); }
    void init() {
        sort(edges.begin(), edges.end(), comp_e);
        uft = UnionFind(V);
        sum = 0;
        for (auto e : edges) {
            if (!uft.isSame(e.u, e.v)) {
                uft.unite(e.u, e.v);
                sum += e.cost;
            }
        }
    }
};

int main() {
    int V, E;
    cin >> V >> E;
    vector<Edge> edges(E);
    for (int i = 0; i < E; i++) {
        long long s, t, w;
        cin >> s >> t >> w;
        Edge e = {s, t, w};
        edges[i] = e;
    }
    Kruskal krs(edges, V);
    cout << krs.sum << endl;
    return 0;
}



Measured memory_bytes: 7640
#include<stdio.h>
void mergeSort(int A[],int ,int );
void merge(int A[],int ,int ,int );
int Mid;
int c=0;
int L[500000],R[500000];
int main(){
  int A[1000000];
  int n,i;

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

  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",c);


  return 0;
}
void mergeSort(int A[],int Left,int Right){

  if(Left+1<Right){
      int Mid=(Left+Right)/2;
  mergeSort(A,Left,Mid);
  mergeSort(A,Mid,Right);
merge(A,Left,Mid,Right);

}
}

void merge(int A[],int Left,int Mid,int Right){
  int i,j,l1,l2,k;
l1=Mid-Left;
  l2=Right-Mid;

  for(i=0;i<l1;i++){
    L[i]=A[Left+i];
  }
  for(j=0;j<l2;j++){
    R[j]=A[Mid+j];
  }
  L[l1]=1000000000;
  R[l2]=1000000000;
  i=0;
  j=0;
  for(k=Left;k<Right;k++)
  if(L[i]<=R[j]){
    A[k]=L[i];
    i++;
    c++;

  }
  else{
    A[k]=R[j];
    j++;
    c++;

  }


}

Measured memory_bytes: 6444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define ln "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<int>())
#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main(){
    ll n;
    in1(n);
    vl h;
    h.PB(0);
    forn(i,n){
        ll input;
        in1(input);
        h.PB(input);
    }
    ll a[n+1];
    a[1]=0;
    for(ll i=2;i<=n;i++){
        if (i-2>=1){
            a[i]=min(a[i-2]+abs(h[i]-h[i-2]),a[i-1]+abs(h[i]-h[i-1]));
        }else a[i]=a[i-1]+abs(h[i]-h[i-1]);
    }
    out1(a[n]);
    return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

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, M;
  cin >> N >> M;
  if(N < M){
    cout << 0 << "\n";
    return 0;
  }
  ll x_tmp, y_tmp, z_tmp;
  vector<ll> ppp(N), ppn(N), pnp(N), npp(N);
  rep(i, 0, N){
    cin >> x_tmp >> y_tmp >> z_tmp;
    ppp[i] =  x_tmp+y_tmp+z_tmp;
    ppn[i] =  x_tmp+y_tmp-z_tmp;
    pnp[i] =  x_tmp-y_tmp+z_tmp;
    npp[i] = -x_tmp+y_tmp+z_tmp;
  }

  sort(ppp.begin(), ppp.end());
  sort(ppn.begin(), ppn.end());
  sort(pnp.begin(), pnp.end());
  sort(npp.begin(), npp.end());

  ll ans_ppp=0, ans_ppn=0, ans_pnp=0, ans_npp=0;
  rep(i, 0, M){
    ans_ppp += ppp[i];
    ans_ppn += ppn[i];
    ans_pnp += pnp[i];
    ans_npp += npp[i];
  }

  ll ans1 = max(max(abs(ans_ppp), abs(ans_ppn)), max(abs(ans_pnp), abs(ans_npp)));

  ans_ppp=0;
  ans_ppn=0;
  ans_pnp=0;
  ans_npp=0;

  rep(i, 0, M){
    ans_ppp += ppp[N-1-i];
    ans_ppn += ppn[N-1-i];
    ans_pnp += pnp[N-1-i];
    ans_npp += npp[N-1-i];
  }

  ll ans2 = max(max(abs(ans_ppp), abs(ans_ppn)), max(abs(ans_pnp), abs(ans_npp)));

  cout << max(ans1, ans2) << "\n";

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

a = []
while True:
    b = list(map(int, input().split()))
    if b[0] == 0 and b[1] == 0:
        break
    a.append(b)

for x in a:
    print(x[0], x[1]) if x[0] < x[1] else print(x[1], x[0])


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

const int INF = 2e9+7;

int solve(int arr[],int N,int M){
	int ret=0,temp;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			temp=arr[i]+arr[j];
			if(temp<=M) ret=max(ret,temp);
		}
	}
	
	return ret;
}

int main(){
	int N,M;
	while(1){
		cin>>N>>M;
		if(!N&&!M) break;
		int arr[N];
		for(int i=0;i<N;i++) cin>>arr[i];
		int ans=solve(arr,N,M);
		if(ans==0) cout<<"NONE";
		else cout<<ans;
		cout<<"\n";
	}
	return 0;
}


Measured memory_bytes: 3120
N,M = gets.split(" ").map{ |v|
	v.to_i
}
xs =  gets.split(" ").map{ |v|
	v.to_i
}
ys =  gets.split(" ").map{ |v|
	v.to_i
}
mod = 1_000_000_007

tate = 0
0.upto(N-2) do |i|
	tate += (xs[i+1] - xs[i]) * (i+1) * (N-i-1)
	tate = tate % mod
end

yoko = 0
0.upto(M-2) do |i|
	yoko += (ys[i+1] - ys[i]) * (i+1) * (M-i-1)
	yoko = yoko % mod
end

puts (tate * yoko) % mod


Measured memory_bytes: 15524
n, m, x = map(int, input().split())
bag = {}
for i in range(n):
    bag[i]=list(map(int, input().split()))

min_ = 10**10
for bit in range(1<<n):
    understanding = [0 for j in range(m)]
    c = 0
    for i in range(n):
        if bit & (1<<i):
            for k in range(m):
                understanding[k] += bag[i][k+1]
            c += bag[i][0]
            
    if all([a >= x for a in understanding] ):
        min_ = min(min_, c)
if min_ == 10**10:
    min_ = -1
print(min_)                
                
            

Measured memory_bytes: 9256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    string s;
    getline(cin, s);
    int T = atoi(s.c_str());
    while (T--) {
        getline(cin, s);
        if (s.size() && s[s.size()-1] == '\r') s.resize(s.size()-1);
        size_t ix = 0;
        while ((ix = s.find("Hoshino", ix)) != string::npos) {
            s[ix+6] = 'a';
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#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>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    int t = n - 1;
    rep(i, n) {
        int lim = 2;
        if (i == 0) lim = 1;
        rep(j, lim) {
            if (t > 0) {
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<mint> a(n+1, 0);
  rep(i, n) {
    int x; cin >> x;
    a[i+1] = x;
  }
  rep(i, n) a[i+1] += a[i];
  mint ans = 0;
  for(int i = 1; i <= n; ++i) ans += (a[i]-a[i-1])*(a[n]-a[i]);
  cout << ans.x << endl;
}


Measured memory_bytes: 4788
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (i*500+j*100+k*50) == X:
                counter += 1

print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	string s;
	cin >> s;
	int x = s.size();
	rep(i,x){
		cout << 'x';
	}
	cout << endl;
  return 0;
}


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

using namespace std;

struct UnionFind {
  std::vector<int> parent;
  int __size;
  UnionFind(int n) : parent(n, -1), __size(n) {}
  void unite(int x, int y) {
    if ((x = root(x)) != (y = root(y))) {
      if (parent[y] < parent[x]) { std::swap(x, y); }
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  int size(int x) { return -parent[root(x)]; }
  int size() { return __size; }
};

int main() {
  int N, K, L; cin >> N >> K >> L;
  UnionFind uf_tree1(N), uf_tree2(N);

  for (int i = 0; i < K; i++) {
    int p, q; cin >> p >> q;
    p--; q--;
    uf_tree1.unite(p, q);
  }
  for (int i = 0; i < L; i++) {
    int r, s; cin >> r >> s;
    r--; s--;
    uf_tree2.unite(r, s);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < N; i++) {
    auto p = make_pair(uf_tree1.root(i), uf_tree2.root(i));
    mp[p]++;
  }

  for (int i = 0; i < N; i++) {
    auto p = make_pair(uf_tree1.root(i), uf_tree2.root(i));
    cout << mp[p] << ((i == N-1) ? "\n" : " ");
  }

  return 0;
}

Measured memory_bytes: 13568