akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, M;
	static int[][] g;
	static int ans;
	static int[] min = new int[20];

	public static void main(String[] arg) {
		N = sc.nextInt();
		M = sc.nextInt();
		g = new int[N][N];
		for (int i = 0; i < M; ++i) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			int f = sc.nextInt();
			g[u][v] = g[v][u] = f;
		}
		int[] r = new int[20];
		dfs(0, r, 0);
		System.out.println(ans);
	}

	static void dfs(int c, int[] r, int d) {
		if (d >= 2) {
			for (int i = 0; i < d; ++i) {
				min[i] = 1 << 30;
			}
			for (int i = 0; i < d; ++i) {
				for (int j = 0; j < i; ++j) {
					min[i] = Math.min(min[i], g[r[i]][r[j]]);
					min[j] = Math.min(min[j], g[r[i]][r[j]]);
				}
			}
			int sum = 0;
			for (int i = 0; i < d; ++i) {
				sum += min[i];
			}
			ans = Math.max(ans, sum);
		}
		for (int i = c; i < N; ++i) {
			boolean ok = true;
			for (int j = 0; j < d; ++j) {
				if (g[i][r[j]] == 0) {
					ok = false;
					break;
				}
			}
			if (!ok) continue;
			r[d] = i;
			dfs(i + 1, r, d + 1);
		}
	}
}

Measured memory_bytes: 23716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;

struct Guy{
	int sc;
	int L;
	bool ok;
};

typedef long long ll;
int n;
Guy guys[101];

ll dp[2][1<<17];

ll dfs(int pos,int s){
	if(pos==n)return 0;
	if(dp[pos][s]!=-1)return dp[pos][s];
	ll res=0;
	// ツ債。ツ嘉アツ偲ヲツづゥツつゥツ氾崢つゥ
	// no get
	res=max(res,dfs(pos+1,s));
	// get
	if(guys[pos].ok){
		bool ok=true;
		for(int i=0;i<17;i++){
			if(((s>>i)&1)&&((guys[pos].sc>>i)&1)){
				ok=false;
				break;
			}
		}
		if(ok){
			res=max(res,dfs(pos+1,s|guys[pos].sc)+guys[pos].L);
		}
	}
	return dp[pos][s]=res;
}

int main(){
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			int m;
			cin>>m>>guys[i].L;
			guys[i].sc=0;
			guys[i].ok=true;
			for(int j=0;j<m;j++){
				int s,e;
				cin>>s>>e;
				s-=6;
				e-=6;
				for(int k=s;k<e;k++){
					if(!((guys[i].sc>>k)&1)){
						guys[i].sc|=(1<<k);
					}
					else{
						guys[i].ok=false;
					}
				}
			}
		}
		for(int i=0;i<2;i++)for(int j=0;j<(1<<17);j++)dp[i][j]=0;
		for(int i=n-1;i>=0;i--){
			int cur=(i+1)%2;
			int nxt=(i)%2;
			for(int j=0;j<(1<<17);j++)dp[nxt][j]=0;
			for(int j=0;j<(1<<17);j++){
				dp[nxt][j]=dp[cur][j];
				if(guys[i].ok){
					bool ok=(j&guys[i].sc)?0:1;
//					for(int k=0;k<17;k++){
//						if(((j>>k)&1)&&((guys[i].sc>>k)&1)){
//							ok=false;
//							break;
//						}
//					}
					if(ok){
						dp[nxt][j]=max(dp[nxt][j],dp[cur][j|guys[i].sc]+guys[i].L);
					}
				}
			}
		}
		ll res=dp[0][0];
		//ll res=dfs(0,0);
		cout<<res<<endl;
	}

	return 0;
}

