akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Calc
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  rep(i,k){
    if(b<=a){
      b*=2;
    }else if(c<=b){
      c*=2;
    }
    if(a<b && b<c){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}


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

int main(){
  int N,X,Y; cin >> N >> X >> Y;
  
  int count[5000]={};
  for(int i=1; i<=N-1; i++){
    for(int j=i+1; j<=N; j++){
      int dist = (X>=i?X-i:i-X)+1+(Y>=j?Y-j:j-Y);
      if(j-i<dist) dist=j-i;
      count[dist]++;
    }
  }
  
  for(int k=1; k<=N-1; k++) cout << count[k] << endl;
}

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

const int N = 500005;

int a[N], consecutive[N];

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

    string s; cin >> s;
    int n = s.size();
    consecutive[n + 1] = 0;
    for (int i = n; i >= 1; --i) {
        if (s[i-1] == '>') consecutive[i] = consecutive[i+1] + 1;
        else consecutive[i] = 0;
    }

    for (int i = 0; i <= n; ++i) {
        if (i == 0) a[i] = 0;
        else {
            if (s[i-1] == '>') a[i] = 0;
            else a[i] = a[i-1] + 1;
        }
        a[i] = max(a[i], consecutive[i+1]);
        // cerr << a[i] << endl;
    }

    long long sum = 0;
    for (int i = 0; i <= n; ++i) {
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
    const T inf = numeric_limits<T>::max();
    using P     = pair<T, int>;
    int n       = G.size();
    vector<T> d(n, inf);
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0;
    q.emplace(d[s], s);
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto &e : G[v]) {
            int u = e.first;
            T c   = e.second;
            if (d[u] > d[v] + c) {
                d[u] = d[v] + c;
                q.emplace(d[u], u);
            }
        }
    }
    return d;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<lint> x(2), y(2);
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    lint n;
    cin >> n;
    x.resize(n + 2);
    y.resize(n + 2);
    vector<lint> r(n + 2, 0);
    for (int i = 0; i < n; ++i) {
        cin >> x[i + 2] >> y[i + 2] >> r[i + 2];
    }
    vector<vector<pair<int, double>>> edges(n + 2);
    for (int i = 0; i < n + 2; ++i) {
        for (int j = 0; j < n + 2; ++j) {
            double dist = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            dist        = max(0.0, dist - r[i] - r[j]);
            edges[i].emplace_back(j, dist);
        }
    }
    auto d = dijkstra(0, edges);
    cout << fixed << setprecision(10) << d[1] << "\n";
    return 0;
}

Measured memory_bytes: 22524
using System;

namespace MinMaxandSum
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			//????°????
			int intMin = 0;
			//?????§???
			int intMax = 0;
			//????¨?
			long sum = 0;

			//1???????????\??????
			string n = Console.ReadLine ();
			int cnt = int.Parse (n); 

			//2???????????\??????
			string[] a = Console.ReadLine().Split(' ');

			//2????????§??\????????????1???????????????????°?????????\??????
			intMin = int.Parse(a[0]);
			//?????§?????????????°???????????????\??????
			intMax = intMin;
			//?????°???????????????
			sum += intMin;

			//2????????\???
			for(int i = 1; i < cnt; i++){

				int intNum = int.Parse(a[i]);

				//????°???????????°???????
				if(intNum < intMin) {
					intMin = intNum;
				}
				//?????§???????????§??????
				if(intMax < intNum) {
					intMax = intNum;
				}
				//?????°???????????????
				sum += intNum;	
			}
			Console.WriteLine(intMin + " " + intMax + " " + sum);
		}
	}
}

Measured memory_bytes: 19932
using System;
using System.Linq;

namespace ABC127
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] n = s.Select(x => int.Parse(x)).ToArray();

            int xi = n[2];

            for (int i = 0; i < 10; i++)
            {
                xi = (xi * n[0]) - n[1];
                Console.WriteLine(xi);
            }
        }
    }
}

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

using namespace std;

const int MAXN = 500010;
const int INF = 1000000010;

int n, m;
int cntNode;

int dist[MAXN];

vector<int> adj[MAXN];
vector<int> weight[MAXN];

deque<int> d;

map<int,int> indNode[MAXN];

void BFS01(int s)
{
	for(int i = 1 ; i <= cntNode ; i++)
		dist[i] = INF;

	dist[s] = 0;
	d.push_front( s );

	while( !d.empty() )
	{
		int cur = d.front();
		d.pop_front();

		for(int i = 0 ; i < (int)adj[cur].size() ; i++)
		{
			int viz = adj[cur][i];
			int w = weight[cur][i];

			if( dist[viz] <= dist[cur] + w ) continue;

			dist[viz] = dist[cur] + w;

			if( w == 0 ) d.push_front( viz );
			else d.push_back( viz );
		}
	}
}

int getExpandedNode(int node, int color)
{
	if( indNode[node][color] == 0 )
		indNode[node][color] = ++cntNode;

	return indNode[node][color];
}

