akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : aoj1188.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;


string s;

int solve(int l,int r){
	if(s[l] == '['){
		int i, cnt = 0; // 次に要素番号 l の後ろに'['があった場合 +1,']'があった場合 -1 とするcntである
		vector<int> each;
		while(l < r){
			for(i = l + 1;i < r && !(s[i] == ']' && cnt == 0);i++){ // そのcntが0でかつs[l]が']'(この選挙区の終端)であるときに終了
				if(s[i] == '['){
					cnt++;
				}else if(s[i] == ']'){
					cnt--;
				}
			}
			each.push_back(solve(l + 1,i));
			l = i + 1;
		}
		sort(each.begin(),each.end());
		int sum = 0;
		for(int i = 0;i < (each.size() + 1) / 2;i++){
			//cout << each[i] << " ";
			sum += each[i];
		}
		//cout << endl;
		//cout << sum << endl;
		return sum;
	}
	if(isdigit(s[l])){
		int d = 0;
		for(int i = l;i < r && isdigit(s[i]);i++){
			d = d * 10 + (s[i] -'0');
		}
		return (d + 1) / 2; // 過半数
	}
}

int main(void){
	int n;
	cin >> n;
	cin.get();
	for(int i = 0;i < n;i++){
		getline(cin,s);
		cout << solve(1,s.size() - 2) << endl;
	}
}

Measured memory_bytes: 1276
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    def printFrame(h: Int,w: Int): Unit = {
      if (w != 0 || h != 0) {
        val rectBase = "#" * w
        val hollow = rectBase.patch(1, "." * (w - 2), w - 2)

        println(rectBase)
        for (i <- 1 to h - 2) {
          println(hollow)
        }
        println(rectBase)
        println

        printFrame(sc.nextInt, sc.nextInt)

      }
    }

    printFrame(sc.nextInt, sc.nextInt)

  }
}

Measured memory_bytes: 45704
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/


int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    n %= 10;
    if(n == 3) cout << "bon" << endl;
    else if(n == 0 || n == 1 || n==6 || n==8) cout << "pon" << endl;
    else cout << "hon" << endl;
}



Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

/**
* Binary_Indexed_Tree(BIT)
* Fenwick Tree
* 0-indexed!!!
* O(log N)
*/
template<typename T = int>
class binary_indexed_tree {
private:
    int N;
    std::vector<T> bit;
public:
    binary_indexed_tree() {}
    binary_indexed_tree(int n) : N(n), bit(n, 0) {}
    // bit[point]にnum追加
    void add(int point, T val) {
        point++;

        for (int i = point; i - 1 < N; i += i & (-i)) {
            bit[i - 1] += val;
        }
    }
    // [0, point)
    T sum(int point) {
        T res = 0;
        for (int i = point; i > 0; i -= i & (-i)) {
            res += bit[i - 1];
        }

        return res;
    }
    // [left, right)
    T sum(int left, int right) {
        return this->sum(right) - this->sum(left);
    }
};

const int MAX = 2e3 + 10;
int N;
int L[MAX];

