akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 62;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll r,c,k;
vector<vector<ll> > v;
ll dp[3100][3100][5];

int main() {
    cin >> r >> c >> k;
    v.assign(r+1,vector<ll>(c+1,-1));
    for (ll i=0;i<k;i++){
        ll R,C,V;
        cin >> R >> C >> V;
        v[R][C]=V;
    }
    memset(dp,0,sizeof(dp));
    for (ll i=0;i<=r;i++){
        for (ll j=0;j<=c;j++){
            for (ll k=0;k<=3;k++){
                if (i<r){
                    chmax(dp[i+1][j][0],dp[i][j][k]);
                    if (v[i+1][j]!=-1){
                        chmax(dp[i+1][j][1],dp[i][j][k]+v[i+1][j]);
                    }
                }
                if (j<c){
                    chmax(dp[i][j+1][k],dp[i][j][k]);
                    if (v[i][j+1]!=-1 and k<3){
                        chmax(dp[i][j+1][k+1],dp[i][j][k]+v[i][j+1]);
                    }
                }
            }
        }
        
    }
    ll ans=0;
    for (ll i=0;i<=3;i++){
        chmax(ans,dp[r][c][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 448964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> maze(h+2,vector<char>(w+2,'#'));
  rep1(i,h) rep1(j,w) cin >> maze[i][j];
  rep(i,h+2){
    rep(j,w+2) cout << maze[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

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

       if (n==1) printf("%d\n",A==B);
      else printf("%lld\n",1ll*(A<=B)*(n-2)*(B-A)+(A<=B));
}

Measured memory_bytes: 128
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int n;
    while(cin>>n){
        int ma=-1,mi=INF;
        if(n==0)break;
        rep(i,n){
            int sum=0;
            rep(j,5){
                int a;
                cin>>a;
                sum+=a;
            }
            ma=max(ma,sum);
            mi=min(mi,sum);
        }
        cout<<ma<<" "<<mi<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 1160
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll mod1=1e9+7;
const ll mod2=998244353;
const int INF=0x3f3f3f3f;
int n,q;
ll a[100005],x,y,ans,f[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans+=a[i];
		f[a[i]]++;
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>x>>y;
		f[y]+=f[x];
		ans+=f[x]*(y-x);
		f[x]=0;
		printf("%lld\n",ans);
		
		
	}



	return 0;
}


Measured memory_bytes: 4700
#include <iostream>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int temp = a + b;
    for (int i = 0; i < (int)s.length(); i++){

        if (s[i] == 'a' && temp > 0) {
            cout << "Yes" << endl;
            temp--;
        }
        else if (s[i] == 'b' && temp > 0 && b > 0) {
            cout << "Yes" << endl;
            temp--;
            b--;
        }
        else cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int num = 0;
  vector<int> editer(s.length(),-1);
  for(int i = 0; i < s.length(); i++){
    switch (s.at(i)){
      case '0':
        editer.at(num) = 0;
        num++;
        break;
      case '1':
        editer.at(num) = 1;
        num++;
        break;
      case 'B':
        if(num > 0)num--;
        editer.at(num) = -1;
    }
  }
  for(int i:editer){
    if(i != -1){
      cout << i;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i] -= (i + 1);
  }
  sort(all(A));
  int b = A[(N + 1) / 2 - 1];

  ll ans = 0;
  rep(i, N) { ans += abs(A[i] - b); }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		String s = sc.next();
		int R = 0;
		for (int i = 0; i < N; i++) {
			if (s.charAt(i)=='R')
				R++;
		}
		int ans = 0;
		for (int i = 0; i < R; i++) {
			if (s.charAt(i)=='W')
				ans++;
		}
		pw.println(ans);
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 36236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;


int keta(int n) {
  int cnt = 0;
  while(n > 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  int i = 0;
  while (pow(2,i) <= n) {
    i++;
  }
  i--;
  cout << pow(2,i) << endl;
}


Measured memory_bytes: 4240
import numpy as np
import statistics as stats

n=int(input())
x=list(map(int,input().split()))
x1=list(range(1,n+1))
x2=list(map(lambda a,b: a-b, x,x1))
b=round(stats.median(x2))
x3=[b]*n
x4=list(map(lambda a,b: a-b, x2,x3))
x5=np.abs(x4)
res=sum(x5)
print(res)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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


const ll MRINF = 5000000000000000;
int main() {


    int N, K;
    cin >> N >> K;

    if(N%K==0)cout << 0;
    else cout << 1;



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    n <- readLn
    xss <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
    forM_ xss $ \xs ->
        let [a,b,c] = sort xs
        in putStrLn $ if c^2 == a^2 + b^2 then "YES" else "NO"

Measured memory_bytes: 4608
S = input()
s = len(S)
L = []
temp = 0
for i in range(s):
    if S[i]=='A' or S[i]=='T' or S[i]=='G' or S[i]=='C':
        if temp ==0:
            temp=1
            L.append(temp)
        else:
            temp*=10
            L.append(temp)
    else:
        temp = 0
L.append(-1)        
if len(L)==2 and L[0]==0:
    P=0
elif len(L)==1:
    P=0
else:
    P = len(str(max(L)))
print(P)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a;
	cin>>a;
	cout<<pow(a,2)<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int d[100010];
vector<int> tp,v[100010];
int n,m;
bool visit[100010];
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (visit[xi]) continue;
		dfs(xi);
	} 
	tp.push_back(x);
} 
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(y);
	}
	for (int i=0;i<n;i++) if (!visit[i]) dfs(i);
	reverse(tp.begin(),tp.end());
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=0;j<v[x].size();j++)
			d[v[x][j]]=max(d[v[x][j]],d[x]+1);
	}
	cout <<*max_element(d,d+n);
	return 0;
} 

Measured memory_bytes: 8056
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

void solve(){
	int n; cin>>n;
	VI A,B;
	rep(i,n){
		int a; cin>>a;
		A.PB(a); B.PB(a);
	}
	sort(RALL(B));
	int ans=B[0];
	int ans2=B[1];
	rep(i,n){
		if(A[i]!=ans) cout<<ans<<endl;
		else cout<<ans2<<endl;
	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3436
use std::cmp::max;
use std::cmp::min;
use std::fmt;
use std::io::stdin;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Read;

#[derive(Debug)]
struct Jewel {
    v: u32,
    c: u32,
}

struct Input {
    n: u32,
    j: Vec<Jewel>,
}

impl fmt::Display for Input {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let j = self.j[0..(self.n as usize)]
            .iter()
            .map(|j| format!("{:?}", j))
            .collect::<Vec<String>>()
            .join(", ");
        write!(f, "{{ n: {}, j: [{}] }}", self.n, j)
    }
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let mut v_vec = Vec::new();
    let mut c_vec = Vec::new();
    for _ in 0..n {
        let v: u32 = iter.next().unwrap().parse().unwrap();
        v_vec.push(v);
    }
    for _ in 0..n {
        let c: u32 = iter.next().unwrap().parse().unwrap();
        c_vec.push(c);
    }
    let j = v_vec
        .iter()
        .zip(c_vec.iter())
        .map(|(v, c)| Jewel { v: *v, c: *c })
        .collect::<Vec<Jewel>>();
    let input = Input { n: n, j: j };
    Ok(input)
}

fn handle_output(input: Input) -> Result<String, Error> {
    let valued_sum: u32 = input
        .j
        .iter()
        .filter(|j| j.v > j.c)
        .map(|j| j.v - j.c)
        .sum();
    Ok(format!("{}", valued_sum))
}

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

Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int n = 0;
    static int m = 0;
    static int q = 0;
    static int[] a = null;
    static int[] b = null;
    static int[] c = null;
    static int[] d = null;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        q = in.nextInt();
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        for(int i=0; i<q; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            c[i] = in.nextInt();
            d[i] = in.nextInt();
        }
        
        int[] A = new int[n];
        int score = dfs(A, 0);
        System.out.println(score);
    }
    private static int dfs(int[] A, int nextIndex) {
        if(nextIndex > n-1) {
            return eval(A);
        }
        int lastVal = 1;
        if(nextIndex > 0) {
            lastVal = A[nextIndex-1];
        }
        int maxScore = 0;
        for(int i=lastVal; i<=m; i++) {
            int[] clone = Arrays.copyOf(A, A.length);
            clone[nextIndex] = i;
            int score = dfs(clone, nextIndex+1);
            maxScore = Math.max(maxScore, score);
        }
        return maxScore;
    }
    private static int eval(int[] A) {
        int score = 0;
        for(int i=0; i<q; i++) {
            if(A[b[i]-1] - A[a[i]-1] == c[i]) {
                score += d[i];
            }
        }
        return score;
    }
}


Measured memory_bytes: 47772
#include <iostream>

typedef long long ll;

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

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  string str;
  cin >> str;

  if((str[0] == str[1] && str[1] == str[2]) || (str[1] == str[2] && str[2] == str[3])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int a;
  scanf("%d",&a);
  if (a < 1200) printf("ABC\n");
  else printf("ARC\n");
}


Measured memory_bytes: 256
import heapq
n,m,s = map(int,input().split())
lst_graph = [list(map(int,input().split())) for _ in range(m)]
lst_cd = [list(map(int,input().split())) for _ in range(n)]
graph = [[] for _ in range(2501*n)]

#頂点番号と残金から拡張した頂点番号に変換
def f(x,c):
    if c >= 2500:
        c = 2500
    return (x-1)*2501+c


#拡張グラフ作成
for i in range(m):
    u,v,a,b = lst_graph[i]
    for c in range(2501):
        if c >= a:
            graph[f(u,c)].append((b,f(v,c-a)))
            graph[f(v,c)].append((b,f(u,c-a)))
for i in range(1,n+1):
    x,time = lst_cd[i-1]
    for c in range(2500):
        graph[f(i,c)].append((time, f(i,c+x)))


#ダイクストラ
def dijkstra_heap(s,edge):
    d = [float("inf")]*(2501*n)
    used = [True]*(2501*n)
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

ans = dijkstra_heap(f(1,s),graph)
for i in range(1,n):
    print(min(ans[(2501*i):(2501*i+2501)]))

Measured memory_bytes: 129836
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
ans = [0 for _ in range(n)]
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
tree = [[]for _ in range(n)]
for a, b in ab:
  tree[a-1].append(b-1)
del ab
for index, i in enumerate(tree):
  for j in i:
    ans[j] += ans[index]
print(" ".join(map(str, ans)))

Measured memory_bytes: 81072
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int N;ll sum=0;
  scanf("%d\n",&N);
  std::vector<char> S(N);
  std::vector<bool> Y; //Xなら0,Yなら1//
  for (size_t i = 0; i < N; i++) {
    scanf("%c\n",&S[i]);
  }
  for (size_t i = 0; i < N; i++) {
    if(S[i]==S[i+1]){
      Y.push_back(true);
      ++i;
    }else{
      Y.push_back(false);
    }
  }
  int leng=Y.size();

  if(Y[0]){
    sum=6;
  }else{
    sum=3;
  }
  for (size_t i = 1; i < leng; i++) {
    if(Y[i-1]==false){
      sum*=2;
    }else if(Y[i-1]==true && Y[i]==true){
      sum*=3;
    }
  }
  printf("%lld\n",(ll)sum%1000000007);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC optimization ("O3,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
using namespace std;

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define _ << ": " <<
#define watch1(var1) (cerr << #var1 _ var1 << ' ')
#define watch2(var1, var2) cerr << #var1 _ var1 << ", " << #var2 _ var2 << '\n';
#define watch3(var1, var2, var3) cerr << #var1 _ var1 << ", " << #var2 _ var2 << ", " << #var3 _ var3 << '\n';
#define wloop(size, arr) cerr << #arr << ": "; for (int i = 0; i < size; i++) cerr << arr[i] << " \n"[i+1 == size];

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int64_t n; read(n);
    int64_t sum = 0;
    for (int i = 1; i <= n; i++) sum += i * ((n/i + (n/i) * (n/i)) / 2);
    cout << sum;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define INF 1000
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int mi=INF,ma=0,a;
	rep(i,N+1){
		cin >> a;
		if (a<mi){
			mi = a;
		}else if(a>ma){
			ma = a;
		}
	}
	cout << ma - mi << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

priority_queue<int>PQ;
int w[301000];
int n;
long long L[301000], R[301000];
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= 3 * n; i++) {
		scanf("%d", &w[i]);
	}
	long long sum = 0;
	for (i = 1; i <= n; i++) {
		PQ.push(-w[i]);
		sum += w[i];
	}
	for (i = n; i <= 2 * n; i++) {
		L[i] = sum;
		sum += w[i + 1];
		PQ.push(-w[i+1]);
		sum += PQ.top();
		PQ.pop();
	}
	sum = 0;
	while (!PQ.empty())PQ.pop();
	for (i = 3*n; i > 2*n; i--) {
		PQ.push(w[i]);
		sum += w[i];
	}
	for (i = 2*n+1; i > n; i--) {
		R[i] = sum;
		sum += w[i - 1];
		PQ.push(w[i-1]);
		sum -= PQ.top();
		PQ.pop();
	}
	long long res = -1e18;
	for (i = n; i <= 2 * n; i++) {
		res = max(res, L[i] - R[i + 1]);
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 4856
N, K = map(int, input().split())
 
snukes = [0] * N
for i in range(K):
  d_i = int(input()) # throw away
  a_i = map(int, input().split())
  for a in a_i:
    snukes[a-1] += 1
 
counter = 0
for i in range(N):
  if snukes[i] == 0:
    counter += 1
 
print(counter)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 1000000007
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  


int power(int x,int y,int mod = MOD) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}

void solve()
{		
	int n,k;
	cin>>n>>k;
	vector<int> inp(n);
	for (auto &x:inp) cin>>x;
	sort(inp.begin(), inp.end());
	vector<vector<int>> dp(k+1,vector<int>(2,-1));
	for (int i=0;i<inp[0];i++){
		dp[i][0] = 1;
		dp[i][1] = 0;
	}
	for (int i=inp[0];i<=k;i++){
		for (auto x:inp){
			if (i-x>-1){
				if (dp[i][0]!=0) dp[i][0] = dp[i-x][1];
				if (dp[i][1]!=1) dp[i][1] = dp[i-x][0];
			}
		}
	}
	cout<<((dp[k][0] == 1) ? "Second" : "First" )<<endl;
	// debug() << imie(dp);
}
 
signed main(){
	
	// int t;
	// cin>>t;
	// while (t--)
	solve();	
 
}
	

Measured memory_bytes: 8804
#C_Make_A_Rectangle
import numpy as np

def MakeRectangle(N, A):
    A = np.array(A)
    length_list = list()
    length_buff = 0
    for length in np.sort(A)[::-1]:
        if len(length_list) == 2:
            break
        if length_buff == length and length != 0:
            length_list.append(length)
            length_buff = 0
        else:
            length_buff = length
    if len(length_list) < 2:
        return 0
    else:
        return length_list[0] * length_list[1]


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = MakeRectangle(N, A)
    print(S)

Measured memory_bytes: 31368
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
//ll MOD = 1000000007;
ll MOD = 998244353;
double EPS = 1e-11;

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

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//素因数分解O(√n)
vector<pair<ll, ll>> MakePrimeList(ll x) {
    vector<pair<ll, ll>> res;
    for(ll k=2; k*k<=x; k++) {
        if(x % k == 0) {
            ll cnt = 0;
            while(x % k == 0){
              x /= k;
              cnt++;
            }
            res.pb({k, cnt});
        }
    }
    if(x > 1) res.push_back({x, 1});
    return res;
}

ll N;
ll A[200010];
void solve(){
  cin >> N;
  rep(i, N) cin >> A[i];
  ll sum = 0;
  map<ll, ll> mp;
  ll ans = 0;
  rep(i, N){
    mp[sum]++;
    sum += A[i];
    ans += mp[sum];
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);    

    int n; cin>>n;
    deque<int> a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));

    vector<P> ans(n-1);
    rep(i,n-2){
        int l=a.front(),r=a.back();
        a.pop_back(); a.pop_front();
        if(a.back()-(l-r)>=(r-l)-a.front()){
            a.push_front(l-r);
            ans.at(i)=P(l,r);
        }else{
            a.push_back(r-l);
            ans.at(i)=P(r,l);
        }
    }
    int l=a.front(),r=a.back();
    cout<<r-l<<endl;
    ans.back()=P(r,l);

    rep(i,n-1){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }

}

