akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n);
    Cinm(int, n, a);
    for(auto e : a){
        if(e.second == 2 || (n % 2 == 1 && e.first == 0 && e.second == 1)) continue;
        Cout(0);
        return 0;
    }
    ll ans = 1;
    Rep(n/2) ans = ans * 2 % MOD;
    Cout(ans);
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (a == b + c) {
      System.out.println("Yes");
      return;
    }

    if (a + b == c) {
      System.out.println("Yes");
      return;
    }

    if (a + c == b) {
      System.out.println("Yes");
      return;
    }

    System.out.println("No");
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int c=0;
  for(int i=1;i<=n;i+=2){
    int y=0;
    for(int j=1;j<=i;j++){
      if(i%j==0) y++;
    }
    if(y==8) c++;
  }
  cout<<c;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(b>=a){
      System.out.println(a);
    }else{
      System.out.println(a-1);
    }
  }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W,a,b;cin>>W>>a>>b;
  int c=0;
  if(a+W<b)c=b-(a+W);
  else if(b+W<a)c=a-(b+W);
  cout<<c<<endl;
}

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(3e3 + 10)

using namespace std;
double dp[N][N];

void solve() {
	int n; cin >> n;
	vector<double> a(n);
	for (double &d : a) cin >> d;
	for (int i = n; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			if (i ==  n) dp[i][j] = (2 * j > n);
			else
				dp[i][j] = dp[i + 1][j + 1] * a[i] + dp[i + 1][j] * (1 - a[i]);
		}
	}

	cout << fixed << setprecision(10) << dp[0][0] << endl;


}
// Remember to clear the global containers

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 49904
#include<stdio.h>
int main(){
  int m[100],f[100],r[100],i;
  for(i=0;i >= 0;i++){
    scanf("%d %d %d",&m[i],&f[i],&r[i]);
    if(m[i] == -1 && f[i] == -1 && r[i] == -1)
      break;
 if(m[i] + f[i] < 30 || m[i] == -1 || f[i] == -1){

      printf("F\n");

    }else if(m[i] + f[i] >= 80){

      printf("A\n");

    }else if(65 <= m[i] + f[i] && m[i] + f[i] < 80){

      printf("B\n");

    }else if(50 <= m[i] + f[i] && m[i] + f[i] < 65 || r[i] >= 50){

      printf("C\n");

    }else if(30 <= m[i] + f[i] && m[i] + f[i] < 50){

      printf("D\n");

    }
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	arrin(arr,n);
	for(i=0;i<n;i++)
	{
	    if(i%2==0 and arr[i]%2)
	    cnt++;
	}
	cout<<cnt;
	
}
int32_t main() {
    fast
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w+", stdout);
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e5 + 123;
const int PLS = 3e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e16;


ll n, m, a[N], dp[N];
vector <ll> g[N];
bool vis[N];


void dfs(int u) {
    vis[u] = 1;
    for (int i = 0; i < g[u].size(); i++) {
        if (!vis[g[u][i]])
            dfs(g[u][i]);
        dp[u] = max(dp[u], 1 + dp[g[u][i]]);
    }
}


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    ll u, v;
    for (int i = 1; i <= m; i++) {
        cin >> u >> v;
        g[u].pb(v);
    }
    for (int i = 1; i <= n; i++)
        if (!vis[i])
            dfs(i);
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, dp[i]);
    cout << ans;
}


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

const int _ = 2e5 + 7;
struct Edge{int end , id , upEd;}Ed[_ << 1];
int head[_] , N , M , val[_] , D[_] , col[_] , cntEd;
void addEd(int a , int b , int c){Ed[++cntEd] = (Edge){b , c , head[a]}; head[a] = cntEd;}
int fa[_] , sz[_]; bool vis[_];
int find(int x){return fa[x] == x ? x : (fa[x] = find(fa[x]));}
void dfs(int x , int p , int c){
	col[x] = c; vis[x] = 1;
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p)
			if(D[Ed[i].end] == D[x] && !vis[Ed[i].end]){dfs(Ed[i].end , x , c ^ 1); val[Ed[i].id] = D[x];}
			else if(D[Ed[i].end] <= D[x]) val[Ed[i].id] = 1e9;
}