Measured memory_bytes: 2916
#include<bits/stdc++.h>
using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  list<int> l;
  for(int i=0;i<n;i++){
    string s;
    int x;
    cin>>s;
    if(s=="insert"||s=="delete") cin>>x;
    if(s=="deleteFirst"){
      l.pop_front();
      continue;
    }
    if(s=="deleteLast"){
      l.pop_back();
      continue;
    }
    if(s=="insert"){
      l.push_front(x);
      continue;
    }
    if(s=="delete"){
      auto it=find(l.begin(),l.end(),x);
      if(it==l.end()) continue;
      l.erase(it);
      continue;
    }
  }
  bool f=0;
  for(auto it=l.begin();it!=l.end();++it){
    if(f) cout<<" ";
    cout<<*it;
    f=1;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 34408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll a[100005], sum[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	map<ll, int> mp;
	FOR(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	
	sort(a, a+n);
	a[n] = -1;
	ll last = 0;
	FOR(i, n) {
		sum[i] = a[i] + last;
		last = sum[i];
	}
	int cnt = 0;
	for (int i = n-1; i >= 0; i--) {
		if (2*sum[i] < a[i+1]) break;
		else if (mp.count(a[i])){
			cnt += mp[a[i]];
			mp.erase(a[i]);
		}
	}
	
	cout << cnt << endl;

	return 0;
}

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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N;

  cin>>N;

  int Q;

  string S;
  
  cin>>Q>>S;

  long long sum[100001];

  sum[0]=0;

  int l[100001],r[100001];
  
  for(int i=0;i<N-1;i++){
    if(S[i]=='A'&&S[i+1]=='C'){
      sum[i+1]=sum[i]+1;
    }else{
      sum[i+1]=sum[i];
    }
  }
  
  for(int i=0;i<Q;i++){
    cin>>l[i]>>r[i];

    cout<<sum[r[i]-1]-sum[l[i]-1]<<endl;
  }

  
  return 0;

}


Measured memory_bytes: 2640
#include <iostream>

#define int long long

int gcd(int a, int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
}

signed main() {
  int x;
  std::cin >> x;
  
  int y = gcd(x, 360);
  std::cout << 360/y << std::endl;
  
  return 0;
}


Measured memory_bytes: 3616
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */

#include <stdio.h>

int main() {

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

	if (a < b && b < c) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define N 3005

ll n;
double p[N],dp[N][N],ans;

int main() {
	// freopen("input.txt", "r", stdin); 
	// freopen("output.txt", "w", stdout);
	fast_io;	 
	accuracy;
	cout << setprecision(precision);
	cin >> n;
	fr(i,1,n) cin >> p[i];
	dp[0][0] = 1;
	fr(i,1,n) {
		fr(j,0,i-1) {
			dp[i][j + 1] += p[i] * dp[i-1][j];
			dp[i][j] += (1 - p[i]) * dp[i-1][j];
		}
	}
	fr(j,0,n) {
		ll t = n-j;
		if(j > t) ans += dp[n][j];
	}
	cout << ans << endl;
}

Measured memory_bytes: 139392
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        n : u32,
        a : u32,
        b : u32,
    );

    let n : u32 = n;
    let a : u32 = a;
    let b : u32 = b;

    let ans = (1..n+1)
        .filter(|x| {
            let sum = x.to_string()
                .chars()
                .map(|c| (c as u8 - b'0')as u32)
                .sum::<u32>();
            a <= sum && sum <= b
        })
        .sum::<u32>();
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    int ans=INF;
    if(x/d>k){
        chmin(ans,x-d*k);
    }
    else{
        k-=x/d;
        x=x%d;
        if(k%2==1)x-=d;
        chmin(ans,abs(x));
    }
    cout<<ans<<endl;
    return 0;
}

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

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

using P = std::pair<int, int>;

int main() {
  int n, k;
  std::cin >> n >> k;

  int mx = (n - 1) * (n - 2) / 2;
  if (k > mx) {
    std::cout << -1 << '\n';
    return 0;
  }

  std::vector<P> ans;
  rep(i, n - 1) { ans.push_back(P(i + 1, n)); }

  int add = mx - k;
  std::vector<P> edge;
  rep(i, n - 1) rep(j, i) edge.push_back(P(i + 1, j + 1));
  rep(i, add) ans.push_back(edge[i]);
  
  std::cout << ans.size() << '\n';
  rep(i, ans.size()) {
    std::cout << ans[i].first << " " << ans[i].second << '\n';
  }

  return 0;
}


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