void addEdge(int U, int V, int W)
{
	adj[U].push_back( V );
	weight[U].push_back( W );
}

int main()
{
	scanf("%d %d",&n,&m);

	cntNode = n;

	for(int i = 1 ; i <= m ; i++)
	{
		int U, V, C;
		scanf("%d %d %d",&U,&V,&C);

		int A = getExpandedNode( U , C );
		int B = getExpandedNode( V , C );

		addEdge( A , B , 0 );
		addEdge( B , A , 0 );
	}

	for(int i = 1 ; i <= n ; i++)
	{
		for(auto it = indNode[i].begin() ; it != indNode[i].end() ; it++)
		{
			addEdge( i , it->second , 0 );
			addEdge( it->second , i , 1 );
		}
	}

	BFS01( 1 );

	if( dist[n] == INF ) printf("-1\n");
	else printf("%d\n",dist[n]);
}

Measured memory_bytes: 103784
import java.util.Scanner;

class Main {
    private static boolean[] calcPrimeTable(int n) {
        boolean[] table = new boolean[n + 1];
        table[0] = table[1] = true;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (!table[i]) {
                for (int j = i + i; j <= n; j += i) {
                    table[j] = true;
                }
            }
        }
        return table;
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        boolean[] table = calcPrimeTable(1000000);

        while (true) {
            int a = scanner.nextInt();
            int d = scanner.nextInt();
            int n = scanner.nextInt();
            int result;

            if (a == 0 && d == 0 & n == 0) {
                break;
            }

            for (int i = 0; ; i++) {
                if (!table[a + d * i]) {
                    n--;
                }
                if (n == 0) {
                    result = a + d * i;
                    break;
                }
            }
            System.out.println(result);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 13000
package main

import "fmt"

func main() {
	var w, h, n int
	fmt.Scan(&w, &h, &n)
	var c = make([][]bool, h)
	for i := 0; i < h; i++ {
		c[i] = make([]bool, w)
	}
	for i := 0; i < n; i++ {
		var x, y, a int
		fmt.Scan(&x, &y, &a)

		switch a {
		case 1:
			for j := x - 1; j >= 0; j-- {
				for k := 0; k < h; k++ {
					c[k][j] = true
				}
			}
		case 2:
			for j := x; j < w; j++ {
				for k := 0; k < h; k++ {
					c[k][j] = true
				}
			}
		case 3:
			for j := y - 1; j >= 0; j-- {
				for k := 0; k < w; k++ {
					c[j][k] = true
				}
			}
		case 4:
			for j := y; j < h; j++ {
				for k := 0; k < w; k++ {
					c[j][k] = true
				}
			}
		}
	}
	sum := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if c[i][j] {
				sum += 1
			}
		}
	}
	fmt.Println(w*h - sum)
}