int main(){
	cin >> N >> M; for(int i = 1 ; i <= N ; ++i) cin >> D[i];
	for(int i = 1 ; i <= M ; ++i){int s , t; cin >> s >> t; addEd(s , t , i); addEd(t , s , i);}
	vector < int > pos; for(int i = 1 ; i <= N ; ++i) pos.push_back(i);
	sort(pos.begin() , pos.end() , [&](int x , int y){return D[x] < D[y];});
	for(int i = 0 , pi ; i < N ; i = pi){
		pi = i; while(pi < N && D[pos[pi]] == D[pos[i]]){sz[fa[pos[pi]] = pos[pi]] = 1; ++pi;}
		for(int j = i ; j < pi ; ++j)
			for(int k = head[pos[j]] ; k ; k = Ed[k].upEd)
				if(D[Ed[k].end] == D[pos[j]] && find(Ed[k].end) != find(pos[j])){
					sz[find(pos[j])] += sz[find(Ed[k].end)]; fa[find(Ed[k].end)] = find(pos[j]);
				}
		for(int j = i ; j < pi ; ++j)
			if(fa[pos[j]] == pos[j])
				if(sz[pos[j]] > 1) dfs(pos[j] , 0 , 0);
				else{
					bool flg = 0;
					for(int k = head[pos[j]] ; k ; k = Ed[k].upEd)
						if(D[Ed[k].end] < D[pos[j]])
							if(!flg){col[pos[j]] = col[Ed[k].end]; val[Ed[k].id] = D[pos[j]] - D[Ed[k].end]; flg = 1;}
							else val[Ed[k].id] = 1e9;
					if(!flg){puts("-1"); return 0;}
				}
	}
	for(int i = 1 ; i <= N ; ++i) putchar(col[i] ? 'W' : 'B');
	cout << endl; for(int i = 1 ; i <= M ; ++i) cout << val[i] << endl;
	return 0;
}