bool check(int a, int b, int c) {
    return a < b + c && b < c + a && c < a + b;
}

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> L[i];
    }

    LL ans = 0;
    sort(L, L + N);

    binary_indexed_tree<int> bit(MAX);
    REP(i, N) {
        REP(j, MAX) bit.add(j, bit.sum(j, j + 1));
        FOR(j, i + 1, N) {
            bit.add(L[j], 1);
        }
        FOR(j, i + 1, N) {
            bit.add(L[j], -1);
            const int left = abs(L[i] - L[j]) + 1;
            const int right = L[i] + L[j];
            ans += bit.sum(left, right);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>


string s;

void die(){
	cout<<"No";
	exit(0);
}

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	cin>>s;
	
	if (s.size()%2==1) die();
	for (int x=0;x<s.size();x++){
		if (x%2==1 && s[x]!='i') die();
		else if (x%2==0 && s[x]!='h') die();
	}
	
	cout<<"Yes";
}

Measured memory_bytes: 256
s = input()
t = input()
ANS = 0

for i in range(len(s) - len(t) + 1):
    ans = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            ans += 1
    ANS = max(ANS,ans)
print(len(t) - ANS)

Measured memory_bytes: 72944
N = int(input())

d = {"AC":0,"WA":0,"TLE":0,"RE":0}

for _ in range(N):
    d[input()] += 1

print("AC x",d["AC"])
print("WA x",d["WA"] )
print("TLE x",d["TLE"])
print("RE x",d["RE"])

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define pb push_back
#define pf push_front
#define PB pop_back
#define PF pop_first
#define mp make_pair
#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;

ll t, n, k;
ll a[N];

ll up(ll x, ll y) {
    return x % y == 0 ? x / y : x / y + 1;
}

ll binser(ll l, ll r) {
    ll ret, mid, temp;
    while(l <= r) {
        mid = (l + r) / 2, temp = 0;
        for(ll i = 1; i <= n; i++) {
            temp += up(a[i], mid) - 1;
        }
        if(temp <= k) {
            ret = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    return ret;
}

void solve() {
    cin >> n >> k;
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    cout << binser(1, a[n]) << "\n";
}

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

Measured memory_bytes: 5100
#include <stdio.h>
#include <stdlib.h>

#define N 2001

typedef struct vertex{
	short int next[N];
	short int length;
} vertex;

vertex field[N];


int count(int i,int k,int r);

int main(){
	int n,k;
	int i,j;
	int a,b;
	int r;
	scanf("%d %d",&n,&k);
	for(i = 0;i < n-1;i++){
		scanf("%d %d",&a,&b);
		field[a].next[field[a].length++] = b;
		field[b].next[field[b].length++] = a;
	}

	r = k / 2;
	b = 0;
	if(k%2){
		for(i = 1;i <= n;i++){
			for(j = 0;j < field[i].length;j++){
				a = count(i,field[i].next[j],r) + count(field[i].next[j],i,r);
				if(b < a){
					b = a;
				}
			}
		}
	}else{
		for(i = 1;i <= n;i++){
			a = count(i,0,r);
			if(b < a){
				b = a;
			}
		}		
	}

	printf("%d\n", n - b);
	return 0;
}
int count(int i,int pre,int r){
	int res = 1;
	int j;
	if(r == 0){
		return res;
	}
	for(j = 0;j < field[i].length;j++){
		if(field[i].next[j] == pre){
			continue;
		}
		res += count(field[i].next[j],i,r-1);
	}
	return res;
}


Measured memory_bytes: 8064
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    for(int i = 0;i < k;i++){
        if(a >= b){
            b *= 2;
        } else if (b >= c){
            c *= 2;
        }
    }

    if(a < b && b < c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>
#include <math.h>

#define gc() getchar_unlocked()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc();
	while (c >= '0');
	return n;
}

int x[102], y[102];

int main()
{
	int n, i, t, t2;
	int d, d1, d2;
	long long d3;
	
	n = in();
	for (i = 0; i < n; i++) x[i] = in();
	for (i = 0; i < n; i++) y[i] = in();
	d = 0, d1 = 0, d2 = 0, d3 = 0;
	for (i = 0; i < n; i++) {
		t = x[i] - y[i];
		if (t < 0) t = -t;
		if (t > d) d = t;
		d1 += t;
		t2 = t*t, d2 += t2;
		d3 += t2*t;
	}
	printf("%d\n", d1);
	printf("%.8lf\n", sqrt((double)d2));
	printf("%.8lf\n", pow((double)d3, 1.0/3));
	printf("%d\n", d);
	return 0;
}





Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 13) cout << B << endl;
    else if (A >= 6) cout << B / 2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let s: String = sc.read();
    let s: Vec<char> = s.chars().collect();
    let mut ans = '0';
    for c in b'a'..b'z'+1 {
        let c = c as char;
        if !s.contains(&c) {
            ans = c;
            break;
        }
    }
    match ans {
        '0' => println!("None"),
        _ => println!("{}", ans),
    }
}

Measured memory_bytes: 4352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, K, Q;
long long int ans;

string S;
int num[100000];
int box[100000];
int bag;
string be;
string af;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	cin >> S;
	for (int i = 0; i < N; i++) {
		if (S[i] == '(')num[i]++;
		else box[i]++;
	}
	if (S[0] == ')')bag = -1;
	else bag++;
	for (int i = 1; i < N; i++) {
		num[i] += num[i - 1];
		box[i] += box[i - 1];
		bag = min(bag, num[i] - box[i]);
	}
	bag = min(0, bag);
	
	for (int i = 0; i < -bag; i++) {
		be += '(';
	}
	for (int j = 0; j < num[N - 1]  -bag - box[N - 1]; j++) {
		af += ')';
	}
	cout << be << S << af << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

int main(void){
  int N;
  cin >> N;
  vector<int> h;
  vector<int> dp;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    h.push_back(tmp);
    dp.push_back(INF);
  }
  
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  
  for(int i=2;i<N;i++){
    dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
  }
  
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1276
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {
	int N, L;
	cin >> N >> L;
	int ans;
	ans = N * (N + 1) / 2+N*(L-1);
	if (L > 0) { ans = ans - L; }
	else if (L < 0 && L+N-1 < 0) { ans = ans - (L + N - 1); }


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


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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> sum1(N + 1, 0);
    vector<long long> sum2(N + 1, 0);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum1[i + 1] = sum1[i] + A[i];
        sum2[i + 1] = sum2[i] + A[i];
    }
    
    long long ans1 = 0;
    long long ch1 = 0;
    for(int i = 1; i <= N; i++){//偶数列を＋
        long long bf = ch1;
        sum1[i] += ch1;
        if(i % 2 == 0){
            if(0 < sum1[i])continue;
            else{
                ch1 += abs(1 - sum1[i]);
                sum1[i] = 1;
            }
        }else{
            if(sum1[i] < 0)continue;
            else{
                ch1 -= abs(-1 - sum1[i]);
                sum1[i] = -1;
            }
        }
        ans1 += abs(ch1 - bf);
    }
    
    long long ans2 = 0;
    long long ch2 = 0;
    for(int i = 1; i <= N; i++){//偶数列を-
        long long bf = ch2;
        sum2[i] += ch2;
        if(i % 2 == 1){
            if(0 < sum2[i])continue;
            else{
                ch2 += abs(1 - sum2[i]);
                sum2[i] = 1;
            }
        }else{
            if(sum2[i] < 0)continue;
            else{
                ch2 -= abs(-1 - sum2[i]);
                sum2[i] = -1;
            }
        }
        ans2 += abs(ch2 - bf);
    }
    
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int h,w;
    cin>>w>>h;
    int n;
    cin>>n;
    vector<int> a[w+1];
    rep(i,w+1)a[i].push_back(inf);
    rep(i,n){
        int x,y;
        cin>>x>>y;
        --x;--y;
        a[x].push_back(y);
    }
    a[w].push_back(0);
    rep(i,w+1)sort(a[i].begin(),a[i].end());
    int H =0 ;
    rep(i,w){
        if(H>=a[i+1][0]){
            cout<<i+1<<endl;
            return 0;
        }
        int z=*lower_bound(a[i+1].begin(),a[i+1].end(),H+1);
        if(z!=H+1)++H;
    }
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
	int n=0;
	string str="";
	set<string> s;
	int counter=0;
	cin>>n;
	for(int k=0;k<n;k++)
	{
		cin>>str;
		if(s.count(str)==0)
		{
			counter++;
		}
		s.insert(str);
	}
	printf("%d\n",counter);
	return 0;
}