getString = BS.unpack <$> BS.getLine

main = do
  s <- getString
  let ss = ["Sunny", "Cloudy", "Rainy"]
  let index = fromJust (findIndex (== s) ss)
  putStrLn $ ss !! ((index + 1) `mod` 3)


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

using namespace std;

using seika = string;
template <class kizuna>
using akari = vector<kizuna>;

template <class T>
vector<pair<T, int>> RunLengthEncoding(vector<T> v)
{
    vector<pair<T, int>> res;
    int len = 0, n = v.size();
    T cur = v.front();
    for (int i = 0; i < n; i++)
    {
        if (cur == v[i])
        {
            len++;
        }
        else
        {
            res.push_back(make_pair(cur, len));
            cur = v[i];
            len = 1;
        }
    }
    res.push_back(make_pair(cur, len));
    return res;
}

int main(void)
{
    int n;
    cin >> n;
    akari<char> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    auto v = RunLengthEncoding(s);
    // for (auto &p : v)
    // {
    //     cout << p.first << ' ' << p.second << endl;
    // }
    cout << v.size() << endl;
}

Measured memory_bytes: 1528
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

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

        List<String> blueList = new ArrayList<>();
        for (int i = 0; i < blue; i++) {
            blueList.add(sc.next());
        }

        int red = sc.nextInt();
        List<String> redList = new ArrayList<>();
        for (int i = 0; i < red; i++) {
            redList.add(sc.next());
        }

        Set<String> set = new HashSet<>(blueList);

        int maxPoint = 0;
        for (String str :set){
            int point = 0;

            for (int i = 0; i < blue; i++) {
                if(Objects.equals(str, (blueList.get(i)))){
                    point++;
                }
            }

            for (int i = 0; i < red; i++) {
                if(Objects.equals(str, (redList.get(i)))){
                    point--;
                }
            }

            if(maxPoint < point){
                maxPoint = point;
            }
        }

        System.out.println(maxPoint);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e12;
using Graph = vector<vector<int>>;

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

signed main(){
  int H, W;
  cin >> H >> W;
  int SH, SW, GH, GW;
  cin >> SH >> SW >> GH >> GW;
  SH--; SW--; GH--; GW--;

  vector<string> S(H);
  for( int i = 0; i < H; i++ ) cin >> S[i];

  vector<vector<int>> dist(H, vector<int>(W, INF));
  dist[SH][SW] = 0;
  deque<pair<int, pair<int, int>>> que;
  que.push_front(make_pair(0, make_pair(SH, SW)));

  while( !que.empty() ){
    int x = que.front().second.first;
    int y = que.front().second.second;
    que.pop_front();

    //移動Aで行けるところ
    for (int direction = 0; direction < 4; ++direction) {
      int next_x = x + dx[direction];
      int next_y = y + dy[direction];
      if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
      if (S[next_x][next_y] == '#') continue;
      if( dist[next_x][next_y] <= dist[x][y] ) continue;
      dist[next_x][next_y] = dist[x][y];
      que.push_front(make_pair(0, make_pair(next_x, next_y)));
    }

    //移動Bで行けるところ
    for( int i = -2; i <= 2; i++ ){
      for( int j = -2; j <= 2; j++ ){
        int next_x = x + i;
        int next_y = y + j;
        if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
        if (S[next_x][next_y] == '#') continue;
        if( dist[next_x][next_y] < dist[x][y]+1 ) continue;
        dist[next_x][next_y] = dist[x][y]+1;
        que.push_back(make_pair(1, make_pair(next_x, next_y)));
      }
    }
  }

  if( dist[GH][GW] == INF ) cout << -1 << endl;
  else cout << dist[GH][GW] << endl;

}