Measured memory_bytes: 12408
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {
	
	ll N;
	cin >> N;
	vll a(N);
	rep(i, N) cin >> a[i];

	cout << accumulate(all(a), 0) - N << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int num[505050];
int S[505050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int cur=0;
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		cur+=x;
		cur%=86400;
		num[cur]++;
		cur+=y;
		cur%=86400;
	}
	FOR(i,86400*3) {
		S[i+1]=S[i]+num[i];
		num[i+86400]=num[i];
	}
	int ma=0;
	FOR(i,86400*2) ma=max(ma,S[i+3600*3+1]-S[i]);
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

int main(void)
{
	int b[3];
	int i;
	
	for (i = 0; i < 3; i++){
		scanf("%d", &b[i]);
	}
	if ((b[0] + b[1] == 2) || b[2] == 1){
		printf("Open\n");
	}
	else {
		printf("Close\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    long long n, m, tmp = 0;
    std::cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        std::cin >> tmp;
        n -= tmp;
    }
    if (n >= 0) { std::cout << n << std::endl; }
    else
    {
        std::cout << -1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3636
function main()
    N = parse(Int, readline())
    t = zeros(Int, N + 1)
    x = zeros(Int, N + 1)
    y = zeros(Int, N + 1)
    
    for i = 2:N + 1
        (t[i], x[i], y[i]) = map(x -> parse(Int, x), split(readline()))
    end

    can = true
    for i = 1:N 
        dt = t[i + 1] - t[i]
        dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
        if dt < dist
            can = false
        end
        if dist % 2 != dt % 2
            can = false
        end
    end

    if can
        println("Yes")
    else
        println("No")
    end
end

main()

Measured memory_bytes: 151936
# C - Bugged
N = int(input())
S = [int(input()) for _ in range(N)]
S = sorted(S)

ans = sum(S)

if ans % 10 != 0:
	pass
else:
	for i in range(N):
		if S[i] % 10 != 0:
			ans = ans - S[i]
			break
	else:
		ans = 0

print(ans)


Measured memory_bytes: 9020
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	vector<ll> sh;
	queue<ll> q;
	q.push(3);
	q.push(5);
	q.push(7);
	while(!q.empty()){
		ll he = q.front();
		q.pop();
		set<char> se;
		se.clear();
		string st = to_string(he);
		REP(i, st.size()) se.insert(st[i]);
		if(se.size() == 3)sh.push_back(he);
		if(he * 10 < 1000000000){
			q.push(he * 10 + 3);
			q.push(he * 10 + 5);
			q.push(he * 10 + 7);
		}
	}
	ll n;
	cin >> n;
	auto it = upper_bound(sh.begin(), sh.end(), n);
	cout << it - sh.begin() << endl;
}

Measured memory_bytes: 768
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <iostream>

using namespace std;
typedef pair<int, int> P;
P dp[33][33][33][33];
bool used[33][33][33][33] = {};
int h, w, s, di;
int sum[34][34] = {};
int d[33][33];

P solve(int lx, int ly, int rx, int ry) {
	if (used[lx][ly][rx][ry]) return dp[lx][ly][rx][ry];
	used[lx][ly][rx][ry] = true;
	int s = sum[rx][ry]-sum[lx][ry]-sum[rx][ly]+sum[lx][ly];
	P res;
	if (s-di < 0) {
		res = P(-1000000, -1000000);
	} else {
		res = P(1, s-di);
	}
	for (int i = lx+1; i < rx; i++) {
		P p1 = solve(lx, ly, i, ry);
		P p2 = solve(i, ly, rx, ry);
		P p = P(p1.first+p2.first, min(p1.second, p2.second));
		if (p.second < 0) continue;
		if (res.first < p.first) {
			res = p;
		} else if (res.first == p.first) {
			res.second = max(res.second, p.second);
		}
	}
	for (int j = ly+1; j < ry; j++) {
		P p1 = solve(lx, ly, rx, j);
		P p2 = solve(lx, j, rx, ry);
		P p = P(p1.first+p2.first, min(p1.second, p2.second));
		if (p.second < 0) continue;
		if (res.first < p.first) {
			res = p;
		} else if (res.first == p.first) {
			res.second = max(res.second, p.second);
		}
	}
	dp[lx][ly][rx][ry] = res;
	return res;
}

int main() {
	while (true) {
		cin >> h >> w >> s;
		fill_n(used[0][0][0], 33*33*33*33, false);
		fill_n(sum[0], 34*34, 0);
		if (!h) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				scanf("%d", &(d[i][j]));
				sum[i+1][j+1] = d[i][j];
			}
		}
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
			}
		}
		//for (int i = 0; i <= h; i++) {
		//	for (int j = 0; j <= w; j++) {
		//		printf("%d ", sum[i][j]);
		//	}
		//	printf("\n");
		//}
		di = sum[h][w]-s;
		//printf("%d\n", di);
		P p = solve(0, 0, h, w);
		//P p1 = solve(0, 1, 4)
		printf("%d %d\n", p.first, p.second);
		//printf("%d %d\n", solve());
	}
}

Measured memory_bytes: 11648
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

s=input()
ss=""
for i in range(1<<3):
 x=s[0]
 y=int(s[0])
 for j in range(3):
   if i>>j&1:
      x+="+"+s[j+1]
      y+=int(s[j+1])
   else:
      x+="-"+s[j+1]
      y-=int(s[j+1])
 if y==7:ss=x+"=7"
print(ss)

Measured memory_bytes: 38384
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [[]]
    for i in range(n):
        a.append([int(i) for i in ipt().split()])
    ta = [1]*(n+1)
    ht = [[0]*(n+1) for i in range(n+1)]
    ng = []
    for i in range(1,n+1):
        ai = min(i,a[i][0])
        bi = max(i,a[i][0])
        if ht[ai][bi]:
            ng.append((ai,bi))
        ht[ai][bi] += 1
    t = 0
    d = 0
    while ng:
#        print(ng,ht)
        pg = []
        for ag,bg in ng:
            tag = ta[ag]
            if tag != n-1:
                aai = min(ag,a[ag][tag])
                abi = max(ag,a[ag][tag])
                if ht[aai][abi]:
                    pg.append((aai,abi))
                ht[aai][abi] += 1
                ta[ag] += 1
            tbg = ta[bg]
            if tbg != n-1:
                bai = min(bg,a[bg][tbg])
                bbi = max(bg,a[bg][tbg])
                if ht[bai][bbi]:
                    pg.append((bai,bbi))
                ht[bai][bbi] += 1
                ta[bg] += 1
            t += 1
        d += 1
        ng = pg*1

    if t == n*(n-1)//2:
        print(d)
    else:
        print(-1)



    return None