Measured memory_bytes: 640
def main():
    n = input()
    aa = map(int, raw_input().split())
    ans = [0] * n
    m = 0
    for i in xrange((n + 1) // 2, n):
        if aa[i] == 1:
            ans[i] = 1
            m += 1
    for i in xrange((n + 1) // 2 - 1, -1, -1):
        s = sum(ans[i::i + 1]) % 2
        if aa[i] != s:
            ans[i] = 1
            m += 1
    print m
    for i, a in enumerate(ans, 1):
        if a:
            print i


if __name__ == '__main__':
    main()


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

long long LARGE_INT = pow(10, 9) + 7;

vector<int> x;

void factorize(int n){
    int ans = 1;
    int num = n;

    for(int i = 2; i<=n; i++){
        while(num % i == 0){
            x.at(i)++;
            num /= i;
        }
    }

    return;
}

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

    x.assign(n+1, 0);

    for (int i=2; i<=n; i++){
        factorize(i);
    }

    long long ans = 1;
    for (int i = 2; i<=n; i++){
        ans *= 1 + x.at(i);
        ans %= LARGE_INT;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int card[100000];
int main(){
  int n,m;cin>>n>>m;
  for(int i = 0; m > i; i++){
    int l,r;cin>>l>>r;
    card[l-1]++;
    card[r]--;
  }
  int ret =0;
  for(int i = 0; n > i; i++){
    if(0 < i)card[i] += card[i-1];
    if(card[i] == m)ret++;
  }
  cout << ret << endl;
}
    
  
  

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

string s;

int main(void)
{
	cin >> s;
	
	int n = 0;
	for(int i = 0; i < s.size(); i++){
		if(n == 0 && s[i] == 'C') n++;
		if(n == 1 && s[i] == 'F') n++;
	}
	
	if(n == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int MAX_V = 1e5;
vector<int> es[MAX_V];

int dfs(int now){
    if(es[now].empty()) return 0;
    int ret = 0;
    vector<int> nums;
    for(auto &e: es[now]){
        nums.pb(dfs(e));
    }
    sort(all(nums), greater<int>());
    rep(i, sz(nums)) chmax(ret, nums[i]+i+1);
    return ret;
}

int main(){
    int N;
    cin >> N;
    rep2(i, 2, N){
        int A; cin >> A;
        es[A-1].pb(i-1);
    }
    cout << dfs(0) << endl;
}

Measured memory_bytes: 13568
n=gets.to_i
a=gets.split.map(&:to_i)
sum=[a[0]]
all=a.sum
ans=(2*a[0]-all).abs
if n-1>2
  (1...n-1).each do |i|
    sum[i]=sum[i-1]+a[i]
    ans=[ans,(sum[i]-all+sum[i]).abs].min
  end
end
p ans


Measured memory_bytes: 29212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A[200000],sum=0,ans=1e9,B[200000]={0};
    cin>>n;
    rep(i,n) cin>>A[i],sum+=A[i];
    B[0]=A[0];
    rep(i,n-1) B[i+1]=B[i]+A[i+1];
    rep(i,n) ans=min(ans,abs(B[i]-(sum-B[i])));
    cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n;
double x[10], ta;
string u[10];

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> x[i] >> u[i];
		if (u[i] == "JPY")ta += x[i];
		else ta += x[i] * 380000.0;
	}
	cout << ta << endl;
	ggr
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    int ans = 0;
    cin >> s;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            bool left = false;
            bool right = false;
            for (int j = 0; j < i; j++) {
                if (s.at(j) == c) left = true;
            }
            for (int j = i; j < n; j++) {
                if (s.at(j) == c) right = true;
            }
            if (left && right) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
N = int(raw_input())
A = map(int, raw_input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

L = [0,]* (N+1)
for i in range(0, N-1):
    L[i+1] = gcd(L[i], A[i])

R = [0,] * (N+1)
for i in range(N-1, 0, -1):
    R[i] = gcd(R[i+1], A[i])

M = list()
for i in xrange(N):
    M.append(gcd(L[i], R[i+1]))

print max(M)

Measured memory_bytes: 13716
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

string s;
ll N;
ll J[100000],O[100000],I[100000];
ll rJ[100000],rO[100000],rI[100000];
ll ans=0;
ll OI,JO;
int main()
{
	cin>>N;
	cin>>s;
	rep(i,N){
		if(s[i]=='J'){
			J[i]++;
			rJ[i]++;
		}
		else if(s[i]=='O'){
			O[i]++;
			rO[i]++;
		}
		else {
			I[i]++;
			rI[i]++;
		}
	}
	rep(i,N-1){
		J[i+1]+=J[i];
		O[i+1]+=O[i];
		I[i+1]+=I[i];
	}
	rrep(i,N-1){
		rJ[i]+=rJ[i+1];
		rO[i]+=rO[i+1];
		rI[i]+=rI[i+1];
	}
	ll cnt=0;
	rep(i,N){
		if(s[i]=='O'){
			ans+=J[i]*rI[i];
			OI+=rI[i];
			JO+=J[i];
		}
		cnt=max(cnt,J[i]*rI[i]);
	}
	cout<<ans+max(cnt,max(JO,OI))<<endl;
}

Measured memory_bytes: 8000
import math
import sys
from fractions import gcd
m=10**9 + 7 
sys.setrecursionlimit(1000010)
(N, M) = list(map(int,input().split()))
A  = list(map(int,input().split()))
B = [ a//2 for a in A]

def log2N (x):
    c = 0
    while True:
        if x % 2 != 0:
            return c
        x = x // 2
        c = c + 1


def lcmn(B):
    if len(B)<1 :
        return 1
    elif len(B) == 1:
        return B[0]
    
    x = B[0] * B[1] // gcd(B[0],B[1])
    if x > M:
        return -1 

    for i in range(2,len(B)):
        x  = lcmn([x,B[i]])
        if x > M:
            return -1 
    return x
    

#print(N,M,A,B)

# print(lcmn(B))

p = log2N(B[0])
# print(p)
for i in range(1,len(B)):
    # print(log2N(B[i]))
    if p != log2N(B[i]):
        print(0)
        exit(0)
        
x = lcmn(B)
if x == -1:
    print(0)
else:
    print((M//x+1)//2)



Measured memory_bytes: 16292
use std::io::stdin;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Read;

#[derive(Debug)]
struct Input {
    a: u8,
    b: u8,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let input = match (iter.next(), iter.next()) {
        (Some(a_str), Some(b_str)) => {
            let (a, b): (u8, u8) = match (a_str.parse(), b_str.parse()) {
                (Ok(a), Ok(b)) => (a, b),
                _ => return Err(Error::new(ErrorKind::InvalidInput, "")),
            };
            Input { a: a, b: b }
        }
        _ => return Err(Error::new(ErrorKind::InvalidInput, "")),
    };
    Ok(input)
}

fn handle_output(input: Input) -> Result<String, Error> {
    Ok(format!(
        "{}",
        vec![
            input.a + input.a - 1,
            input.a + input.b,
            input.b + input.b - 1
        ]
        .iter()
        .max()
        .unwrap()
    ))
}

fn main() {
    let mut input_str = String::new();
    let stdin = stdin();
    stdin.lock().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}


Measured memory_bytes: 4352
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i]+L[j] > L[k] and (L[i]!=L[j] and L[j]!=L[k] and L[i]!=L[k]):
                count += 1
print(count)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
using namespace std;
int main(){
  int nagasa = 0;
  cin >> nagasa;
  string s,t;
  cin >> s >> t;
  for(int i = 0;i <= nagasa - 1;i++){
    if(i == nagasa - 1){
      cout << s[i] << t[i] << endl;
    } 
    else{
      cout << s[i] << t[i];
    }
  }
  return 0;
}



Measured memory_bytes: 256
def count_chars(s)
  h = Hash.new { 0 }
  s.chars.each { |c| h[c] += 1 }
  h
end

s = gets.chomp
t = gets.chomp

sh = count_chars(s)
th = count_chars(t)

ls = sh.each_key.map do |key|
  sh[key]
end
ls.sort!.reverse!

lt = th.each_key.map do |key|
  th[key]
end
lt.sort!.reverse!

puts "No" if lt !=ls 
puts "Yes" if lt == ls


Measured memory_bytes: 22600
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n,m,k;
int a[M],b[M];


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    rep(i,1,n+1){
        cin >> a[i];
        a[i]+=a[i-1];
    }
    rep(i,1,m+1){
        cin >> b[i];
        b[i]+=b[i-1];
    }
    int ans=0;
    int j=m;
    for(int i=0; i<=n; i++){
        if(a[i]>k) break;
        while(a[i]+b[j]>k)
            j--;
        ans=max(ans,i+j);
        //cout << i << " " << j << "\n";
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
int x[51],y[51];
int main()
{
	int cnt,i,j,n,m,k,l,ans=INT_MAX,cx,cy;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&x[i],&y[i]);
	if(n==1)
	{
		printf("1");
		return 0;
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if (i==j)
				continue;
			cx=x[j]-x[i];
			cy=y[j]-y[i];
			cnt=0;
			for(k=0;k<n;k++)
				for(l=0;l<n;l++)
					if(cx==x[l]-x[k]&&cy==y[l]-y[k])
						cnt++;
			ans=min(ans,n-cnt);
		}
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;
vector<int> DP;
int solve(int u , vector<vector<int>>& g){
	if(DP[u] != -1) return DP[u];
	int ans = 0;
	for(int & v : g[u]){
		ans = max(ans , 1 + solve(v , g));
	}
	return DP[u] = ans;
}

int main(){
	int n , m;
	cin >> n >> m;
	vector<vector<int>> g(n + 1);
	DP.resize(n + 1 , -1);

	for(int i = 1 ; i <= m ; i++){
		int u , v;
		cin >> u >> v;
		g[u].push_back(v);
	}
	int ans = 0;
	for(int i = 1 ; i <= n ; i++){
		if(DP[i] == -1){
			ans = max(ans , solve(i , g));
		}else ans = max(ans , DP[i]);
	}

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

}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;


int main() {
	LL X, Y;
	cin >> X >> Y;
	int ret = 0LL;
	LL v = X;
	while (true) {
		ret++;
		if (Y / 2LL < v)
			break;
		v *= 2LL;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll a[N], res, sum;
bool used[N];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], sum ^= a[i];   
   for (int bit = 60; bit >= 0; bit --) {
      if (!(sum & (1ll << bit))) continue;
      for (int i = 1; i <= n; i ++)
         if (a[i] & (1ll << bit))
            a[i] -= (1ll << bit);
   }                                               
   for (int bit = 60; bit >= 0; bit --) {
      int pos = -1;
      for (int i = 1; i <= n; i ++) {
         if (used[i]) continue;
         if (a[i] & (1ll << bit)) {
            if (pos == -1 || a[pos] < a[i])
               pos = i;
         }
      }
      if (pos != -1) {
         used[pos] = 1;
         for (int i = 1; i <= n; i ++)
            if (i != pos && (a[i] & (1ll << bit)))
               a[i] ^= a[pos];
      }
   }
   for (int i = 1; i <= n; i ++) res ^= a[i];
   cout << res + (sum ^ res);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1152
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      string[] str=Console.ReadLine().Split(' ');
      int ans=0;
      for(int i=1;i<(N-1);i++){
        if((int.Parse(str[i-1])<int.Parse(str[i]))&&(int.Parse(str[i])<int.Parse(str[i+1])))
        {
         ans++; 
        }else if((int.Parse(str[i-1])>int.Parse(str[i]))&&(int.Parse(str[i])>int.Parse(str[i+1])))
                 {
          ans++;}
                 }
	Console.WriteLine(ans);
        
	
    }
    
  }

}

Measured memory_bytes: 11092
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N;
	cin >> N;

	map<int, int> mp;
	int a;
	for (int i = 0; i < N; i++) {
		cin >> a;
		mp[a]++;
	}

	int ans = 0;
	for (const auto &e : mp) if (e.second & 1) ans++;

	cout << ans << "\n";

	return 0;
}

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

class BIT {
public:
	int size_ = 1;
	vector<int> bit;

	void init(int sz) {
		size_ = sz + 2;
		bit.resize(size_ + 2, 0);
	}
	void add(int pos, int x) {
		pos++;
		while (pos <= size_) {
			bit[pos] += x;
			pos += (pos&-pos);
		}
	}
	int sum(int pos) {
		int s = 0; pos++;
		while (pos >= 1) {
			s += bit[pos];
			pos -= (pos&-pos);
		}
		return s;
	}
};

long long mod = 998244353;
long long N, X[1 << 18], Y[1 << 18], LX[1 << 18], LY[1 << 18], P1[1 << 18], P2[1 << 18], P3[1 << 18], P4[1 << 18];
long long power[1 << 18];
vector<long long> GX, GY, R[1 << 18];
BIT Z1, Z2;

int main() {
	cin >> N;
	power[0] = 1; for (int i = 1; i <= 200000; i++) power[i] = (2LL * power[i - 1]) % mod;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		GX.push_back(X[i]);
		GY.push_back(Y[i]);
	}
	sort(GX.begin(), GX.end()); GX.erase(unique(GX.begin(), GX.end()), GX.end());
	sort(GY.begin(), GY.end()); GY.erase(unique(GY.begin(), GY.end()), GY.end());

	for (int i = 0; i < N; i++) {
		X[i] = lower_bound(GX.begin(), GX.end(), X[i]) - GX.begin(); X[i]++; LX[X[i]]++;
		Y[i] = lower_bound(GY.begin(), GY.end(), Y[i]) - GY.begin(); Y[i]++; LY[Y[i]]++;
		R[X[i]].push_back(i);
	}
	for (int i = 1; i <= GX.size(); i++) LX[i] += LX[i - 1];
	for (int i = 1; i <= GY.size(); i++) LY[i] += LY[i - 1];

	Z1.init(N + 2);
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < R[i].size(); j++) {
			P1[R[i][j]] = Z1.sum(Y[R[i][j]] - 1);
			P2[R[i][j]] = Z1.sum(N + 1) -  Z1.sum(Y[R[i][j]]);
		}
		for (int j = 0; j < R[i].size(); j++) Z1.add(Y[R[i][j]], 1);
	}
	Z2.init(N + 2);
	for (int i = N; i >= 1; i--) {
		for (int j = 0; j < R[i].size(); j++) {
			P3[R[i][j]] = Z2.sum(Y[R[i][j]] - 1);
			P4[R[i][j]] = Z2.sum(N + 1) - Z2.sum(Y[R[i][j]]);
		}
		for (int j = 0; j < R[i].size(); j++) Z2.add(Y[R[i][j]], 1);
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		long long V1 = LX[X[i] - 1], V2 = N - LX[X[i]];
		long long V3 = LY[Y[i] - 1], V4 = N - LY[Y[i]];
		ans += power[V1]; ans %= mod;
		ans += power[V2]; ans %= mod;
		ans += power[V3]; ans %= mod;
		ans += power[V4]; ans %= mod;
		ans -= power[P1[i]]; ans += mod; ans %= mod;
		ans -= power[P2[i]]; ans += mod; ans %= mod;
		ans -= power[P3[i]]; ans += mod; ans %= mod;
		ans -= power[P4[i]]; ans += mod; ans %= mod;
		ans += power[0]; ans += mod; ans %= mod;
	}
	cout << (1LL * N * power[N] - ans + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 35812
#include<iostream>
#include<cmath>
#include<climits>
using namespace std;
typedef struct{int x;int y;}co;
int main(){
    int n,m,min=INT_MAX,min_c; cin>>n>>m;
    co s[n],c[m];
    int d[m];
    for(int i=0;i<n;i++)cin>>s[i].x>>s[i].y;
    for(int i=0;i<m;i++)cin>>c[i].x>>c[i].y;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)d[j]=abs(s[i].x-c[j].x)+abs(s[i].y-c[j].y);
        min=INT_MAX;
        for(int j=0;j<m;j++)if(d[j]<min){min=d[j];min_c=j;}
        cout<<min_c+1<<endl;
    }
    return 0;
}

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

using namespace std;

static int dp[101];

bool calc(int n) {
  if (n <= 0) {
    return false;
  }
  if (dp[n] > 0) {
    return true;
  }
  if (dp[n] < 0) {
    return false;
  }
  bool const ret = calc(n - 4) || calc(n - 7);
  dp[n] = ret ? 1 : -1;
  return ret;
}

int main() {
  dp[0] = -1;
  dp[1] = -1;
  dp[2] = -1;
  dp[3] = -1;
  dp[4] = 1;
  dp[7] = 1;
  int n;
  std::cin >> n;
  std::cout << (calc(n) ? "Yes" : "No") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <vector>
#include <cstring>
#define N 200005

using namespace std;

struct edge{
	int to, nxt;
}e[N << 1];

int n, cnt, num, tot;
int a[N], p[N], fir[N], dfn[N], low[N], co[N];

stack < int > st;
vector < int > G[N];

void add(int ,int);
void Tarjan(int);
void dfs(int ,int);

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d",p + i), add(p[i], i);
	for(int i = 1; i <= n; ++i)
		if(!dfn[i]) Tarjan(i);
	bool flag = true;
	for(int i = 1; i <= tot; ++i){
		int sz = G[i].size();
		if(sz == 1 || sz % 2 == 0) continue;
		for(int j = 0; j < sz; ++j)
			dfs(G[i][j], co[G[i][j]]);
		bool book = true;
		for(int j = 1; j < sz; ++j)
			if(a[G[i][j]] != a[G[i][j - 1]]){
				book = false;break;
			}
		if(book) flag = false;
	}
	if(flag) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

void add(int u,int v){
	e[++cnt].to = v;e[cnt].nxt = fir[u];fir[u] = cnt;
	return ;
}

void Tarjan(int u){
	dfn[u] = low[u] = ++num;
	st.push(u);
	for(int i = fir[u]; i; i = e[i].nxt){
		int v = e[i].to;
		if(!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
		else if(!co[v]) low[u] = min(low[u], dfn[v]);
	}
	if(low[u] == dfn[u]){
		co[u] = ++tot;G[tot].push_back(u);
		while(st.top() != u){
			co[st.top()] = tot;
			G[tot].push_back(st.top());
			st.pop();
		}
		st.pop();
	}
	return ;
}

void dfs(int u,int x){
	bool vis[100];memset(vis, false, sizeof vis);
	for(int i = fir[u]; i; i = e[i].nxt){
		int v = e[i].to;
		if(co[v] == x) continue;
		dfs(v, x);vis[a[v]] = true;
	}
	int pos = 0;
	while(vis[pos]) ++pos;
	a[u] = pos;
	return ;
}


Measured memory_bytes: 23036
def exgcd(x,y):
  a0,a1=1,0
  b0,b1=0,1
  while y>0:
    q=x//y
    a2=a0-q*a1
    b2=b0-q*b1
    x,y=y,x%y
    a0,a1=a1,a2
    b0,b1=b1,b2
  return [a0,b0]
  
x,y=map(int,input().split())
ans=exgcd(x,y)
print(ans[0],ans[1])


Measured memory_bytes: 5600
n = int(input())
v_L = list(map(int,input().split()))
c_L = list(map(int,input().split()))


ans = 0
for val in range(len(v_L)):
    if v_L[val] - c_L[val] >= 0:
        ans += v_L[val] - c_L[val]

print(ans)


Measured memory_bytes: 38384
#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,k;
    cin >> n;
    vector <vector <int>> s(100001,vector <int> (2,0)),s2(100001, vector <int> (2,0));
    rep(i,n){
        cin >> k;
        if(i%2==0){
            ++s2[k][0];
        }
        else{
            ++s[k][0];
        }
    }

    rep(i,100001){
        s[i][1]=i;
        s2[i][1]=i;
    }

    sort(s2.begin(),s2.end());
    sort(s.begin(),s.end());
    int ans;
    if(s[100000][1]==s2[100000][1]){
        ans=max(s[100000][0]+s2[99999][0],s[99999][0]+s2[100000][0]);
    }
    else{
        ans=s[100000][0]+s2[100000][0];
    }

    cout << n-ans << endl;
    
    

    return 0;
}

Measured memory_bytes: 11136
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

ai = 0
bi = 0

for i in range(N-1):
    for j in range(i+1, N):
        if(A[i] > A[j]):
            ai += 1
            ai %= mod

for i in range(N):
    for j in range(N):
        if (A[i] < A[j]):
            bi += 1
            bi %= mod

ansa = ai * K % mod
ansb = K * (K-1) // 2 % mod
ansb = ansb * bi % mod
ans = (ansa + ansb) % mod
print(ans)



Measured memory_bytes: 3188
import sys
import math

while True:
    try:
	n = (int)(input())
	res = 0
	for i in range(0,10):
	    for j in range(0,10):
		for k in range(0,10):
		    for l in range(0,10):
			if (i+j+k+l == n):
			    res += 1
	print (res)
    except EOFError:
	break

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

#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;
#define endl '\n'
#define matrix vector<vector<ll>>
ll fact[4009] , inv[4009]  , mod=998244353 , n,  k;
ll fp(ll x , ll exp)
{
    if(exp == 0)
        return 1;
    if(exp % 2 == 0)
        return fp((x * x) % mod, exp / 2) % mod;
    return ((fp((x * x) % mod, exp / 2) % mod) * x) % mod;
}
void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}
int main()
{
    VIC
    cin>>k>>n;
    calcFacAndInv(4000);
    for(ll i=2;i<=2*k;i++)
    {
        ll p=0, ans = ncr(n+k-1,k-1);
        for(int j=1;j<=i/2;j++)
            if(j <= k && i-j<=k)
                p++;
            for(int j=1;j<=p;j++)
            {
              //  cout<<j<<" "<<p<<endl;
              if(2*j>n)break;
                ll cur=ncr(p,j) * ncr(n-2*j+k-1,k-1);
                if(j%2==0)
                    ans+=cur;
                else
                    ans-=cur;
                ans %= mod;
                ans=(ans+ mod)%mod;
            }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 384
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getNString n = map readString <$> replicateM n BS.getLine

check :: [String] -> [String] -> Char -> String
check _ [] c = "Yes"
check ds (w : ws) c
  | w `elem` ds = "No"
  | c == head w = check (w : ds) ws (last w)
  | otherwise = "No"

main = do
  n <- getInt
  ws <- getNString n
  let ws' = map head ws
  putStrLn $ check [head ws'] (tail ws') (last (head ws'))


Measured memory_bytes: 508
#include<iostream>
#include<utility>
#include<algorithm>

using namespace std;

struct card {
	char suit, value;
	bool operator==(const card &r) const {
		return suit==r.suit && value==r.value;
	}
};

void bubbleSort(card *c, int n) {
	for(int i=0; i<n; i++) {
		for(int j=n-1; j>i; j--) {
			if(c[j].value < c[j-1].value) swap(c[j], c[j-1]);
		}
	}
}


void selectionSort(card *c, int n) {
	for(int i=0; i<n; i++) {
		int minj=i;
		for(int j=i+1; j<n; j++) {
			if(c[j].value < c[minj].value) minj=j;
		}
		if(i!=minj) swap(c[i], c[minj]);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	card A[36], B[36];
	cin>>n;
	for(int i=0; i<n; i++) cin>>A[i].suit>>A[i].value;
	copy(A, A+n, B);
	bubbleSort(A, n);
	selectionSort(B, n);
	cout<<A[0].suit<<A[0].value;
	for(int i=1; i<n; i++) cout<<' '<<A[i].suit<<A[i].value;
	cout<<"\nStable\n"<<B[0].suit<<B[0].value;
	for(int i=1; i<n; i++) cout<<' '<<B[i].suit<<B[i].value;
	cout<<(equal(A, A+n, B)?"\nStable\n":"\nNot stable\n");
	return 0;
}



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

#define Int int_fast64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T,vector<T>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
#define LL(n) Int n; cin >> n;
#define RP(n) for (Int i = 0; i < n; i++)
#define REP(n,i) for (Int i = 0; i < n; i++)

struct node{
    int to;
    int length;
};

vector<vector<node>> to;
vector<int> flag;
vector<int> c;

void dfs(int from){
    for (auto z : to.at(from)){
        int next = z.to;
        if (flag.at(next) == 0) {
            flag.at(next) = 1;
            if (z.length % 2 == 0) {
                c.at(next) = c.at(from);
            } else {
                c.at(next) = 1 - c.at(from);
            }
            dfs(next);
        }
    }
}

int main(void){
    LL(n);
    to.resize(n);
    flag.resize(n);
    c.resize(n);
    for (int i = 0 ;i < n - 1 ; i++){
        int a, b ,length;
        cin >> a >> b >> length;
        a--;
        b--;
        to.at(a).push_back({b,length});
        to.at(b).push_back({a,length});
    }
    dfs(0);
    for (auto z : c){
        cout << z << endl;
    }
}

Measured memory_bytes: 8576
N = int(input())
F = [int(input().replace(" ", ''), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for f, p in zip(F, P):
        n_store = "{:010b}".format(i & f).count("1")
        outcome += p[n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<int> a(n);
    int max = 0;
    for(int in=0;in<n;in++) {
        cin >> a[in];
        if(max<a[in]) max = a[in];
    }

    int l = 1, r = max, mid, ans = max, ktmp, times;
    while(l<r) {
        mid = l + (r - l) / 2;

        ktmp = 0;
        for(int in=0;in<n;in++) {
            times = a[in] / mid;
            if(a[in]%mid!=0) times++;
            times--;
            ktmp += times;
        }
        if(ktmp<=k) {
            ans = min(ans, mid);
            r = mid;
        }
        else l = mid + 1;
    }

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


Measured memory_bytes: 3980
import java.util.*;

public class Main {
	ArrayList<ArrayList<Edge>> pass;
	long [] close;
	
	class Edge implements Comparable<Edge>{
		int from,to, cost;
		public Edge(int from, int to, int cost) {
			this.from = from; this.to = to; this.cost = cost;
		}
		public int compareTo(Edge o) {
			if(this.cost < o.cost)return -1;
			if(this.cost > o.cost)return 1;
			return 0;
		}
	}
	
	void dfs(int now, int prev, long value){
		close[now] = value;
		
		for(Edge e: pass.get(now)){
			if(e.to == prev) continue;
			dfs(e.to, now, value + e.cost);
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			pass = new ArrayList<>();
			for(int i = 0; i < n; i++){
				pass.add(new ArrayList<>());
			}
		
			
			for(int i =0; i < n-1; i++){
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1; 
				int c = sc.nextInt();
				pass.get(a).add(new Edge(a, b, c));
				pass.get(b).add(new Edge(b, a, c));
			}
			int q = sc.nextInt();
			int start = sc.nextInt() -1;
			
			close = new long[n];
			Arrays.fill(close, Long.MAX_VALUE);
			dfs(start, -1, 0);
			
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < q; i++){
				int x = sc.nextInt()-1;
				int y = sc.nextInt()-1;
				sb.append(close[x] + close[y] + "\n");
			}
			System.out.print(sb.toString());
		}

	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 197780
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

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

using namespace std;

int N;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  int ans = 0;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    ans += r-l+1;
  }
  cout << ans << endl;
}


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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			string line = "";
			var r = new List<int[]>();
			while ((line = Console.ReadLine()) != null)
			{
				r.Add(line.Split(',').Select(i => int.Parse(i)).ToArray());
			}
			Console.WriteLine(r.Select(i => i[0] * i[1]).Sum());
			Console.WriteLine("{0:F0}", r.Select(i => i[1]).Average());
		}
	}
}

Measured memory_bytes: 6088
#include<stdio.h>

int main(void)

{

int a,b,c;

int count=0;

int i;

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

for(i=a;i<=b;i++)

{

if(c%i==0) count++;

}


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


return 0;

}

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

using namespace std;

typedef long long ll;

vector<vector<int>> ichigo;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	ichigo.resize(H);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '#')ichigo[i].push_back(j);
		}
	}

	int nothing = -1;
	int ans[300][300] = {};
	int cnt = 1;
	for (int i = 0; i < H; i++) {
		if (ichigo[i].size() == 0 && nothing == -1) {
			nothing = i;
		}
		else if(ichigo[i].size() != 0){
			int s;
			if (nothing == -1)s = i;
			else s = nothing;
			nothing = -1;
				if (ichigo[i].size() == 1) {
					for (int w = 0; w < W; w++) {
						for(int h = s; h <= i; h++)
						ans[h][w] = cnt;
					}
				}
				else {
					for (int w = 0; w <= ichigo[i][0]; w++)
						for (int h = s; h <= i; h++)
							ans[h][w] = cnt;
					int idx = 1;
					for (int w = ichigo[i][0] + 1; w < W; w++) {
						for (int h = s; h <= i; h++)
							ans[h][w] = cnt;
						if (idx < ichigo[i].size() && ichigo[i][idx] == w) {
							cnt++;
							idx++;
							for (int h = s; h <= i; h++)
								ans[h][w] = cnt;
						}
					}
				}
				cnt++;
			}
	}
	if (nothing != -1) {
		cnt -= ichigo[nothing - 1].size();
		int s = nothing;
		if (ichigo[nothing - 1].size() == 1) {
			for (int w = 0; w < W; w++) {
				for (int h = s; h < H; h++)
					ans[h][w] = cnt;
			}
		}
		else {
			for (int w = 0; w <= ichigo[nothing - 1][0]; w++)
				for (int h = s; h < H; h++)
					ans[h][w] = cnt;
			int idx = 1;
			for (int w = ichigo[nothing - 1][0] + 1; w < W; w++) {
				for (int h = s; h < H; h++)
					ans[h][w] = cnt;
				if (idx < ichigo[nothing - 1].size() && ichigo[nothing - 1][idx] == w) {
					cnt++;
					idx++;
					for (int h = s; h < H; h++)
						ans[h][w] = cnt;
				}
			}
		}
	}
	
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
LL A[100000],B[100000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

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

	LL ans = 0;
	for(int i=N-1; i>=0; i--){
		LL now = A[i] + ans;
		LL goal = ceil((double)now / B[i]) * B[i];
		ans += goal - now;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
use std::io::stdin;

fn main() {
    let mut k = String::new();
    stdin().read_line(&mut k).unwrap();
    let k: u32 = k.trim().parse().unwrap();

    let acl = String::from("ACL");   

    println!(
        "{}", 
        (0..k).collect::<Vec<u32>>().into_iter().map(|_ :u32| {
            acl.clone()
        }).collect::<Vec<String>>().join("")
    );
}


Measured memory_bytes: 2008
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int n,m;
std::cin >> n >> m;
int out = 0;
if(m >= 2 * n){
    out += n;
    m -= 2 * n;
    out += m/4;
} else {
    out += m/2;
}
std::cout << out << std::endl;
return 0;
}

Measured memory_bytes: 256