Measured memory_bytes: 15220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	int M1,D1,M2,D2; cin >> M1 >> D1 >> M2 >> D2;
	cout << (M1!=M2) << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var S = ReadLine();

        var c = new char[S.Length];
        var a = 0;
        for (int i = 0; i < S.Length; i++)
        {
            if (i + 1 < S.Length && S[i] == 'B' && S[i + 1] == 'C')
            {
                c[a] = 'X';
                i++;
            }
            else
            {
                c[a] = S[i];
            }
            a++;
        }
        S = new string(c);
        var ans = 0L;
        foreach (var s in S.Split(new char[] { 'B','C'}))
        {
            var sum = 0L;
            var w = new int[s.Length];
            var aa = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A')
                {
                    aa++;
                 
                }
                w[i] = aa;
            }
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'X') sum += w[i];
            }
            ans += sum;
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 23516
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<deque>

using namespace std;

int main()
{
	int n;
	cin >> n;
	deque<int> b;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		if(i%2==n%2)b.push_back(a);
		else b.push_front(a);
	}


	for(int i=0;i<n;i++)
		cout << b[i] << " ";
	cout << endl;

	
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
using namespace std;
 
int main(){
    FIN;
    //freopen("../input.txt", "r", stdin);

    int T;cin>>T;
    int mod = T%10;
    if(mod == 2 || mod == 4 || mod == 5 || mod == 7 || mod == 9){
        cout<<"hon";
    }else if(mod == 0 || mod == 1 || mod == 6 || mod == 8){
        cout<<"pon";
    }else{
        cout<<"bon";
    }
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    map<ll, ll> mp;
    rep(i,n+1) mp[sum[i]]++;
    ll ans = 0;
    for(auto m: mp){
        ans += (m.second * (m.second-1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18720
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}


const double pi = 3.141592653;
int main(int argc, char const *argv[]) {
    // code
   	int n;
   	scanf("%d", &n);
   	vector<int> a(n+1), cnt(n+1, 0);
   	for (int i=2; i<=n; ++i) {
   		scanf("%d", &a[i]);
   		++cnt[a[i]];
   	}

   	for (int i=1; i<=n; ++i)
   		printf("%d\n", cnt[i]);
    return 0;
}

Measured memory_bytes: 4844
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm> 
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
  
    cout << max(max(A + B, A - B),A*B) << endl;
}


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

int main(){
    vector<char> cc;
    string s;
    cin >> s;
    int sl=s.size();
    for(int i=0;i<sl;i++){
        if(s[i]=='0'){
            cc.push_back('0');
        }else if(s[i]=='1'){
            cc.push_back('1');
        }else{
            if(cc.size()!=0)cc.pop_back();
        }
    }
    sl=cc.size();
    for(int i=0;i<sl;i++)cout << cc[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    while(true){
        int w, h;
        cin >> w >> h;

        if(w == 0 && h == 0){
            break;
        }

        vector<vector<bool>> area(h, vector<bool>(w, false));
        rep(i, h){
            rep(j, w){
                int x;
                cin >> x;
                if(x == 1){
                    area[i][j] = true;
                }
            }
        }

        vector<vector<int>> mark(h, vector<int>(w, 0));
        int c = 1;

        vector<int> dx = {1, 0, -1, 0, 1, 1, -1, -1};
        vector<int> dy = {0, 1, 0, -1, 1, -1, 1, -1};

        rep(i, h){
            rep(j, w){
                if(mark[i][j] != 0 || not area[i][j]){
                    continue;
                }

                stack<P> st;
                st.emplace(i, j);

                while(not st.empty()){
                    P p = st.top();
                    st.pop();

                    int x = p.first;
                    int y = p.second;

                    if(mark[x][y] != 0 || not area[i][j]){
                        continue;
                    }

                    mark[x][y] = c;

                    rep(k, 8){
                        int nx = x + dx[k];
                        int ny = y + dy[k];
                        if(0 <= nx && nx < h && 0 <= ny && ny < w && area[nx][ny]){
                            st.emplace(nx, ny);
                        }
                    }
                }
                c++;
            }
        }
        cout << c - 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3280
import collections
import heapq

s = raw_input()
h = {'R': lambda x:x-1, 'L': lambda x:x+1}
q = collections.deque([])
for i in range(len(s)-1):
	if s[i:i+2] == 'RL':
		q.append((i,i,i+1,i,'R'))
		q.append((i+1,i,i+1,i+1,'L'))
res = [0] * len(s)

while(q):
	u, a,b,w,d = q.popleft()
	res[w] += 1
	v = h[d](u)
	if 0 <= v  < len(s) and s[v] == d:
		nw = {a:b,b:a}[w] #if w == b else a
		q.append((v, a,b,nw,d))
print ' '.join(map(str,res))

Measured memory_bytes: 48412
def checkInput(inputList):
    a = 0
    b = 0
    c = 0
    d = 0
    for num in inputList:
        if(num == 1):
            a = 1
        elif(num == 9):
            b = 1
        elif(num == 7):
            c = 1
        elif(num == 4):
            d = 1
    if(a == 1 and b == 1 and c == 1 and d == 1):
        return True
    else:
        return False

if __name__ == '__main__':
    inp = list(map(int,input().split()))
    if(checkInput(inp)):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
const int MAX = 510000;
const int MOD = 1000000007;

vector<ll> divisor(ll n)
{
	vector<ll> value;
	for( ll i=1; i*i<=n;i++)
	{
		
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		
	}
	return value;
}
ll n;
int cnt;

void solve()
{
	
	cin>>n;
	cnt=0;
	vector<ll>div=divisor(n-1);
	vector<ll>div2=divisor(n);
	rep(i,div.size()){
		if(div[i]!=1)cnt++;
	}
	FOR(i,0,div2.size()){
		ll k=n;
		while(k>=div2[i]&&div2[i]!=1){
			if(k%div2[i]==0){
				k/=div2[i];
			}else{
				k%=div2[i];
			}
		}
		if(k==1)cnt++;
	}
	
	cout<<cnt<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;
#define MAX_N (105)
int n;

int pre[MAX_N];
int in[MAX_N];
int pos;
int printed;

void dfs(int l, int r) {
    if ( r - l <= 0 ) return;
    int num = pre[pos++];
    int pos_in;
    // linear search.
    for ( int i = l; i < r; i++ ) {
	if ( in[i] == num ) {
	    pos_in = i;
	    break;
	}
    }

    dfs( l, pos_in );
    dfs( pos_in + 1, r );
    printf("%d%c", num, ((printed == n - 1) ? '\n' : ' '));
    printed++;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) scanf("%d", &pre[i]);
    for ( int i = 0; i < n; i++ ) scanf("%d", &in[i]);

    dfs(0, n);

    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()  
#define sz(x) int(x.size()) 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=2e5+5;
bool DEBUG=0;
string s;
int n;
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> s;
    int cnt = 0;
    for(int i=0; i<n; i++){
		cnt+=s[i]=='R';
	}
	int ans = 0;
	for(int i=0; i<cnt; i++){
		ans+=s[i]=='W';
	}
	cout<<ans<<'\n';
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(i >= K) {
            if(T[i-K] == T[i]) {
                T[i] = 'z';
                continue;
            }
        }
        if(T[i] == 'r') ans+=P;
        if(T[i] == 's') ans+=R;
        if(T[i] == 'p') ans+=S;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)
//using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1 ,rr =1;
    for(ll i=0;i<k;++i) {
      r*=(n-i);
      rr*=(i+1);
      //r %= 1000000007;
      //rr %= 1000000007;
    }
    r/=rr;
    //r %= 1000000007;
    return r;
}
ll kyori(vector<ll>& y,vector<ll>& z,ll D){
  ll a=0;
  FORi(D){
    a+=pow((long long)(y[i]-z[i]),2);
  }
  ll b =  ((ll)pow((ll)sqrt(a),2)==a);
  if(b) return 1;
  return 0;
}
int main() {
  ll L,R;
  cin>>L>>R;
  ll l,r;
  l=L%2019;
  r=R%2019;
  //l<r (L-R)<2019 L->Rまでの範囲
  //r<l (L-R)<2019 0->r l->2018
  ll min = LLONG_MAX;
  if(R-L<2019){
    if(l<r){
      for(ll i=l;i<=r;++i){
  	    for(ll j=i+1;j<=r;++j){
          ll m = (i*j)%2019;
          if(m<min)min=m;
  	    }
      }
    }else{
      for(ll i=0;i<=r;++i){
  	    for(ll j=i+1;j<=r;++j){
          ll m = (i*j)%2019;
          if(m<min)min=m;
  	    }
      }
      for(ll i=r;i<2019;++i){
  	    for(ll j=i+1;j<2019;++j){
          ll m = (i*j)%2019;
          if(m<min)min=m;
  	    }
      }
    }
  }else{
    for(ll i=0;i<2019;++i){
  	  for(ll j=i+1;j<2019;++j){
        ll m = (i*j)%2019;
        if(m<min)min=m;
      }
    }
  }
  cout<<min<<endl;
  //l<r  >2019 0->2018の範囲
  //r<l  >2019 0->2018の範囲
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<b;i++)
	{
		if(a*i%b==c)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
vector<int> G[100010];
vector<int> d1,d2;

void dfs(int s,int par,int l,vector<int> &d){
    d[s]=l;
    for(int t:G[s]){
        if(t==par) continue;
        dfs(t,s,d[s]+1,d);
    }
}

void solve(){
    cin >> n;
    rep(i,n-1){
        int a,b;cin >> a >> b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    d1.resize(n);
    d2.resize(n);
    dfs(0,-1,0,d1);
    dfs(n-1,-1,0,d2);
    int s1=0,s2=0;
    rep(i,n){
        if(d1[i]<=d2[i]) s1+=1;
        else s2+=1;
    }
    if(s1>s2) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

const int MAX = 100000;

int main(){
  ios::sync_with_stdio(false);
	cin.tie(NULL);
  int N;
  cin >> N;
  int ans=1;
  int A[N+2];
  int t;
  int f=0;
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  for(int i=N;i>1;i--){
    A[i]=A[i]-A[i-1];
  }
  for(int i=2;i<=N;i++){
    if(A[i]==0) continue;
    if(f==0) {
      f=A[i];
      continue;
    }
    if(A[i]>0 && f<0){
      f=0;
      ans++;
    }else if(A[i]<0 && f>0){
      f=0;
      ans++;
    }
  }

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

Measured memory_bytes: 640
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    a = [0]+list(mi())
    b = [0]*(N+1)
    for i in range(N, 0, -1):
        if i > N//2:
            b[i] = a[i]
        else:
            b[i] = (a[i]+sum(b[i*2::i]))%2
    print(sum(b))
    print(' '.join([str(i) for i in range(N+1) if b[i]]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 98252
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {
  ll n,k;
  cin>>n>>k;
  ll cnt=0;
  if(k==0){
    cout<<n*n;
    return 0;
  }
  for(int i=k+1;i<=n;i++){
    cnt+=(n/i)*(i-k);
    if(n%i>=k){
      cnt+=n%i-k+1;
    }
  }
  cout<<cnt;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static final String SEVEN = "7";
	public static void main(final String[] args) {

		Scanner scan = new Scanner(System.in);
		int inputN = scan.nextInt();
		scan.close();
		String numN = String.valueOf(inputN);
		String charN = null;
		for (int i=0; i < numN.length(); i++) {
			if (i != (numN.length() - 1)) {
				charN = numN.substring(i, i+1);
			} else {
				charN = numN.substring(i);
			}
			if (SEVEN.equals(charN)) {
				System.out.println("Yes");
				return;
			}
		} 
		System.out.println("No");
	}
}

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

bool isPalindrome(string S){
  bool state = true;
  int size = S.size();
  for(int i=0;i<size;i++){
    if(S.at(i) != S.at(size-1-i)){
      state = false;
    }
  }
  return state;
}

int main(){
  string S;
  cin >> S;
  int N = S.size();
  string S1 = S.substr(0, (N-1)/2);
  string S2 = S.substr((N+1)/2, (N-1)/2);
/*
  cout << S1 << endl;
  cout << S << endl;
  cout << S2 << endl;
*/  
  if(isPalindrome(S1)&&isPalindrome(S)&&isPalindrome(S2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Float_Text_IO;
use Ada.Text_IO;
use Ada.Integer_Text_IO;
use Ada.Float_Text_IO;

procedure hoge is
 a: integer;
 b: integer;
 c: integer;
begin
 get(a);
 get(b);
 get(c);
 if a=b then
  if a/=c then
   put_line("Yes");
  else
   put_line("No");
  end if;
 elsif a=c then
  put_line("Yes");
 elsif b=c then
  put_line("Yes");
 else
  put_line("No");
 end if;
end hoge;

Measured memory_bytes: 3664
#include <vector>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> adj[n];
    while (m--) {
        int s, t; cin >> s >> t;
        adj[s-1].push_back(t-1);
    }
    double dp1[n];
    dp1[n-1] = 0;
    for (int k = n-2; k >= 0; k--) {
        double tmp = 0;
        for (int x : adj[k]) tmp += dp1[x];
        tmp /= adj[k].size();
        dp1[k] = tmp + 1;
    }
    double ans = dp1[0];
    for (int i = 0; i < n; i++) {
        if (adj[i].size() <= 1) continue;
        int j = adj[i][0];
        for (int k : adj[i]) if (dp1[k] > dp1[j]) j = k;
        double dp[n];
        dp[n-1] = 0;
        for (int k = n-2; k >= 0; k--) {
            double tmp = 0;
            for (int x : adj[k])
                if (k != i || x != j) tmp += dp[x];
            tmp /= adj[k].size() - (k == i);
            dp[k] = tmp + 1;
        }
        ans = min(dp[0], ans);
    }
    cout << setprecision(16) << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define int long long


string solve() {
	string a, b;
	cin >> a >> b;
	int n = a.size();
	int m = b.size();
	int dp[n + 1][m + 1];
	int i, j;
	for (i = 0; i <= n; i++)dp[i][0] = 0;
	for (j = 0; j <= m; j++)dp[0][j] = 0;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (a[i - 1] == b[j - 1])dp[i][j] = 1 + dp[i - 1][j - 1];
			else dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
		}
	}
	int len = dp[n][m];
	deque<char> dq;
	i = n - 1; j = m - 1;
	while (i >= 0 && j >= 0) {
		if (a[i] == b[j]) {
			dq.push_front(a[i]);
			i--; j--;
		}
		else {
			if (dp[i + 1][j] > dp[i][j + 1])j--;
			else i--;
		}
	}
	string str = "";
	while (!dq.empty()) {
		str += dq.front();
		dq.pop_front();
	}
	return str;
}




int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cout << solve();
	return 0;
}

Measured memory_bytes: 73940
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
  	int N; 
	string A, B, C;
	cin >> N >> A >> B >> C; 
	int ans = 0; 
	for(int i = 0; i < N; i++){
		if(A.at(i) != B.at(i) && B.at(i) != C.at(i) && C.at(i) != A.at(i)) ans += 2; 
		else if(A.at(i) == B.at(i) && B.at(i) == C.at(i)) ans += 0; 
		else ans += 1; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 100C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(2200000).
*>
WORKING-STORAGE SECTION.
01 N          PIC  9(06) COMP.
01 I          PIC  9(06) COMP.
01 W          PIC S9(10) COMP.
01 S          PIC  9(10) COMP.
01 AMR        PIC  9(01) COMP. 
01 P1         PIC  9(7) COMP.
01 P2         PIC  9(7) COMP.
01 TBL1.
   03 A       PIC  9(10) OCCURS 200000 DEPENDING ON N.
01 TBL-SA.
   03 SA      PIC S9(10) OCCURS 200000 DEPENDING ON N.
01 CNT        PIC 9(15) COMP.
01 OUT        PIC Z(14)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I)
    COMPUTE SA(I) = A(I) - I
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  SORT SA ASCENDING KEY SA.
  DIVIDE N BY 2 GIVING S REMAINDER AMR.
  IF (AMR = 1)
    MOVE SA(S + 1) TO W
  ELSE
    COMPUTE W ROUNDED = (SA(S) + SA(S + 1)) / 2
  END-IF  
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    COMPUTE S = A(I) - (W + I)
    COMPUTE CNT = CNT + S  
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


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

using namespace std;

int f(vector<int> v, vector<int> c) {
    int result = 0;
    for (int i = 0; i < v.size(); i++) {
        if (v[i] > c[i]) {
            result += v[i] - c[i];
        }
    }
    return result;
}

int main() {

    int n;
    cin >> n;

    vector<int> v;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    vector<int> c;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        c.push_back(tmp);
    }

    int result = f(v, c);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

int t[N * 4];

void build(int v, int l, int r) {
  if (l + 1 == r) {
    t[v] = r;
  } else {
    int mid = (l + r) / 2;
    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);
    t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
  }
}

void update(int v, int l, int r, int pos, int val) {
  if (l + 1 == r) {
    t[v] = val;
  } else {
    int mid = (l + r) / 2;
    if (pos < mid) {
      update(v * 2 + 1, l, mid, pos, val);
    } else {
      update(v * 2 + 2, mid, r, pos, val);
    }
    t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
  }
}

int get(int v, int l, int r, int ql, int qr) {
  if (l == ql && r == qr) {
    return t[v];
  }
  int mid = (l + r) / 2;
  if (qr <= mid) {
    return get(v * 2 + 1, l, mid, ql, qr);
  }
  if (ql >= mid) {
    return get(v * 2 + 2, mid, r, ql, qr);
  }
  return max(get(v * 2 + 1, l, mid, ql, mid), get(v * 2 + 2, mid, r, mid, qr));
}

void solve(int) {
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<int> x;
  for (auto& pr : a) {
    cin >> pr.first >> pr.second;
    x.push_back(pr.first);
  }
  sort(begin(a), end(a));
  sort(begin(x), end(x));
  vector<int64> on(n + 1, 0);
  vector<int64> off(n + 1, 0);
  on[n] = 1;
  off[n] = 0;
  build(0, 0, n);
  for (int i = n - 1; i >= 0; --i) {
    int pos = lower_bound(begin(x), end(x), a[i].first + a[i].second) - begin(x);
    if (pos != n) {
      pos = get(0, 0, n, i, pos);
    }
    update(0, 0, n, i, pos);
    on[i] = on[pos] + off[pos];
    off[i] = on[i + 1] + off[i + 1];
    on[i] %= mod;
    off[i] %= mod;
  }
  cout << (on[0] + off[0]) % mod << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 7924
n=int(input())

def digit(n,m):
    a=n
    _list = []
    while True:
        _list.append(a%m)
        a=a//m
        if a==0:
            break
    return sum(_list)

ans=10**10
for i in range(n+1):
    ans=min(ans,digit(i,6)+digit(n-i,9))
print(ans)


Measured memory_bytes: 42332
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int x,y;
	while(cin >> x >> y){
		if(!(x|y)) break;
		vector<string> f(x);
		int table[x][y];
		int tmpi=0;
		int ret=0;
		for(int i=0;i<x;i++) cin >> f[i];
		
		for(int i=0;i<x;i++){
			tmpi = 0;
			for(int j=y-1;j>=0;j--){
				if(f[i][j] == '.'){
					tmpi++;
				}else{
					tmpi = 0;
				}
				table[i][j] = tmpi;
			}
		}
		
		for(int i=0;i<x;i++){
			for(int j=0;j<y;j++){
				if(f[i][j] == '.'){
					int maxiwidth = 1 << 28;
					for(int k=0;k+i<x;k++){
						maxiwidth = min(maxiwidth, table[i+k][j]);
						ret = max(ret, maxiwidth * (k + 1));
					}
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  int n,cnt=0;
  cin>>n;

   int arr[n];
   for(int i=0;i<n;i++)cin>>arr[i];

    sort(arr,arr+n,greater<int>());

    int counts = 0;

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

            for (int k = j + 1; k < n; k++)


            if(arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i]){
                if (
                    arr[i] + arr[j] > arr[k]
                    && arr[i] + arr[k] > arr[j]
                    && arr[k] + arr[j] > arr[i])
                    counts++;
        }        }
    }

    cout<<counts<<endl;

  return 0;
 }
  

Measured memory_bytes: 3600