Measured memory_bytes: 4352
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
# 同一の集合の判定
def same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False
# 集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x

# 集合の数
def uCnt(x):
    return -par[find(x)]

n, q = map(int, input().split())
par = [-1 for i in range(n)]

for i in range(q):
    c, x, y = map(int, input().split())
    if c == 0:
        unite(x, y)
    else:
        if same(x, y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 5784
// AtCoder Beginner Contest 095 - Problem D: Static Sushi (https://atcoder.jp/contests/abc095/tasks/arc096_b) 
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

struct Info { ll cals, dist, best; };

ll solve(ll N, ll C, const vector<ii>& xs)
{
    vector<Info> Ls(N + 1), Rs(N + 1);
    ll ans = 0;

    Rs[0] = Info { 0, 0, 0 };
    Ls[0] = Rs[0];

    for (ll i = 1; i <= N; ++i)
    {
        auto x = xs[i - 1].first;
        auto v = xs[i - 1].second;

        Rs[i].cals = Rs[i - 1].cals + v;
        Rs[i].dist = x;

        ans = max(ans, Rs[i].cals - Rs[i].dist);
        Rs[i].best = max(Rs[i - 1].best, Rs[i].cals - Rs[i].dist);

#ifdef DEBUG
cout << "i = " << i << ", x = " << x << ", v = " << v << '\n';
cout << "R cals = " << Rs[i].cals << ", dist = " << Rs[i].dist << ", best = " << Rs[i].best << '\n';
#endif
    }

    for (ll i = 1; i <= N; ++i)
    {
        auto x = xs[N - i].first;
        auto v = xs[N - i].second;

        Ls[i].cals = Ls[i - 1].cals + v;
        Ls[i].dist = C - x;

        ans = max(ans, Ls[i].cals - Ls[i].dist);
        Ls[i].best = max(Ls[i - 1].best, Ls[i].cals - Ls[i].dist);

#ifdef DEBUG
cout << "i = " << i << ", x = " << x << ", v = " << v << '\n';
cout << "L cals = " << Ls[i].cals << ", dist = " << Ls[i].dist << ", best = " << Ls[i].best << '\n';
#endif
    }

    for (ll i = 1; i <= N; ++i)
    {
        auto r = (Rs[i].cals - 2*Rs[i].dist) + Ls[N - i].best;
        auto l = (Ls[i].cals - 2*Ls[i].dist) + Rs[N - i].best;

        ans = max(ans, r);
        ans = max(ans, l);

#ifdef DEBUG
cout << "i = " << i << ", r = " << r << ", l = " << l << '\n';
#endif
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, C;
    cin >> N >> C;

    vector<ii> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, C, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int A[200200],B,N,K,sum[200200]={};
string S;

int main(){

    cout << fixed << setprecision(18);
    cin>>S;
     cout<<S.substr(0,3)<<endl;

}




Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var nm = Reads();
            var n = nm[0];
            var m = nm[1];
            var ans = new long[n];
            for (int i = 0; i < m; i++)
            {
                var ab = Reads();
                ans[ab[0]-1]++;
                ans[ab[1]-1]++;
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(ans[i]);
            }
            
            

            Console.Out.Flush();
        }
    }
}




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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}
const int maxn = 305;
int A[maxn][maxn];
int p[maxn];
int N,M;