Measured memory_bytes: 19352
#include<stdio.h>
#define MAX 101
int main(){
  int i,j,k,n,a,b,A[MAX],B[MAX][MAX];

  scanf("%d",&n);
  for(i=1; i<=n; i++)
    scanf("%d%d",&A[i-1],&A[i]);
 
  for(i=1; i<=n; i++)
    B[i][i] = 0;
 
  for(j=2; j<=n; j++){

    for(i=1; i<=n-j+1; i++){
      a = i + j -1;
      B[i][a] = 1000000;

      for(k=i; k<=a-1; k++){
	b = B[i][k] + B[k+1][a] + A[i-1]*A[k]*A[a];
	if(B[i][a] >= b)
	  B[i][a] = b;
      }
    }
  }
 
  printf("%d\n",B[1][n]);
   
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
    string s2;
    bool cnt = true;
    if(n == 1){cout << "No"; return 0;}
    if(n % 2 == 1){cout << "No" << endl; return 0;}
    
    rep(i, n/2){
        if(s[i] != s[i + n/2]){
            cnt = false;
        }
    }
    if(cnt){cout << "Yes" << endl;}
    else {cout << "No" << endl;}
    
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
  string S;
  cin >> S;
  int ans = 100000;
  for (int i = 0; i < S.length() - 2; i++)
  {
    int num = 0;
    num += (S[i] - '0') * 100;
    num += (S[i + 1] - '0') * 10;
    num += (S[i + 2] - '0');
    ans = min(ans, abs(num - 753));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import java.util.*;

class Main {

	static int n = 0;
	static int[] A = null;

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		n = stdIn.nextInt();

		A = new int[n];
		for (int i=0; i<n; i++) {
			A[i] = stdIn.nextInt();
		}

		int q = stdIn.nextInt();

		for (int i=0; i<q; i++) {
			if(solve(0,stdIn.nextInt()))
				System.out.println("yes");
			else
				System.out.println("no");
		}
 	}

 	static boolean solve(int i,int m){
 		if(i >= n)
 			return m==0;
 		if(solve(i+1,m))
 			return true;
 		if(solve(i+1,m-A[i]))
 			return true;
 		return false;
 	}
}

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

typedef struct {
	int row;
	int column;
}Matrix;

const int MaxN = 100;

int dp[MaxN + 1][MaxN + 1];

int calc(std::vector<Matrix>& m, int a, int b)
{
	int ans;

	if (b - a == 0) {
		return 0;
	}
	if (b - a == 1) {
		if (dp[a][b] != 0) {
			return dp[a][b];
		}
		else {
			ans = m[a - 1].row*m[b - 1].column*m[a - 1].column;
			dp[a][b] = ans;
			return ans;
		}
	}
	else {
		if (dp[a][b] != 0) {
			return dp[a][b];
		}

		ans = calc(m, a, a) + calc(m, a + 1, b) + m[a - 1].row*m[b - 1].column*m[a - 1].column;
		for (int i = 1; i < b - a; i++) {
			int temp;
			temp = calc(m, a, a + i) + calc(m, a + i + 1, b) + m[a - 1].row*m[b - 1].column*m[a + i - 1].column;
			if (temp < ans) {
				ans = temp;
			}
		}
		dp[a][b] = ans;
	}

	return ans;
}

int main()
{
	int n;
	Matrix temp;
	std::vector<Matrix> m;
	
	std::cin >> n;

	for (int i = 0; i < n; i++) {
		std::cin >> temp.row >> temp.column;
		m.push_back(temp);
	}

	std::cout << calc(m, 1, m.size()) << std::endl;

	return 0;
}

Measured memory_bytes: 3176
#include <cstdio>
long long O;
int N, M, f[100001], w[100001], s[100001][3], d[100001], e[100001];
int F(int x)
{
	if (f[x] == x)
		return x;
	F(f[x]);
	d[x] = (d[x] + d[f[x]]) % 3;
	return f[x] = f[f[x]];
}
void add(int u, int v)
{
	int fu = F(u), fv = F(v);
	if (fu == fv)
	{
		if (d[u] != (d[v] + 1) % 3)
			w[fu] = 1;
		e[fu]++;
	}
	else
	{
		f[fu] = fv;
		w[fv] |= w[fu];
		d[fu] = (4 + d[v] - d[u]) % 3;
		for (int i = 0; i < 3; i++)
			s[fv][(i + d[fu]) % 3] += s[fu][i];
		e[fv] += e[fu] + 1;
	}
}
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)
	{
		f[i] = i;
		s[i][0] = 1;
	}
	while (M--)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v);
	}
	for (int i = 1; i <= N; i++)
		if (F(i) == i)
		{
			if (w[i])
				O += (long long)(s[i][0] + s[i][1] + s[i][2]) * (s[i][0] + s[i][1] + s[i][2]);
			else if (s[i][0] && s[i][1] && s[i][2])
				O += (long long)s[i][0] * s[i][1] + (long long)s[i][1] * s[i][2] + (long long)s[i][2] * s[i][0];
			else
				O += e[i];
		}
	printf("%lld\n", O);
	return 0;
}


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


