akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	int N, Q;
	string S;

	cin >> N >> Q;
	cin >> S;

	vector<int> l = vector<int>(Q), r = vector<int>(Q);
	for (int i = 0; i < Q; ++i)
	{
		cin >> l[i] >> r[i];
	}

	vector<int> acPos;
	acPos.push_back(-1);
	for (int i = 0; i < N - 1; ++i)
	{
		if (S[i] == 'A' && S[i + 1] == 'C')
		{
			acPos.push_back(i);
			++i;
		}
	}
	acPos.push_back(N + 1);

	for (int i = 0; i < Q; ++i)
	{
		int f = 0, e = acPos.size() - 1;
		for (int j = 0; acPos[j] < l[i] - 1; ++j)++f;
		for (int j = acPos.size() - 1; acPos[j] > r[i] - 2; --j)--e;
		cout << e - f + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 2044
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if (r <= x&&x+r <= W&&r <= y&&y+r <= H)
    printf("Yes\n");
    else
    printf("No\n");

















    return 0;
}

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

int v[] = {6000, 4000, 3000, 2000};

int main() {
	for (int i = 0; i < 4; i++) {
		int t, n;
		cin >> t >> n;
		cout << n * v[t - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
string s;
int main()
{
	cin >> s;
	if (s[1] != 'R')
	{
		if (s[0] == 'R' || s[2] == 'R')cout << 1;
	}
	else if (s[0] == 'R' and s[2] != 'R')cout << 2;
	else if (s[2] == 'R' and s[0] != 'R')cout << 2;
	else if (s[0] == 'R')cout << 3;
	if(s[0]==s[1] and s[1]==s[2] and s[2]=='S')cout << 0;
  if (s == "SRS")cout << 1;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>

std::vector<long long> div(long long n) {
    std::vector<long long> ret(1, 1);
    for (long long i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) ret.push_back(i);
    }
    if (sqrt(n) == (long long)sqrt(n)) {
        for (long long i = ret.size() - 2; i >= 0; i--) {
            ret.push_back(n / ret[i]);
        }
    }
    else {
        for (long long i = ret.size() - 1; i >= 0; i--) {
            ret.push_back(n / ret[i]);
        }
    }
    return ret;
}

std::vector<long long> comdiv(long long a, long long b) {
    if (a > b) std::swap(a, b);
    std::vector<long long> v = div(a);
    std::vector<long long> ret(1, 1);
    for (long long i = 1; i < v.size(); i++) {
        if (b % v[i] == 0) ret.push_back(v[i]);
    }
    return ret;
}

bool is_prime(long long n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (long long i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    long long a, b;
    std::cin >> a >> b;
    std::vector<long long> v = comdiv(a, b);
    long long ans = 1;
    for (auto i : v) {
        if (is_prime(i)) ans++;
    }
    std::cout << ans << std::endl;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const long INF = 1e18;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int n;
long K;
vector <long> pos, neg;

bool Check(long x){
  long cnt = 0;
  auto F = [&](vector <long> &cur, long val){
    long res = 0;
    for (int i = 0; i < cur.size(); i++){
      long tmp = val / cur[i] + (val % cur[i] != 0);
      int k = lower_bound(all(cur), tmp) - cur.begin();
      k = max(k, i + 1); res += cur.size() - k;  
    }  
    return res;
  };
  if (x > 0){
    cnt += F(neg, x) + F(pos, x);
  }
  else {
    auto C2 = [&](long x){
      return x * (x - 1) / 2;
    };
    long z = n - pos.size() - neg.size();
    cnt += z * (z - 1) / 2; 
    cnt += z * (pos.size() + neg.size());
    cnt += C2(1ll * pos.size()) + C2(1ll * neg.size());
    x = -x;
    for (int i = 0; i < neg.size(); i++){
      long cur = x / neg[i];
      int k = upper_bound(all(pos), cur) - pos.begin();
      cnt += k;  
    }
  }
  return (cnt >= K);
}

int main()
{
  fastio;
  cin >> n >> K; K = 1ll * n * (n - 1) / 2 - K + 1;
  for (int i = 1; i <= n; i++){
    int x; cin >> x;
    if (x < 0) neg.push_back(-x);
    else if (x > 0) pos.push_back(x);
  }
  sort(all(neg)); sort(all(pos));
  long l = -INF; long r = INF; long res;
  while (l <= r){
    long m = (l + r) / 2;
    if (Check(m)){
      res = m;
      l = m + 1;
    }
    else r = m - 1;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 2420
fn main() {
    let mut sc = Scanner::new();
    let h = sc.usize_read();
    let w = sc.usize_read();
    let sh = sc.usize_read();
    let sw = sc.usize_read();

    if h % sh == 0 && w % sw == 0 {
        println!("No");
        return;
    }

    println!("Yes");
    if w % sw == 0 {
        let one = create_one(h, sh);
        for i in 0..h {
            for _ in 0..w {
                print!("{} ", one[i]);
            }
            println!();
        }
    } else {
        let one = create_one(w, sw);
        for _ in 0..h {
            for j in 0..w {
                print!("{} ", one[j]);
            }
            println!();
        }
    }
}

fn create_one(w: usize, sw: usize) -> Vec<i64> {
    let mut sum = vec![1e6 as i64; w + 1];
    sum[0] = 0;
    for i in 1..(w + 1) {
        if i >= sw {
            sum[i] = sum[i - sw] - 1;
        }
    }
    (0..w).map(|i| sum[i + 1] - sum[i]).collect()
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main() {
    int a, b;
    string s;
    cin >> a >> b >> s;
    if(s.size()!=a+b+1) {cout << "No" << endl; return 0;}
    if(s[a]!='-') {cout << "No" << endl; return 0;}
    rep(i,s.size()){
        if(i==a) continue;
        bool ok = false;
        if(s[i]>='0' && s[i]<='9') ok = true;
        if(!ok) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
A,B=map(str,input().split())
#print(A*B)
getcontext().prec=40
A=int(A)
#print(Decimal(A)*Decimal(B))

A=str(A)
A=list(map(int,A))
b=list(str(B))
B=[0]*3
#print(A,b)
N=len(A)                #Aの桁数
table=[[0 for _ in range(len(A)+1)] for _ in range(10)]
for i in range(1,10):
    career=0
    for j in range(N,0,-1):
        buf=A[j-1]*i+career
        career=buf//10
        table[i][j]=buf%10
    table[i][0]=career
#print(table)
A=list(A)
A.insert(0,0)
A.insert(len(A),0)
A.insert(len(A),0)

#print(A)
ans=[0]*(len(A))
B=[int(b[0]),int(b[2]),int(b[3])]
#print(B)
#print(ans)
for i in range(2,-1,-1):
    piv=B[i]
    buf=[]
    buf = table[piv]
    #print(buf)
    career=0
    for j in range(N,-1,-1):
        num=ans[j+i]+buf[j]+career
        career=num//10
        ans[j+i]=num%10
    #print(ans)
    #input()
ans=map(str,ans)
s="".join(ans)
print(int(s[:len(s)-2]))

Measured memory_bytes: 72616
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    string s,t; cin >> s >> t;
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));
    vector<vector<int>> match = dp;

    for (int i=1; i<=s.size(); i++){
        for (int j=1; j<=t.size(); j++){
            if (s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                match[i][j] = 1;
            }
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans;
    for (int i=s.size(), j=t.size(), cur=dp[i][j];cur;){
        int pos = -1;
        for (int k=i; k>0; k--){
            if (match[k][j] && dp[k][j] == cur){
                pos=k;
                break;
            }
        }
        if (pos != -1){
            j--; i=pos-1;
            ans += t[j];
            cur--;
            continue;
        }
        for (int k=j; k>0; k--){
            if (match[i][k] && dp[i][k] == cur){
                pos=k;
                break;
            }
        }
        if (pos != -1){
            i--; j=pos-1;
            ans += s[i];
            cur--;
        } else{
            i--; j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> a(100005,0);
int main() {
	int n,k;
	cin>>n;
	ll sum=0;
	for(int i=0;i<n;i++){
	    cin>>k;
	    a[k]++;
	    sum+=(ll)k;
	}
	int q;
	cin>>q;
	while(q--){
	    ll b,c;
	    cin>>b>>c;
	    sum-=(a[b]*b);
	    sum+=(a[b]*c);
	    a[c]+=a[b];
	    a[b]=0;
	    cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3856
#include<bits/stdc++.h>
#define taskname ""
#define int long long
using namespace std;

string s, t;
int ans, n, m;

int check(int v)
{
    int c = 0;
    for (int i = v - m + 1; i <= v; ++i)
        if (s[i] != t[i - (v - m + 1)]) ++c;
    return c;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> s >> t;
    n = s.size(), m = t.size();
    ans = n;
    for (int i = m - 1; i < n; ++i)
        ans = min(ans, check(i));
    cout << ans;
}


Measured memory_bytes: 3624
//
// AGC013A
//
//

#include <iostream>
#include <math.h>
#include<chrono>
#include <vector>
#include <cstring>   // memset
using namespace std;

int N;

void normal(){
	cin >> N;

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

	int ans = 1;				// 最低でも1回
	int len_count = 0;
	int dir = 0;

  string outs="";

	for(int i=0; i<N; i++) {

		if(len_count == 0) {        // 1文字目
			len_count++;
		} else if (dir ==0) {			// 2文字目
			if (A[i] - A[i-1] > 0) dir =  1;
			if (A[i] - A[i-1] < 0) dir = -1;
			len_count++;
		} else {
			int dir2 = A[i] - A[i-1];
			if((dir ==  1 && dir2 < 0) ||
         (dir == -1 && dir2 > 0))	{
				ans++;

				len_count = 1;						//1文字目に戻す
				dir = 0;
			} else  {
				len_count++;
			}
		}

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

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


Measured memory_bytes: 640
program main
Implicit None
	integer(8)::s
	
	read*,s
	if(s/100 > 12 .or. s < 100)then
		if(mod(s,100) > 12 .or. mod(s,100) == 0)then
			print"(a)","NA"
			else
			print"(a)","YYMM"
		endif
		else
		if(mod(s,100) > 12 .or. mod(s,100) == 0)then
			print"(a)","MMYY"
			else
			print"(a)","AMBIGUOUS"
		endif
	endif
end program main

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

using namespace std;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    if(a<=8 && b<=8)
    {
    	cout<<"Yay!"<<endl;
    }
    else
    	cout<<":("<<endl;
	return 0;

}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int N;
    while(1){
        cin >> N;
        if(!N) return 0;
        vector<char> c(N);
        vector<P> v;
        for (int i = 0; i < N; i++) {
            cin >> c[i];
            if(c[i]=='W'){
                LL x,y;cin >> x >> y;
                v.pb(mp(x,y));
            }
            else if(c[i]=='D'){
                LL x;cin >> x;
                v.pb(mp(x,-1));
            }
            else if(c[i]=='R'){
                LL x;cin >> x;
                x++;
                v.pb(mp(-1,-1));
                LL ans=-1,t=0;
                map<LL,LL> ma;
                for (int j = 0; j < i; j++) {
                    if(c[j]=='W'){
                        if(t+v[j].sc<=x){
                            t+=v[j].sc;
                            ma[v[j].fs]+=v[j].sc;
                        }
                        else{
                            ma[v[j].fs]+=x-t;
                            t=x;
                        }
                        if(ans==-1&&x==t){
                            ans=v[j].fs;
                        }
                    }
                    else if(c[j]=='D'){
                        t-=ma[v[j].fs];
                        ma[v[j].fs]=0;
                        if(ans==v[j].fs){
                            ans=-1;
                        }
                    }
                }
                cout << ans << endl;
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3272
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split().Select(int.Parse).ToArray();
            double cost = int.MaxValue;

            for (int i = -100; i <= 100; i++)
            {
                double tmpCost = 0;
                foreach (var item in As)
                {
                    tmpCost += Math.Pow((item - i), 2);
                }
                cost = Math.Min(cost, tmpCost);
            }

            Console.WriteLine(cost);
        }
    }
}

Measured memory_bytes: 11348
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {a: i32, b: i32};

    let c1 = a + b;
    let c2 = a - b;
    let c3 = a * b;

    let mut result = std::cmp::max(c1, c2);
    result = std::cmp::max(result, c3);

    println!("{}", result)
}


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

int main(){
  string S;
  cin >> S;
  vector<string> DAY={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  for(int i=0; i<DAY.size(); i++){
    if(S==DAY.at(i)){
      cout << 7-i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6]={0};
  for(int i=0; i<9; i++){
    if(i%2 == 0){
      for(int j=0,a; j<4; j++){
	scanf("%1d",&a);
	field[i/2][j+1]+=4*a;
	field[i/2+1][j+1]+=a;
      }
    }
    else{
      for(int j=0,a; j<5; j++){
	scanf("%1d",&a);
	field[i/2+1][j]+=2*a;
	field[i/2+1][j+1]+=8*a;
      }
    }
  }
  int x=0,y=1,d=2;
  for(;;){
    if(d == 1){
      if(!(field[x][y]&2)){d = 2;y++;}
      else if(field[x][y]&1){cout <<"U";d = 8;}
      else{cout <<"U";x--;}
    }
    else if(d == 2){
      if(!(field[x][y]&4)){d = 4;x++;}
      else if(field[x][y]&2){cout <<"R";d = 1;}
      else{cout <<"R";y++;}
    }
    else if(d == 4){
      if(!(field[x][y]&8)){d = 8;y--;}
      else if(field[x][y]&4){cout <<"D";d = 2;}
      else{cout <<"D";x++;}
    }
    else if(d == 8){
      if(!(field[x][y]&1)){d = 1;x--;}
      else if(field[x][y]&8){cout <<"L";d = 4;}
      else{cout <<"L";y--;}
    }
    if(x == 0 && y == 1 && d == 2) break;
  }
  cout <<endl;
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
    
typedef long long in;
typedef unsigned long long ull;
    
#define MOD 1000000007
#define mi 18446744073709551615

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long double a,b;
    cin>>a>>b;
    cout<<setprecision(100)<<(floor)(a*b);
    
    
    return 0;
}

Measured memory_bytes: 3828
import java.util.*;

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

		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		if (a * b % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
		
		scanner.close();
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void)
{
	int n,x,y;
	int o,p;
	int i, sum,sum_2;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d %d %d %d", &x, &y, &o, &p);
		
		if (o >= 5 && p >= 2){
			x = x/10*8;
			y = y/10*8;
			sum = o*x + p*y;
		}
		else if (o < 5 && p < 2){
			sum = o*x + p*y;
			
			p = 2;
			o = 5;
			sum_2 = o*x/10*8 + p*y/10*8;
			
			if (sum > sum_2) sum = sum_2;
		}
		
		else if (o < 5){
			sum = o*x + p*y;
			
			o = 5;
			sum_2 = o*x/10*8 + p*y/10*8;
			
			if (sum > sum_2) sum = sum_2;
		}
		
		else if (p < 2){
			sum = o*x + p*y;
			
			p = 2;
			sum_2 = o*x/10*8 + p*y/10*8;
			
			if (sum > sum_2) sum = sum_2;
		}
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC158
{
    /// <summary>
    /// StationandBus
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (s[0] == s[1] && s[0] == s[2])
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }

        #region Console
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 13140
#include <cmath>
#include <iostream>

using namespace std;

int main(){
  int A,B,C,X;
  int ans = 0;
  cin >> A >> B >> C >> X;
  for(int i = 0; i<=A;i++){
    for(int j = 0; j <= B ; j++){
      for(int p = 0; p <= C; p++){
        if(X - (500*i) - (100*j) - (50*p) == 0)ans+=1;
      }
    }
  }
  cout << ans << endl;
}


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

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

Measured memory_bytes: 4052
#include<stdio.h>
#define MAX 100

int main(){
  int G[MAX][MAX];
  int n,a,b,c,i,j; 

  scanf("%d", &n);

  for ( i = 0; i<n; i++ ){
    for ( j = 0; j <n; j++ ){
      G[i][j] = 0;
  }
  }
  
  for (i=0;i<n;i++ ){
    scanf("%d%d",&a,&b);
    a--;
    for (j=0;j<b;j++){
      scanf("%d",&c);
      c--;
      G[a][c] = 1;
    }
  }
  
  for (i=0;i<n;i++){
    for (j=0;j<n;j++){
      if(j){
	printf(" ");
      }
      printf("%d",G[i][j]);
    }
  
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2128
// No sorceries shall prevail. //           
import java.util.*;
import java.io.*;
public class Main {
	
	static long gcd(long a, long b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	static int gcd(int a, int b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	
	static long mod = 1000000007;
	public static void main(String args[]) {
		Scanner inp=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		
		String s=inp.next();
		StringBuilder sb=new StringBuilder(s);
		int n=inp.nextInt();
		boolean reversed=false;
		char prev[]=new char[n];
		char next[]=new char[n];
		int pr=0,ne=0;
		for(int i=0;i<n;i++) {
			int x=inp.nextInt();
			if(x==1) {
				reversed= !reversed;
			}
			else {
				x=inp.nextInt();
				char k=inp.next().charAt(0);
				if(x==2 && !reversed) {
					next[ne++]=k;
				}
				else if(x==1 && reversed) {
					next[ne++]=k;
				}
				else {
					prev[pr++]=k;
				}
			}
		}
		if(!reversed) {
			for(int i=pr-1;i>=0;i--) {
				out.print(prev[i]);
			}
			for(int i=0;i<s.length();i++) {
				out.print(s.charAt(i));
			}
			for(int i=0;i<ne;i++) {
				out.print(next[i]);
			}
		}
		else {
			for(int i=ne-1;i>=0;i--) {
				out.print(next[i]);
			}
			for(int i=s.length()-1;i>=0;i--) {
				out.print(s.charAt(i));
			}
			for(int i=0;i<pr;i++) {
				out.print(prev[i]);
			}
		}
		
		out.close();
		inp.close();
	}
}

Measured memory_bytes: 124208
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b, r = c + d;
  if(l > r) cout << "Left" << endl;
  if(l < r) cout << "Right" << endl;
  if(l == r) cout << "Balanced" << endl;
  return 0;
}
//templete by private_yusuke

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  int M = 1e9;
  int k, x;
  scanf("%d %d", &k, &x);
  int start = max(-M, x + 1 - k), end = min(M, x - 1 + k);
  FORE(i, start, end) {
    printf("%d ", i);
  }
  printf("\n");
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    input();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define pi acos(-1)
#define P pair<int,int>
#define fi first
#define se second
#define si signed
#define sc(x) scanf("%lld",&(x));
int n;
int A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
const double EPS =1e-7;
double sqr(int x)
{
    double l = 1, r = x;
    while(l+EPS<=r){
           // cout<<l<<' '<<r<<endl;
        double mid = (l+r)/2;
        if(mid*mid > x){
            r = mid;
        }else l = mid;
    }
    return l;

}
signed main()
{
   int a,b,c;
   sc(a)sc(b)sc(c)
   if(a+b>=c)cout<<"No";
   else {
    c-=(a+b);
    if(4*a*b>=c*c){
        cout<<"No";
    }else cout<<"Yes";
   }
    //cout<<A[n-1]<<'\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int limit = scan.nextInt();
			if(n == 0 && limit == 0){
				break;
			}
			int[] a = new int[n];
			for(int i = 0;i < n;i++){
				a[i] = scan.nextInt();
			}
			int min = 0;
			int b = 0;
			boolean sw = false;
			int t;
			for(int i = 0;i < n;i++){
				t = a[i] * (limit / a[i]);
				if(i == 0 || min > t){
					min = t;
					b = i;
					sw = false;
				}else if(min == t){
					if(a[b] > a[i]){
						b = i;
					}else if(a[b] == a[i]){
						sw = true;
					}
				}
			}
			System.out.println((sw)?n:b+1);
		}
	}
}

Measured memory_bytes: 27024
#include <iostream>
using namespace std;
int main(){
    int E,Y;
    cin>>E>>Y;
    if(E==0){
        if(Y<=1911)cout<<"M"<<Y-1867<<endl;
        else if(Y<=1925)cout<<"T"<<Y-1911<<endl;
        else if(Y<=1988)cout<<"S"<<Y-1925<<endl;
        else cout<<"H"<<Y-1988<<endl;
    }
    else if(E==1)cout<<Y+1867<<endl;
    else if(E==2)cout<<Y+1911<<endl;
    else if(E==3)cout<<Y+1925<<endl;
    else cout<<Y+1988<<endl;
    
    return 0;
}



Measured memory_bytes: 3136
N =int(input())
X = [int(i) for i in input().split()]
m = sum(X)//len(X)
mm = m+1

suma1 = 0
suma2 = 0
for i in X:
  suma1 += (i-m)**2
  suma2 += (i-mm)**2
print(min(suma1,suma2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<sstream>
#define ll long long int
#include <stdlib.h>
#include <vector>
#define pi acos(-1)
#define maxm 100005
#define pb push_back
#define MOD 1e9+7
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
///s1.substr(1,3);///STARTING FROM INDEX 1, 3 LNEGTH SUBSTRING.
///s1.find("adn")///RETURNS STARTING INDEX OF THE SUBSTRING
///"adn" IF IT EXISTS IN THE STRING S1.///
///s1.find("adn",int pos);///RETURNS STARTING INDEX OF THE
///SUBSTRING "adn" SEARCHING FROM INDEX POS OF STRING s1.///
///string::npos returns a garbage value if not found...
///reverse(s1.begin(),s1.end())-> to reverse a string.
///next_permutation(f,f+n)->f array er next permutation return korbe..
///str.erase(1,2)->deletes 2 char from index 1..
///for(auto i:p2)->i=p2.begin() theke p2.end() er ag porjonto..
///max_element(v,v+4);->return a pointer to the max element
///in a array/vector.. v from 1st element to 4th element.
///same for min_element(v,v+4);
///__builtin_popcount(a);->counts how many number of one's
/// in a in binary representation.
///accumulate(l1+1,l1+10+1,0LL)=>it perform the sum from l1[1] to
///l1[10] and 0 is the initial sum.
///cout<<fixed<<setprecision(12)<<x14<<endl;//=>x14 er
///doshomik er por 12 ta 0 thakbe.
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gcd(a,b) __gcd(a,b)
using namespace std;


int main()
{
    //IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,i,j,k,x,y,q=-1,n,c,m,z,z2,l,r,cases=0,d,p,nl,np,a,e=1,b,x2=-1,x1=1000000005,x3=0,x4=0,x5=0,x6=0,x7=0,x8=0;
    

    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0)x3+=0;
        else x3+=i;
    }
    cout<<x3<<endl;

    return 0;
}


Measured memory_bytes: 3636
/*
*@Author  Chand Vachhani
*/

#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define vi          vector<int>
#define vii         vector<vector<int>>
#define pii         pair<int,int>
#define mii         map<int,int>
#define pb          push_back
#define pf          push_front
#define mp(a,b)          make_pair((a),(b))
#define vpii        vector<pair<int,int>>
#define fo(i,l,n)   for(int i{l}; i<n; i++)
#define rf(s)       for(auto &c : s)
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define PI          3.141592653589
#define sz(x)       (int)x.size()
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007  

using namespace std;

signed main(){
    tezz
   
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    vector<bool> dp(k+1,false); // Here dp[i] is true if first player win 
                                // Basicly this solution is doing that for every calue of k 
                                // it calculate is=f first player wins or not
    for(int stone=0; stone<=k; stone++){
        for(auto x : a){
            if(stone>=x && !dp[stone-x])dp[stone]=true;
        }
        // for(auto it: dp)cout << it << " ";
        // cout << endl;
    }
    if(dp[k])cout << "First";
    else cout << "Second";
   
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split(" "))

status = []
for i in range(H):
    status.append([i for i in input()])

for i in range(H):
    for j in range(W):
        if status[i][j] == "#":
            flag = 0
            if i - 1 >= 0:
                if status[i - 1][j] == "#":
                    flag = 1
                    continue
            if i + 1 <= H -1:
                if status[i + 1][j] == "#":
                    flag = 1
                    continue
            if j - 1 >= 0:
                if status[i][j - 1] == "#":
                    flag = 1
                    continue
            if j + 1 <= W -1:
                if status[i][j + 1] == "#":
                    flag = 1
                    continue
            if flag == 0:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
H, W = gets.split.map(&:to_i)
S = H.times.map{gets.chomp}

visited = Array.new(H){Array.new(W)}
ans = 0
H.times do |i|
    W.times do |j|
        next if visited[i][j]
        visited[i][j] = true
        num = [0, 0]
        que = [[i, j]]
        while que.size > 0
            x, y = que.shift
            num[S[x][y] == '#' ? 1 : 0] += 1

            [[-1, 0], [1, 0], [0, -1], [0, 1]].each do |a, b|
                x2 = x+a
                y2 = y+b
                if x2.between?(0, H-1) && y2.between?(0, W-1) && !visited[x2][y2] && S[x][y] != S[x2][y2]
                    que.push([x2, y2])
                    visited[x2][y2] = true
                end
            end
        end
        ans += num[0] * num[1]
    end
end
puts ans

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
絶対値最小を選ぶ
*/

ll n,l,ans;

void init(){
	cin>>n>>l;
	ans=l*n+n*(n-1)/2;
}

int main(void){
	init();
	if(l+n-1<=0){
		ans-=l+n-1;
	}else if(l>=0){
		ans-=l;
	}else{
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N, *AB = map(int, open(0).read().split())
B = AB[1::2]

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])


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

int main() {
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> A(N);
    for (int i = 0; i < N; i++) {
        int K; cin >> K;
        for (int j = 0; j < K; j++) {
            int x, y; cin >> x >> y; x--;
            A[i].emplace_back(x, y);
        }
    }
    
    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        int res = 0;
        vector<bool> say(N, false);
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) { say[i] = true; res++; }
        }
        
        bool ok = true;
        for (int i = 0; i < N; i++) {
            if (say[i] == false) continue;
            for (int j = 0; j < A[i].size(); j++) {
                int x, y; tie(x, y) = A[i][j];
                if (say[x] != y) ok = false;
            }
        }
        
        if (ok == true) ans = max(ans, res);
    }
    
    cout << ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;
 
typedef long long int ll;

const ll INF=(ll)1e18;

int d[51][51];
int a[51], b[51];
int N, M;

bool dfs(){
    bool visited[N+1];
    REP(i,N+1)visited[i] = false;

    stack<int> st;
    st.push(1);

    while(st.size() > 0){
        int v = st.top();
        st.pop();

        visited[v] = true;
        REP(i,N+1){
            if(d[v][i] == 1 && visited[i] == false){
                st.push(i);
            }
        }
    }

    FOR(i,1,N+1){
        if(visited[i] == false){
            return false;
        }
    }
    return true;
}

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

    REP(i,N+1)REP(j,N+1)d[i][j] = 0;

    REP(i,M){
        cin >> a[i] >> b[i];
        d[a[i]][b[i]] = 1;
        d[b[i]][a[i]] = 1;
    }

    int ans = 0;
    REP(i,M){
        d[a[i]][b[i]] = 0;
        d[b[i]][a[i]] = 0;
        if(dfs()){
        }else{
            ans++;
        }
        d[a[i]][b[i]] = 1;
        d[b[i]][a[i]] = 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
s = input()
ans = 10 ** 10
for i in range(26):
    c = chr(ord("a") + i)
    s_c = list(s)
    cnt = 0
    while len(set(s_c)) != 1:
        t = ""
        for i in range(len(s_c) - 1):
            if s_c[i] == c or s_c[i + 1] == c:
                t += c
            else:
                t += s_c[i]
        cnt += 1
        s_c = t
    ans = min(ans, cnt)

print(ans)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int Root(int x);
bool Unite(int x, int y);

vector<int> tree[SIZE];
int root[SIZE], sz[SIZE];

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

    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 1; i <= n; ++i) {
        root[i] = i;
        sz[i] = 1;

    }

    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        tree[a].pb(b);
        tree[b].pb(a);
        Unite(a, b);

    }

    for(int i = 0; i < k; ++i) {
        int c, d;
        cin >> c >> d;
        if(Root(c) != Root(d)) continue;
        tree[c].pb(d);
        tree[d].pb(c);

    }

    for(int i = 1; i <= n; ++i) {
        Root(i);
        int t = sz[i] - int(tree[i].size()) - 1;
        cout << t << " ";

    }
    cout << endl;
    return 0;
}

int Root(int x) {
    if(x == root[x]) return x;
    int rt = Root(root[x]);
    sz[x] = sz[rt];
    return rt;

}

bool Unite(int x, int y) {
    int rx, ry;
    rx = Root(x);
    ry = Root(y);
    if(rx == ry) return false;
    sz[rx] += sz[ry];
    sz[ry] = sz[rx];

    if(rx < ry) {
        root[ry] = rx;

    } else {
        root[rx] = ry;

    }

    return true;
}



Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin >> n >> k;
  vl q;
  rep(i,n){
    ll a;
    cin >> a;
    q.push_back(a);
  }
  ll ans = 0;
  rep(l,n+1){
    rep(r,n+1){
      if(l+r > n) continue;
      int d = k-l-r;
      if(d < 0)continue;
      vl v;
      rep(i,l)v.push_back(q[i]);
      rep(i,r)v.push_back(q[n-1-i]);
      sort(rng(v));
      rep(i,min(d,sz(v)))if(v[i] < 0)v[i] = 0;
      ll sum = 0;
      rep(i,sz(v))sum+=v[i];
      maxs(ans,sum);
      //cout<<l<<" "<<r<<" "<<d<<" "<<sum<<endl;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
n = input()

for i in range(2 ** 3):
    ops = ["+"] * 3
    for j in range(3):
        if i >> j & 1:
            ops[j] = "-"

    f = ""
    for pn, po in zip(n, ops + [""]):
        f += (pn + po)
    if eval(f) == 7:
        print(f + "=7")
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second
#define INF (1LL<<61)

using namespace std;

int n, m;
vi adj[500010];
int vis[500010];
int dp[500010];

void dfs(int sv) {

	vis[sv] = 1;
	for (auto ch : adj[sv]) {
		if (!vis[ch])
			dfs(ch);

		dp[sv] = max(dp[sv] , 1 + dp[ch]);

	}

}



int32_t main() {

	fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w", stdout);
// #endif

	cin >> n >> m;
	for (int i = 1 ; i <= m ; i++) {
		int x , y;
		cin >> x >> y;
		adj[x].pb(y);
	}

	for (int i = 1 ; i <= n ; i++)if (!vis[i])dfs(i);

	int ans = 0;
	for (int i = 1 ; i <= n ; i++)ans = max(ans , dp[i]);
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 22748
//কী পেয়েছো তুমি, কী চেয়েছিলে তুমি.? হিসেবটা তোমার বড়ই গড়মিল...!!//
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
string ch="abcdefghijklmnopqrstuvwxyz";
typedef long long ll;
int main()
{
    int a,b;
	string u,s,t;
	cin>>s>>t>>a>>b>>u;
	if(u==s)a--;
	else if(u==t) b--;
	cout<<a<<' '<<b<<'\n';
 
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
//char buf[1<<24],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
typedef int DATA1;
typedef int DATA2;
inline void sc (DATA1 &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
inline void print (DATA2 x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
inline void pr (DATA2 x) { print(x),putchar('\n'); }
char change (char c)
{
	if (c=='b') return 'd';
	if (c=='d') return 'b';
	if (c=='p') return 'q';
	return 'p';
}
char s[N];
int main()
{
	//freopen (".in","r",stdin);
	//freopen (".out","w",stdout);
	scanf ("%s",s+1);
	int n=strlen (s+1);
	if (n&1) { puts("No"); return 0; }
	for (int i=1; i<=n>>1; i++)
		if (s[i]!=change (s[n-i+1])) { puts("No"); return 0; }
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
string s;
int main(){
	cin>>n>>s;
	int ans=0; 
	for(int i=0;i<n-2;i++){
		string t=s.substr(i,3);
		if(t=="ABC")
		ans++;
	}
	cout<<ans;
	re 0;
}


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

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n;
    cin >> n;

    vector<string> v(n + 1);

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;

        sort(all(s));

        v[i] = s;
    }

    v[n] = "{";

    ll ans = 0, cnt = 1;

    sort(all(v));

    for(int i = 1; i < n + 1; i++){
        if(v[i].compare(v[i - 1]) == 0) cnt++;
        else{
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }

    cout << ans;
}


Measured memory_bytes: 6372