int main()
{
    scanf("%d %d",&N,&M);
    _for(i,0,N){
        _for(j,0,M){
            scanf("%d",&A[i][j]);
        }
    }
    set<int> dele;
    int ans = N;

    _for(i,0,M-1){
        int maxc = 0;
        int maxm = -1;
        map<int,int> mp;

        _for(i,0,N){
            int &ind = p[i];
            while(dele.count(A[i][ind])){
                ind++;
            }
            if(++mp[A[i][ind]] > maxc){
                maxm = A[i][ind];
                maxc = mp[A[i][ind]];
            }
        }

        ans = min(ans,maxc);
        dele.insert(maxm);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define N 52
using namespace std;
typedef long long ll;
ll dp[2][N][N*N];
int n, a;
int x[N];
int tot;
int main() {
  cin>>n>>a;
  tot=0;
  for (int i = 0; i < n; ++i) {
  	cin>>x[i];
    tot += x[i];
  }
  memset(dp, 0LL, sizeof(dp));
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    int now = (i&1) ^ 1;
    memset(dp[now], 0, sizeof(dp[now]));
  	for (int j = 0; j <= i; ++j) {
      for (int k  =0; k < tot; ++k) {
      	dp[now][j+1][k+x[i]] += dp[now^1][j][k];
        dp[now][j][k] += dp[now^1][j][k];
      }
    }
  }
  ll res=0;
  for (int i= 1; i <= n; ++i) {
  	for (int j = 0; j <= tot; ++j) {
      if (j % i == 0 && j / i == a) {
      	res += dp[n&1][i][j];
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ll long long
const int Maxn=0;
#define mod 0x3f3f3f3f
using namespace std;
int a[100003],b[100003];
int aa[100003],bb[100003];
int s[100003];
priority_queue<int,vector<int>,greater<int> >q;
int main()
{  int n;
cin>>n;
int su,su1;su=su1=0;
int sum=0;
for(int i=1;i<=n;i++)
    { cin>>s[i];
       if(s[i]<0)a[++su]=s[i];
       else  b[++su1]=s[i];}
       sort(s+1,s+1+n);
       if(n==2)
       {
           cout<<s[2]-s[1]<<endl;
           cout<<s[2]<<" "<<s[1]<<endl;
           return 0;
       }
       sort(a+1,a+su+1);
       sort(b+1,b+1+su1);
       if(su1==0)
       {
           aa[++sum]=a[su];
           bb[sum]=a[su-1];
           int m=aa[sum]-bb[sum];
           for(int i=su-2;i>=1;i--)
           {
               aa[++sum]=m;
               bb[sum]=a[i];
               m-=a[i];
           }
       }
       else if(su==0)
       {
           aa[++sum]=b[1];
           bb[sum]=b[2];
           int m=b[1]-b[2];
           for(int i=3;i<su1;i++)
           {
               aa[++sum]=m;
               bb[sum]=b[i];
               m=m-b[i];
           }
           aa[++sum]=b[su1];
           bb[sum]=m;
       }
       else {
        for(int i=1;i<su1;i++)
               aa[++sum]=a[1],bb[sum]=b[i],a[1]=a[1]-b[i];
               // a[++su]=a[1]-b[i],aa[++sum]=a[1],bb[sum]=b[i];
               // cout<<su<<endl;
       aa[++sum]=b[su1];
       bb[sum]=a[1];
        int m=b[su1]-a[1];
        for(int i=2;i<=su;i++)
            {
                aa[++sum]=m;
                bb[sum]=a[i];
                m-=a[i];
            }
       }
   cout<<aa[sum]-bb[sum]<<endl;
   for(int i=1;i<=sum;i++)
    cout<<aa[i]<<" "<<bb[i]<<endl;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  SPEED;
  int n; cin >> n;
  vector<ll> a(n);
  vector<ll> dp(n, LLONG_MAX/2);
  rep(i, n) {
    cin >> a[i];
  }

  reverse(a.begin(), a.end());

  rep(i, n) {
    *upper_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }

  auto it = lower_bound(dp.begin(), dp.end(), LLONG_MAX/2);
  cout << distance(dp.begin(), it) << endl;

}

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

int lcs(string str1, string str2)
{
	int len[1001][1001] = { 0 };

	int len1 = str1.size();
	int len2 = str2.size();
	str1 = ' ' + str1;
	str2 = ' ' + str2;
	for (int i = 0; i <= len1; i++)
	{
		for (int l = 0; l <= len2; l++)len[i][l] = 0;
	}
	for (int i = 1; i <= len1; i++)
	{
		for (int l = 1; l <= len2; l++)
		{
			if (str1[i] == str2[l]) len[i][l] = len[i - 1][l - 1] + 1;
			else
			{
				len[i][l] = max(len[i - 1][l], len[i][l - 1]);
			}
		}
	}
	return len[len1][len2];
}
int main()
{
	int n;
	string str1, str2;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}

	return 0;
}

Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	cin>>t;
	int flag = 0;
	int c = 0;
	while(t--){
		int a,b;
		cin>>a>>b;
		if(a == b) c++;
		else c = 0;
		if(c >= 3) flag = 1;
 	}
 	if(flag) cout<<"Yes\n";
 	else cout<<"No\n";
 	return 0;
}


Measured memory_bytes: 3608
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

from collections import defaultdict, deque

d = defaultdict(int)
INF = 10 ** 9
def bfs(n):
    reached = [INF for _ in range(N)]
    reached[n] = 0
    q = deque()
    q.append(n)
    while q:
        x = q.popleft()
        for i in [-1, 1]:
            nx = x + i
            if nx < 0 or nx > N-1 or reached[nx] != INF:
                continue
            reached[nx] = reached[x] + 1
            q.append(nx)
        if x == X and reached[Y] == INF:
            reached[Y] = reached[x] + 1
            q.append(Y)
        if x == Y and reached[X] == INF:
            reached[X] = reached[x] + 1
            q.append(X)
    for i in range(N):
        k = reached[i]
        d[k] += 1

for i in range(N):
    bfs(i)

for i in range(1, N):
    print(d[i]//2)

            


Measured memory_bytes: 54620
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
cnt = 0
for i in range(n):
  c = min(a[i] + a[i+1],b[i])
  if b[i] > a[i]:
    a[i+1] = a[i] + a[i+1] - c
  cnt += c
print(cnt)

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

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;

	int a[100001]={},dp[100001]={0};

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

	dp[0]=0;
	int cur;
	for (int i = 1; i < n; i++)
	{
		cur=INT_MAX;
		for(int j=1; j<=k && i>=j;j++)
			cur= min(cur, dp[i-j]+ abs(a[i]-a[i-j]));
		
		dp[i] = cur;
	}
	
	cout<<dp[n-1];
	return 0;
}

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

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

    let mut count = 0;

    for i in 0..n {
        if (i + 1) % 2 == 1 && a[i] % 2 == 1 {
            count += 1;
        }
    }

    println!("{}", count)
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
long long n,ans;
int main()
{
	cin>>n;
	map<string,int> mp;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		sort(s.begin(),s.end());
		ans+=mp[s]; 
		mp[s]++;
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;
ll MOD = 1e9+7;

ll mod(ll num) {
	return ((num%MOD)+MOD)%MOD;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> neg, nneg;
	for (int i = 0; i < N; ++i) {
		ll num;
		cin >> num;
		if (num < 0) neg.push_back(-num);
		else nneg.push_back(num);
	}
	sort(begin(neg), end(neg));
	reverse(begin(neg), end(neg));
	sort(begin(nneg), end(nneg));
	reverse(begin(nneg), end(nneg));

	ll ans = 1;

	if (!nneg.size() && K%2) {
		for (int i = 0; i < K; ++i)
			ans = mod(ans*(-neg[neg.size()-1-i]));
		cout << ans << endl;
		return 0;
	}

	int cnt = 0, p1 = 0, p2 = 0;
	for (int i = 0; i < K; ++i) {
		if (p1 == neg.size()) ans = mod(ans*nneg[p2++]);
		else if (p2 == nneg.size() || neg[p1] > nneg[p2]) {
			++cnt;
			ans = mod(ans*(-neg[p1++]));
		} else ans = mod(ans*nneg[p2++]);
	}

	if (K == N) {
		cout << ans << endl;
		return 0;
	}

	if (cnt%2) {
		if (p1 == neg.size() || p2 == 0) {
			ans = 1;
			for (int i = 0; i < cnt-1; ++i) ans = mod(ans*(-neg[i]));
			for (int i = 0; i < K-(cnt-1); ++i) ans = mod(ans*nneg[i]);
		} else if (p2 == nneg.size() || p1 == 0) {
			ans = 1;
			for (int i = 0; i < cnt+1; ++i) ans = mod(ans*(-neg[i]));
			for (int i = 0; i < K-(cnt+1); ++i) ans = mod(ans*nneg[i]);
		} else if (neg[p1]*neg[p1-1] > nneg[p2]*nneg[p2-1]) {
			ans = 1;
			for (int i = 0; i < cnt+1; ++i) ans = mod(ans*(-neg[i]));
			for (int i = 0; i < K-(cnt+1); ++i) ans = mod(ans*nneg[i]);
		} else {
			ans = 1;
			for (int i = 0; i < cnt-1; ++i) ans = mod(ans*(-neg[i]));
			for (int i = 0; i < K-(cnt-1); ++i) ans = mod(ans*nneg[i]);
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 5436
n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    t = set()
    i = (high+low)//2
    for j in range(n-i*2+1):
        t.add(s[j:i+j])
        if s[i+j:j+2*i] in t:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,i,j;
  cin >> h >> w;
  char table[h+2][w+2];
  for(i = 1;i < h+1;i++){
    for(j = 1;j < w+1;j++){
      cin >> table[i][j];
    }
  }
  for(i = 0;i < h+2;i++){
    table[i][0] = '.';
    table[i][w+1] = '.';
  }
  for(j = 0;j < w+2;j++){
    table[0][j] = '.';
    table[h+1][j] = '.';
  }

  string tf = "Yes";
  for(i = 1;i < h+1;i++){
    for(j = 1;j < w+1;j++){
      if(table[i][j] == '#') {
        if(table[i-1][j] == '.' && table[i+1][j] == '.' && table[i][j-1] == '.' && table[i][j+1] == '.') {
          tf = "No";
          break;
        }
      }
    }
  }
  cout << tf << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
public class Contest
{
	public static void Main(string[] args)
	{
		string p = Console.ReadLine();
		string r = string.Empty;
		for(int i = 0; i < p.Length; i++)
		{
			r += (char)((10 - (p[i] - '0')) + '0');
		}
		Console.WriteLine(r);
	}
}

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

int main()
{
    long long int T[5],N,i,m,sum;
    scanf("%lld",&N);
    for(i=0; i<5; i++)
        scanf("%lld",&T[i]);
    m=T[0];
    for(i=1; i<5; i++)
        if(T[i]<m)
            m=T[i];
    if(N%m==0)
        sum=N/m+4;
    else
        sum=N/m+5;
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 128