void solve(long long K, std::string S){
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;
using static Read;

class Program
{
    public static void Main()
    {
        var n = Int();
        WriteLine($"{n * (n + 1) / 2}");
    }
}

static class Read
{
    static Queue<string> queue = new Queue<string>();
    static void Enqueue()
    {
        ReadLine().Split(' ').ToList().ForEach(a => queue.Enqueue(a));
    }
    public static int Int()
    {
        if(queue.Count == 0)
            Enqueue();
        return int.Parse(queue.Dequeue());
    }
    public static long Long()
    {
        if(queue.Count == 0)
            Enqueue();
        return long.Parse(queue.Dequeue());
    }
    public static double Double()
    {
        if(queue.Count == 0)
            Enqueue();
        return double.Parse(queue.Dequeue());
    }
    public static string String()
    {
        if(queue.Count == 0)
            Enqueue();
        return queue.Dequeue();
    }
    public static int[] IntArray()
    {
        return ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static long[] LongArray()
    {
        return ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
    }
    public static double[] DoubleArray()
    {
        return ReadLine().Split(' ').Select(a => double.Parse(a)).ToArray();
    }
    public static string[] StringArray()
    {
        return ReadLine().Split(' ');
    }
}


Measured memory_bytes: 11348
class Node
  def initialize(val)
    @val = val
    @left = nil
    @right = nil
  end
  def insert(val)
    if val < @val
      if @left
        @left.insert(val)
      else
        @left = Node.new(val)
      end
    else
      if @right
        @right.insert(val)
      else
        @right = Node.new(val)
      end
    end
  end
  def print
    puts " #{inorder([]).join(" ")}"
    puts " #{preorder([]).join(" ")}"
  end
  def preorder(list)
    #root
    list << @val
    #left
    list = @left.preorder(list) if @left
    #right
    list = @right.preorder(list) if @right
    return list
  end
  def inorder(list)
    #left
    list = @left.inorder(list) if @left
    #root
    list << @val
    #right
    list = @right.inorder(list) if @right
    return list
  end
  def find(num)
    if @val == num then
      return "yes"
    elsif @val > num
      if @left
        return @left.find(num)
      else
        return "no"
      end
    else
      if @right
        return @right.find(num)
      else
        return "no"
      end
    end
  end
end

n = gets.to_i
tree = nil

n.times{
  command, num = gets.split
  case command;
  when "insert";
    if tree
      tree.insert(num.to_i)
    else
      tree = Node.new(num.to_i)
    end
  when "find";
    puts tree.find(num.to_i)
  when "print";
    tree.print
  end
}

Measured memory_bytes: 67040
#include<stdio.h> 
 #include<stdlib.h>
 #include<math.h>
  
 #define INF 1000000
  
 int matrixChainOrder(int *);
  
 int aaa,sum;
 int mainn[100][100],cap[100],p[101];
  
 int matrixChainOrder(int *p){
   int n,l,i,j,k,q;
  
   n = aaa;
   for(i = 1;i <= n;i++){
     mainn[i][i] = 0;
   }
   for(l = 2;l <= n;l++){
     for(i = 1;i <= n-l+1;i++){
       j = i + l - 1;
       mainn[i][j] = INF;
       for(k = i;k <= j-1;k++){
  
     q = mainn[i][k] + mainn[k+1][j] + (p[i-1] * p[k] * p[j]);
  
     mainn[i][j] = (int)fmin(mainn[i][j],q);
  
       }
     }
   }
  
  return mainn[1][n]; 
 }
 int main(){
   int i,j,n,re;
  
   scanf("%d",&n);
  
   aaa = n;
   
   for(i = 1;i <= n;i++){
     scanf("%d %d",&p[i-1],&p[i]);
   }
  
   re = matrixChainOrder(p);
  
   printf("%d\n",re);
  
   return 0;
 }
  
 

Measured memory_bytes: 640
// --------------------<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 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 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;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
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 main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c;
    cin >> a >> b >> c;
    if(c>=a && c<=b) cout << "Yes";
    else cout << "No";
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="RRR") cout<<3;
  else if(s=="RRS"||s=="SRR") cout<<2;
  else if(s=="SSS") cout<<0;
  else cout<<1;
  return 0;
}