if __name__ == '__main__':
    main()


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

using namespace std;
using llint = long long;

//0, 1, 2
const int N = 100, B = 1e9 + 7;

char s1[N], s2[N];
llint dp[N][3][3];

void updadd(llint &a, llint b) {
  a += b;
  a %= B;
  if (a < 0) a += B;
}

int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s1);
  scanf("%s", s2);
  //dp[0]
  if (s1[0] == s2[0]) {
    for (int i = 0; i < 3; ++i) dp[0][i][i] = 1;
  } else {
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        dp[0][i][j] = (i != j);
      }
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        vector <int> vj, vk;
        auto go = [=](char *s1, vector <int> &vj, int j) {
          if (s1[i + 1] == s1[i]) {
            vj.push_back(j);
          } else {
            for (int x = 0; x < 3; ++x) if (x != j) vj.push_back(x);
          }
        };
        go(s1, vj, j);
        go(s2, vk, k);
        for (auto nj : vj) {
          for (auto nk : vk) {
            if (s1[i + 1] == s2[i + 1]) {
              if (nj == nk) {
                updadd(dp[i + 1][nj][nk], dp[i][j][k]);
              }
            } else {
              if (nj != nk) {
                updadd(dp[i + 1][nj][nk], dp[i][j][k]);
              }
            }
          }
        }
      }
    }
  }
  llint ans = 0;
  for (int j = 0; j < 3; ++j) {
    for (int k = 0; k < 3; ++k) {
      updadd(ans, dp[n - 1][j][k]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<string> S(N);

    for(int i = 0; i < N; i ++){
        cin >> S[i];
    }
    sort(S.begin(), S.end());

    int max_count = 0;
    int count = 1;

    for(int i = 1; i < N; i ++){
        if(S[i] == S[i - 1]){
            count ++;
        }else{
            if(count > max_count){
                max_count = count;
            }
            count = 1;
        }
    }
    if(count > max_count){
        max_count = count;
    }
    count = 1;

    for(int i = 1; i < N; i ++){
        if(S[i] == S[i - 1]){
            count ++;
        }else{
            if(count == max_count){
                cout << S[i - 1] << endl;
            }
            count = 1;
        }
    }
    if(count == max_count){
        cout << S[N - 1] << endl;
    }
}

Measured memory_bytes: 15360
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

int c[10][10],n;

int mdig(int a) {
    int s = a;
    while(s / 10) {
        s /= 10;
    }
    return s;
}

int main() {
    cin >> n;
    for(int i = 1;i <= n;i++) {
        c[mdig(i)][i%10]++;
    }
    ll r = 0;
    for(int i = 0;i < 10;i++) for(int j =0;j < 10;j++) r += c[i][j] * c[j][i];
    cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n, l;    cin >> n >> l;
    vector<string> s(n);
    rep(i, n)   cin >> s[i];
    sort(ALL(s));
    rep(i, n) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 3596
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


int main(){	
	ll N;
	cin >> N;
	vector<P> X(N);
	rep(i, N) {
		cin >> X[i].first >> X[i].second;
	}
	SORT(X);
	ll now = X[0].first+X[0].second;
	ll del = 0;
	repn(i, N-1) {
		if (now <= X[i].first-X[i].second) {
			now = max(now, X[i].first+X[i].second);
		} else {
			del++;
			now = min(now, X[i].first+X[i].second);
		}
	}
	cout << N-del << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, t; scanf("%d%d", &n, &t);
	std::vector<int> a(n), b(n);
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);

		vec.push_back({a[i], b[i]});
	}
	sort(begin(vec), end(vec));

	auto dp = make_v<int>(n + 1, t + 1);
	for(int i = 0; i < n; i++) {
		int A = vec[i].first, B = vec[i].second;
		
		for(int j = 0; j < dp[i + 1].size(); j++) dp[i + 1][j] = dp[i][j];
		
		for(int j = 0; j < t; j++) {
			int to = std::min(j + A, t);
			
			dp[i + 1][to] = std::max(dp[i + 1][to], dp[i][j] + B);
		}
	}

	int ans = 0;
	for(auto v: dp[n]) ans = std::max(ans, v);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35584
import queue
import copy
import math

# 2つの入力を空白で分割し、数値化
N, M = map(int, input().split())

ac = set()
submits_count_until_AC = {} #

for i in range(0, M):
    p, S = input().split()

    prev = None

    if p in ac:
        continue

    if p in submits_count_until_AC:
        prev = submits_count_until_AC[p]
    else:
        prev = 0

    if S == "AC":
        ac.add(p)
    else:
        submits_count_until_AC[p] = prev + 1


ac_coount = len(ac)

pena = 0

for k, v in submits_count_until_AC.items():
    if k in ac:
        pena += v

print("{} {}".format(ac_coount, pena))


Measured memory_bytes: 15080
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string str;
  int diff='Z'-'A'+1;
  cin>>n;
  cin>>str;
  for(int i=0;i<str.size();i++){
    str[i]=(str[i]-'A'+n)%diff+'A';
  }
  cout<<str<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <deque>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    ll h,w;
    cin >> h >> w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    ll a = (w + 1) / 2;
    ll b;
    if(w % 2 == 0){
        b = a;
    }else{
        b = a - 1;
    }

    if(h % 2 == 0){
        cout << (a + b) * h / 2 << endl;
    }
    else{
        cout << (a + b) * (h / 2) + a << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define F first
#define S second
#define en "\n"
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;



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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;

	ll ans = 0;

	REP(i, n) {
		ll a, k;
		cin >> a >> k;
		while (a % k != 0) {
			if ((a % k) % (a / k + 1) == 0) {
				a -= a % k;
			}
			else {
				a -= ((a % k) / (a / k + 1) + 1) * (a / k + 1);
			}
		}
		ans ^= a / k;
	}

	cout << ((ans != 0) ? "Takahashi" : "Aoki") << en;

	return 0;
}


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

#define dd ch=getchar()
inline int read()
{
	int x=0;char dd;bool f=false;
	while(!isdigit(ch))f|=ch=='-',dd;
	while(isdigit(ch))x=(x<<1)+(x<<3)+ch-48,dd;
	return f?-x:x;
}
#undef dd
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}
#define writesp(x) (write(x),putchar(' '))
#define writeln(x) (write(x),putchar('\n'))

const int N=2e5+5;

int n,m;
int minn[N],fa[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline int pos(int x){return (x-1)%n+1;}
struct node{int u,v,w;}a[N<<1];
int tot=0;
inline void add(int u,int v,int w){a[++tot]=(node){u,v,w};}
inline bool cmp(const node &x,const node &y){return x.w<y.w;}
inline void CLANNAD_TXDY()
{
	sort(a+1,a+1+tot,cmp);
	for(int i=1;i<=n;i++)fa[i]=i;
	int cnt=0,ans=0;
	for(int i=1;i<=tot;i++)
	{
		int x=a[i].u,y=a[i].v,w=a[i].w;
		if(find(x)==find(y))continue;
		fa[find(x)]=find(y);
		ans+=w;
		if(++cnt==n-1)break;
	}
	writeln(ans);
}
signed main()
{
	n=read(),m=read();
	memset(minn,0x3f,sizeof(minn));
	for(int i=1;i<=m;i++)
	{
		int u=read()+1,v=read()+1,w=read();
		minn[u]=min(minn[u],w+1);
		minn[v]=min(minn[v],w+2);
		add(u,v,w);
	}
	for(int i=1;i<=n;i++)
		minn[pos(i+1)]=min(minn[pos(i+1)],minn[i]+2);
	for(int i=1;i<=n;i++)
		minn[pos(i+1)]=min(minn[pos(i+1)],minn[i]+2);
	for(int i=1;i<=n;i++)
		add(i,pos(i+1),minn[i]);
	CLANNAD_TXDY();
	return 0;
}

Measured memory_bytes: 13056
#include<cstdio>
#include<algorithm>
using namespace std;
int n,l,sum;
int pd(int x)
{
	return sum-x-l+1;
}
int main()
{
	scanf("%d%d",&n,&l);
	
	int i; 
	for(i=1;i<=n;i++)
	{
		sum+=l+i-1;
	}
	
	int z=1,y=n,mid;
	while(z<=y)
	{
		mid=z+(y-z)/2;
		if(pd(mid)<sum) y=mid-1;
		if(pd(mid)>sum) z=mid+1; 
		if(pd(mid)==sum) break;
	}
	
	int ans=sum-l-mid+1;
	
	printf("%d",ans);
	return 0;
}

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

int main(){
  set<char> s{'a', 'i', 'u', 'e', 'o'};
  char ch;
  cin >> ch;
  
  set<char>::iterator it = s.find(ch);
  if (it == s.end())
    cout << "consonant" << endl;
  else 
    cout << "vowel" << endl;
  
  return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
d = []
for i in range(10):
    a = list(map(int,input().split()))
    d.append(a)
def WF(d):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
WF(d)
L = []
for i in range(h):
    b = list(map(int,input().split()))
    L.append(b)
ans = 0
for i in range(h):
    for j in range(w):
        if L[i][j] == 1 or L[i][j] == -1:
            continue
        else:
            ans += d[L[i][j]][1]
print(int(ans))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int A,B,M;
    cin >> A >> B >> M;
    
    int a[A],b[B];
    int a_min = MOD,b_min = MOD;
    for(int i=1;i<=A;i++){
        cin >> a[i];
        a_min = min(a_min,a[i]);
    }
    for(int i=1;i<=B;i++){
        cin >> b[i];
        b_min = min(b_min,b[i]);
    }
    
    int x[M],y[M],c[M],total[M],ans = a_min + b_min;
    for(int i=0;i<M;i++){
        cin >> x[i] >> y[i] >> c[i];
        total[i] = a[x[i]]+b[y[i]]-c[i];
        ans = min(ans,total[i]);
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double


using namespace std;
const int N = 1e5 + 5;


int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += max(0, a[i - 1] - a[i]);
        if(a[i] < a[i - 1])
            a[i] = a[i - 1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4376
#include<stdio.h>
int arr[1000020];
long long i, j;
void sieve() {
	//puts("sieve");
	int count = 0;
	//puts("declare");
	for(i=2; i<1000020; i++) {
		//printf("loop %lld\n", i);
		if(arr[i] == -1) continue;
		if(arr[i] == 0) arr[i] = ++count;
		for(j=i*i; j<1000020; j+=i) {
			//printf("%d ", j);
			arr[j] = -1;
		}
	}
	//puts("SIEVE_END");
}

int main() {
	//puts("MAIN1");
	sieve();
	//puts("MAIN2");
	int n;
	while(scanf("%d", &n) != EOF) {
		while(1) {
			if(arr[n] == -1) {
				n--;
				continue;
			}
			printf("%d\n", arr[n]);
			break;
		}
	}
	return 0;
}

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

li_ans = [0] * n

for a in range(1, 110):
    for b in range(1, 110):
        for c in range(1, 110):
            val = (a ** 2) + (b ** 2) + (c ** 2) + (a * b) + (b * c) + (c * a)
            if val <= n:
                li_ans[val - 1] += 1
for an in li_ans:
    print(an)


Measured memory_bytes: 9272
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define mp make_pair
#define F first
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y)
#define S second
#define ll long long int
#define inf 1000000014
#define infl (ll)(1e18+25934834)
#define MOD 1000000007
#define sz(x) (int) x.size()
#define pi pair< ll,ll >
#define pii pair<pi,int>
#define nax 15005000
#define pu push
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define trace1(x)  cerr << #x << ": " << x << endl
#define trace2(x, y)  cerr << #x << ": " << x << " | " << #y << ": " << y << endl
using namespace std;
int main(int argc, char const *argv[])
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w", stdout);
    int n,m;
    sd2(n,m);
    int sq = sqrt(m);
    int temp,temp2;
    int fans = 0;
    for(int i = 1 ; i <= sq;i++)
    {
        if(m % i == 0)
        {
            temp = m / i;
            if(i >= n)
                fans = max(fans, temp);
            if(m / i >= n)
                fans = max(fans, i);
        }
    }
    printf("%d\n",fans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int n,m;
  scanf("%d%d",&n,&m);
  int i,j,k;
  int flag[30] = {0};
  int f,ans=0;
  REP(i,n)
  {
    k=0;
    scanf("%d",&k);
    REP(j,k)
    {
      f=0;
      scanf("%d",&f);
      flag[f-1]++;
    }
  }
  REP(i,m)
  {
    if(flag[i]==n)
    {
      ans++;
    }
  }
  printf("%d",ans);
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<int> v[100005];
bool visited[100005];
int dist[100005];
int par[100005];
void bfs(int s)
{
	queue<int> q;
	dist[s]=0;
	q.push(s);
	while(!q.empty())
	{
		int cur=q.front();
		q.pop();
		visited[cur]=true;
		for(auto i:v[cur])
		{
			if(dist[i]>dist[cur]+1)
			{
				dist[i]=dist[cur]+1;
				par[i]=cur;
				q.push(i);
			}
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)dist[i]=1e8;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}	
	bfs(1);
	for(int i=1;i<=n;i++)
	{
		if(!visited[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++)cout<<par[i]<<endl;
}

Measured memory_bytes: 11040
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////

int main(){
	
	string s;
	map<char,int> m;
	cin >> s;

    rep(i,0,sz(s)) m[s[i]] ++;

    if((int)m.size() == sz(s))cout <<"yes" << endl;
    else cout << "no" <<endl;
	
    
	return  0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        b[i] = (b[i - 1] + a) % m;
    }

    map<int, int> mp;
    for (int i = 0; i <= n; i++) {
        mp[b[i]]++;
    }

    ll r = 0;
    for (const auto& p : mp) {
        ll t = p.second;
        r += t * (t - 1) / 2;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
using namespace std;
typedef pair<int, int> P;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,q;
  cin>>a>>b>>q;
  vector<int> s(a),t(b);
  rep(i,a)cin>>s[i];
  rep(i,b)cin>>t[i];
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  rep(i,q){
    int x;
    cin>>x;
    auto a_itr=lower_bound(s.begin(),s.end(),x),b_itr=lower_bound(t.begin(),t.end(),x);
    vector<int> a_memo, b_memo;
    if(a_itr!=s.end())a_memo.push_back(*a_itr);
    if(b_itr!=t.end())b_memo.push_back(*b_itr);
    if(a_itr--!=s.begin())a_memo.push_back(*a_itr);
    if(b_itr--!=t.begin())b_memo.push_back(*b_itr);
    int ans=LLONG_MAX;
    rep(j,a_memo.size()){
      rep(k,b_memo.size()){
        int m=min(abs(a_memo[j]-x),abs(b_memo[k]-x))+abs(a_memo[j]-b_memo[k]);
        ans=min(m,ans);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 2944
def chmin(arr, arr_ind, x, y)
    if (x > y) 
        arr[arr_ind] = y
    end
    return arr
end

n = gets.to_i
a = gets.split(" ").map(&:to_i)
n.times { a << gets.to_i }

dp = Array.new(a.length, Float::INFINITY)

dp[0] = 0

for i in 1..n-1 
    dp = chmin(dp, i, dp[i], dp[i-1] + (a[i] - a[i-1]).abs)
    if i > 1
        dp = chmin(dp, i, dp[i], dp[i-2] + (a[i] - a[i-2]).abs)
    end
end

puts(dp[n-1])


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

using namespace std;

typedef long long LL;
const int N = 1e3 + 4;

int a[N * (int)1e3];

int p[N], tot;
bool isp[N];

void euler() {
    for (int i = 2; i < N; i++) {
        if (!isp[i]) {
            p[tot++] = i;
        }
        for (int j = 0; j < tot && p[j] * i < N; j++) {
            isp[p[j] * i] = true;
            if (i % p[j] == 0) break;
        }
    }
}

bool mk[N * (int)1e3];

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    euler();

    int n;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool ok = true;
    int g = a[0];
    for (int i = 0; i < n; i++) {
        g = __gcd(g, a[i]);
        for (int j = 0; j < tot; j++) {
            int c = 0;
            while (a[i] % p[j] == 0) {
                a[i] /= p[j];
                c++;
            }
            if (c) {
                if (mk[p[j]]) {
                    ok = false;
                    break;
                }
                mk[p[j]] = true;
                
            }
        }
        if (a[i] > 1) {
            if (mk[a[i]]) {
                ok = false;
                break;
            }
            mk[a[i]] = true;
            
        }
    }
    
    if (ok) {
        cout << "pairwise coprime\n";
    }
    else if (g == 1) {
        cout << "setwise coprime\n";
    }
    else cout << "not coprime\n";
    return 0;
}

Measured memory_bytes: 7884
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  rep(i, n){
    a[i] /= 2;
  }
  ll l = 1;
  rep(i, n){
    l = LCM(a[i], l);
    if(l > m){
      print(0);
      return 0;
    }
  }
  rep(i, n){
    if((l/a[i])%2==0){
      print(0);
      return 0;
    }
  }
  print((m-l)/(2*l)+1);
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

a=max(arr)

mat=[0]*(a+3)

for i in range(n):
    mat[arr[i]]+=1
    mat[arr[i]+1]+=1
    mat[arr[i]+2]+=1
print(max(mat))


Measured memory_bytes: 78016
costa = 0
costb = 0
n = 0


N,M,X = map(int, input().split())
A = list(map(int, input().split()))


for i in range(X,-1,-1):
    j = A.count(i)
    if j == 1:
        costa = costa + 1

for n in range(X,N+1):
    k = A.count(n)
    if k == 1:
        costb = costb + 1

if costa > costb:
    print(costb)
else:
    print(costa)
        

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from bisect import bisect_left,bisect_right
def main():
    N,M,K = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    for i in range(N):
        A[i + 1] += A[i]
    for i in range(M):
        B[i + 1] += B[i]
    
    ans = 0
    for i in range(N + 1):
        idx = bisect_left(B,K - A[i])
        if 0 <= idx <= M and A[i] + B[idx] == K:
            ans = max(ans,i + idx)
        else:
            idx -= 1
            if idx >= 0:
                ans = max(ans,i + idx)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 114220
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    std::vector<std::vector<int>> a(3, std::vector<int>(3));
    rep(i, 3) rep(j, 3) std::cin >> a[i][j];
    int n;
    std::cin >> n;
    std::map<int, int> b;
    rep(i, n) {
        int _;
        std::cin >> _;
        b[_] = 1;
    }
    bool isOk = false;
    rep(i, 3) {
        if(b[a[i][0]] > 0 and b[a[i][1]] > 0 and b[a[i][2]] > 0) {
            isOk = true;
        }
        if(b[a[0][i]] > 0 and b[a[1][i]] > 0 and b[a[2][i]] > 0) {
            isOk = true;
        }
    }
    if(b[a[0][0]] > 0 and b[a[1][1]] > 0 and b[a[2][2]] > 0) {
        isOk = true;
    }
    if(b[a[0][2]] > 0 and b[a[1][1]] > 0 and b[a[2][0]] > 0) {
        isOk = true;
    }
    std::cout << (isOk ? "Yes" : "No") << std::endl;
}

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

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

using namespace std;

typedef pair<string,int> P;

int main(){
  int n,q,Time;
  queue<P> Q;
  string name;

  cin >> n >> q;
  for(int i = 0 ; i < n ; i++){
    cin >> name >> Time;
    Q.push(P(name,Time));
  }

  int ans = 0;
  while(!Q.empty()){
    P p = Q.front(); Q.pop();

    if(p.second <= q){
      ans += p.second;
      cout << p.first << " " << ans << endl;
    }else{
      ans += q; 
      p.second -= q;
      Q.push(p);
    }
  }

  return 0;
}

Measured memory_bytes: 4404
import java.util.Scanner;

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

      int a = r*100 + g*10 + b;

      if(a % 4 ==0) {
          System.out.println("YES");
      } else {
          System.out.println("NO");
      }
  }
}

Measured memory_bytes: 21972