Measured memory_bytes: 3576
<?php
define('MOD', pow(10, 9) + 7);
fscanf(STDIN, "%d", $N);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$x[0] = 3;
$ans = 1;
for ($i = 0; $i < $N; $i++) {
    if (!isset($x[$a[$i]]) || $x[$a[$i]] === 0) {
        $ans = 0;
        break;
    } else {
        $ans *= $x[$a[$i]];
        $x[$a[$i]]--;
        if (!isset($x[$a[$i] + 1])) {
            $x[$a[$i] + 1] = 1;
        } else {
            $x[$a[$i] + 1]++;
        }
    }
    $ans %= MOD;
}
printf("%d", $ans);

Measured memory_bytes: 18932
N=int(input())
Nlen=len(str(N))

if Nlen==1:
  print(N)
elif Nlen==2:
  print(9)
elif Nlen==3:
  print(9+(N-99))
elif Nlen==4:
  print(9+900)
elif Nlen == 5:
    print(9 + (999 - 99) + (N - 9999))
elif Nlen == 6:
    print(9 + (999 - 99) + (99999 - 9999))
  
  

Measured memory_bytes: 3060
#include<iostream>
#include<math.h> 
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<climits>
using namespace std;
typedef long long int lli;
lli mod=1000000007;
lli gcd(lli a, lli b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
lli prime(lli x) 
{ 
    lli res = 0; 
    if (x % 2 == 0) { 
        res++; 
        while (x % 2 == 0) 
            x = x / 2; 
    } 
    for (lli i = 3; i <= sqrt(x); i = i + 2) { 
        if (x % i == 0) {
            res++; 
            while (x % i == 0) 
                x = x / i; 
        } 
    } 
    if (x > 2) 
        res++; 
    return res; 
} 
lli common(lli a, lli b) 
{ 
    lli g = gcd(a, b); 
    return prime(g); 
} 
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    lli a,b;
    cin>>a>>b;
    lli ans=common(a,b);
    cout<<ans+1<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
template <class T>
void print(T x){cout << x << '\n';}



void solve(long long N, std::vector<std::vector<long long>> A){
  vector<vector<ll>> acc(2, vector<ll>(N+1));

  acc[0][0]=0;
  acc[1][0]=0;
  FOR(i,1,N+1){
    acc[0][i] = acc[0][i-1]+A[0][i-1];
    acc[1][i] = acc[1][i-1]+A[1][i-1];
  }

  // REP(i, N+1){
  //   cout << acc[0][i] << " ";
  // }
  // cout << "\n";
  // REP(i, N+1){
  //   cout << acc[1][i] << " ";
  // }
  // cout << "\n";


  ll m=0;
  FOR(i, 1, N+1){
    ll b = acc[0][i]+acc[1][N]-acc[1][i-1];
    if(b>m)m=b;
  }
  print(m);
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::vector<long long>> A(2, std::vector<long long>(N));
  for(int i = 0 ; i < 2 ; i++){
    for(int j = 0 ; j < N ; j++){
      scanf("%lld",&A[i][j]);
    }
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define O 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[O][O];
int color[O],d[O],f[O],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}
void dfs(){
  int u;

  for(u=0 ; u<n ; u++)
    {
      color[u] = WHITE;
    }
  tt=0;
  
  for( u=0 ; u<n ; u++)
    {
      if(color[u] == WHITE)dfs_visit(u);
    }
  
  for( u=0 ; u<n ; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}


int main()
{
  int u,v,k,i,j;

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

  for ( i=0 ; i<n ; i++)
    {
      scanf("%d %d",&u,&k);
      u--;
      for(j=0 ; j<k ; j++)
	{
	  scanf("%d",&v);
	  v--;
	  M[u][v] = 1;
	}
    }

  dfs();

  return 0;
}




Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for(int i = 0;i < N + 1;i++) {
		cin >> A.at(i);
	}
	vector<int> B(N);
	for(int i = 0;i < N;i++) {
		cin >> B.at(i);
	}
	int answer = 0;
	for(int i = 0;i < N;i++) {
		answer += min(A.at(i) + A.at(i + 1),B.at(i));
		int a = 0;
		B.at(i) = max(B.at(i) - A.at(i),a);
		A.at(i + 1) = max(A.at(i + 1) - B.at(i),a);
	}
	cout << answer << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
using namespace std;
int len, k;
char req[3] = {'0', '1'};
string word;
int main(){
	cin >> len >> k >> word;
	vector < int > thing;
	int s = 0, now = 1, ans = 0, r = 0, l = 0;
	for(int i = 0;i < len;++i){
		if(word[i] == req[now])++s;
		else{
			thing.push_back(s);
			s = 1;
			now ^= 1;
		}
	}
	thing.push_back(s);
	s = 0;
	while(r <= (k << 1) and r < thing.size()){
		s += thing[r++];
	}
// 	cout << r << '\n';
	ans = s;
	while(r < thing.size()){
		s = s - thing[l] - thing[l + 1] + thing[r] + (r + 1 < thing.size() ? thing[r + 1] : 0);
		r += 2;
		l += 2;
		ans = max(s, ans);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    int n; cin >> n;
    int ans = 0;
    for(int a = 1; a < n; a++) ans += (n - 1) / a;
    cout << ans << endl;
    return 0;    
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
long long n,m;
const long long mod = 1e9+7;
long long dp[310][310][310];
vector<pair<long long,long long> > vec[310];
bool check(long long i,long long j,long long k){
    long long pos = max(i,max(j,k));
    for (register int p = 0; p < vec[pos].size(); p++){
        long long l = vec[pos][p].first;
        long long num = vec[pos][p].second;
        long long cnt = 0;
        if (i>=l){
            cnt++;
        }
        if (j>=l){
            cnt++;
        }
        if (k>=l){
            cnt++;
        }
        if (cnt!=num){
            return false;
        }
    }
    return true;
}
int main () {
    scanf("%lld%lld",&n,&m);
    dp[0][0][0] = 1;
    for (register int i = 1; i <= m; i++){
        long long l,r,x;
        scanf("%lld%lld%lld",&l,&r,&x);
        vec[r].push_back(make_pair(l,x));
    }
    long long ans = 0;
    for (register int i = 0; i <= n; i++){
        for (register int j = 0; j <= n; j++){
            for (register int k = 0; k <= n; k++){
                if (dp[i][j][k]==0){
                    continue;
                }
                if (!check(i,j,k)){
                    dp[i][j][k] = 0;
                    continue;
                }
                long long l = max(i,max(j,k));
                if (l==n){
                    ans += dp[i][j][k];
                    ans %= mod;
                }
                dp[l+1][j][k] += dp[i][j][k];
                dp[l+1][j][k] %= mod;
                dp[i][l+1][k] += dp[i][j][k];
                dp[i][l+1][k] %= mod;
                dp[i][j][l+1] += dp[i][j][k];
                dp[i][j][l+1] %= mod;
            }
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 227584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 10010;
const ll INF = LLONG_MAX/3;
ll dp[N];

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

    vector<int> s(n),p(n);
    rep(i,n) scanf(" %d %d", &s[i], &p[i]);

    fill(dp,dp+N,-INF);
    dp[0] = 0;
    rep(i,n){
        for(int j=N-1; j>=0; --j){
            int nx = j+s[i];
            if(nx>=N) continue;
            dp[nx] = max(dp[nx], dp[j]+p[i]);
        }
    }

    for(int i=1; i<=m; ++i){
        int lim = c/i;
        ll ans = -INF;
        rep(j,lim+1) ans = max(ans, dp[j]);
        printf("%lld\n", ans*i);
    }

    return 0;
}



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

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

  int n, m;
  cin >> n >> m;
  vector<vector<P>> ken(100100);
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    ken[p].push_back(make_pair(i, y));
  }

  P answers[100100];
  for( auto &l : ken) {
    sort(l.begin(), l.end(), [](P a, P b){return a.second < b.second;});
  }

  rep(i, 100010) {
    int cnt = 1;
    for (auto a : ken[i]) {
      answers[a.first] = make_pair(i, cnt);
      cnt++;
    }
  }

  for(auto i : answers) {
    if (i.first == 0 && i.second == 0) continue;
    printf("%06d", i.first);
    printf("%06d\n", i.second);
  }
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;constexpr int32 INF=1<<30;constexpr ll INFLL=1LL<<62;
#define all(x) x.begin(),x.end()
#define LB(V,x) lower_bound(all(V),x)-V.begin()
#define uint uint32
inline int f(int x){
    return x%2==0 ? x/2 : x*3+1;
}
void Main(){
    int s;
    cin >> s;
    map<int, int> R;
    for(int n=1;n<=1000000;n++){
        if(R[s]!=0){
            cout << n;
            return;
        }
        R[s] = n;
        s = f(s);
    }
    
}
int main(){cin.tie(0);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string S; cin >> S;
    string res(S.size(), 'x');
    cout << res << "\n";
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())

def bisect(x,X):
  l=0
  r=10**18
  while r>l+1:
    n=(r+l)//2
    if n*x>=X:
      r=n
    else:
      l=n
  return r    

for _ in range(N-1):
  t,a=map(int,input().split())
  n=max(bisect(t,T),bisect(a,A))  
  T=n*t
  A=n*a
    
print(T+A)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin>>a>>b;
	int ans = 0;
	for(int i=0;i<a.size();++i)
		if(a[i]!=b[i])
			ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3800
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    print(N ** 3)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
#include <cstdio>
using namespace std;
int v[100005],f[100005];
int my_find(int x){
    if(f[x]==x)
        return x;
    else
        return my_find(f[x]);
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&v[i]);
    for(int i=1;i<=n;i++)
        f[i]=i;
    int x,y;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        x=my_find(x);
        y=my_find(y);
        f[y]=x;
    }
    for(int i=1;i<=n;i++)
        f[i]=my_find(i);
    int s=0;
    for(int i=1;i<=n;i++){
        if(v[i]==i)
            s++;
        else if(f[i]==f[v[i]])
            s++;
    }
    printf("%d\n",s);
    return 0;
}


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

int calcDistance(pair<int, int> a, pair<int, int> b){
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int main(){
    int N;
    cin >> N;
    vector< tuple<int, int, int> > travel; // t, x, y
    for(int i = 0; i < N; i++){
        int t, x, y;
        cin >> t >> x >> y;
        travel.push_back(make_tuple(t, x, y));
    }

    bool can_travel = true;
    pair<int, int> before_coord = make_pair(0, 0);
    int before_time = 0;
    for(auto t:travel){
        int current_time = get<0>(t);
        pair<int, int> current_coord = make_pair(get<1>(t), get<2>(t));
        int dist = calcDistance(current_coord, before_coord);
        int time = current_time - before_time;
        if(dist > time || dist % 2 != time % 2){
            can_travel = false;
            break;
        }
        before_time = get<0>(t);
        before_coord = make_pair(get<1>(t), get<2>(t));
    }

    if(can_travel) cout << "Yes" << endl;
    else           cout << "No"  << endl;
}

Measured memory_bytes: 1912
#include <iostream>
using namespace std;
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c){
    cout << "No" << endl;
  }else if (a != b && b != c && c != a){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 888
def gcd_on_blackboard(n, a)
  left_to_right = [a.first]
  right_to_left = [a.last]

  1.upto(n - 1) do |i|
    left_to_right << gcd(left_to_right.last, a[i])
    right_to_left.unshift gcd(right_to_left.first, a[n - 1 - i])
  end

  m = []
  n.times do |i|
    if i - 1 < 0
      m << right_to_left[i + 1]
    elsif i + 1 == n
      m << left_to_right[i - 1]
    else
      m << gcd(left_to_right[i - 1], right_to_left[i + 1])
    end
  end

  m.max
end

def gcd(a, b)
  a, b = b, a if a < b
  r = a % b
  until r.zero?
    a = b
    b = r
    r = a % b
  end
  b
end

n = gets.to_i
a = gets.split.map(&:to_i)
puts gcd_on_blackboard(n, a)

Measured memory_bytes: 11128
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    ll a,b,c;
    cin >> a>> b>> c;
    cout<< (floor(1.0*a*min(b-1,c)/b)) <<nl;
    
}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int n,a,c[110000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		c[a]++;
	}
	int ans=0;
	for(int i=1;i<100000;i++)ans=max(ans,c[i-1]+c[i]+c[i+1]);
	cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

struct Data{
	mint v=0,sz=0;
};

Data op(Data a,Data b){
	a.v += b.v;
	a.sz += b.sz;
	return a;
}
Data e(){
	return Data();
}

Data mapping(pair<mint,mint> a,Data b){
	b.v *= a.first;
	b.v += a.second * b.sz;
	return b;
}

pair<mint,mint> composition(pair<mint,mint> a,pair<mint,mint> b){
	return make_pair(a.first*b.first,a.first*b.second + a.second);
}

pair<mint,mint> id(){
	return make_pair(1,0);
}

int main(){
	
	int N,Q;
	cin>>N>>Q;
	vector<Data> A(N);
	rep(i,N){
		int a;
		cin>>a;
		A[i].v = a;
		A[i].sz = 1;
	}
	
	lazy_segtree<Data,op,e,pair<mint,mint>,mapping,composition,id> seg(A);
	
	rep(i,Q){
		int t;
		cin>>t;
		
		if(t==0){
			int l,r,b,c;
			cin>>l>>r>>b>>c;
			seg.apply(l,r,make_pair(b,c));
		}
		else{
			int l,r;
			cin>>l>>r;
			cout<<seg.prod(l,r).v.val()<<endl;
		}
	}
	
    return 0;
}

Measured memory_bytes: 19196
import scala.io.StdIn

object Main extends App {
  val Array(a, b) = StdIn.readLine().split(" ").map(_.toInt)

  def solve(a: Int, b: Int): Int = {
    List(a + a -1 , a  + b , b + b - 1).max
  }

  println(solve(a, b))
}
  



Measured memory_bytes: 27084
#include <stdio.h>
#include <math.h>

int main(void){

  int n, i, j, heiho, co = 0, sosu = 0, seisu[10000];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &seisu[i]);
    heiho = (int)sqrt(seisu[i]);
    co = 0;
    if(seisu[i] == 2) co = 0;
    else if(seisu[i]%2 == 0) co = 1;
    else {
      for(j = 3; j <= heiho; j += 2){
	if(seisu[i]%j == 0) co = 1;
      }
    }
    if(co == 0) sosu++;
  }

  printf("%d\n", sosu);
  return 0;
}

Measured memory_bytes: 628