akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Graph{
public:
    typedef pair<int,int> Node;
    class Cmp{
    public:
        bool operator()(Node &n1,Node &n2){
            return n1.second>n2.second;
        }
    };
    static const int MAXN=1e5+10;
    int N,M;
    vector<int>G[MAXN];
    int d[MAXN][3];
    //每个节点的状态有三种,通过bfs将所有的状态全部遍历一遍
    int vis[MAXN][3];
    void dijstra(int s){
        queue<Node>q;
        memset(d,0x3f,sizeof(d));
        memset(vis,0,sizeof(vis));
        d[s][0]=0;
        q.push((Node){s,0});
        while(!q.empty()){
            auto t=q.front();
            q.pop();
            if(vis[t.first][t.second])continue;
            vis[t.first][t.second]=true;
            for(auto v:G[t.first]){
                int m=(t.second+1)%3;
                if(d[v][m]>d[t.first][t.second]+1){
                    d[v][m]=d[t.first][t.second]+1;
                    q.push(Node{v,m});
                }
            }
        }
    }
    void read(){
        cin>>N>>M;
        for(int t=0;t<M;t++){
            int u,v;
            cin>>u>>v;
            G[u].push_back(v);
        }
    }
};
class Solver{
public:
    static const int MAXN=1e5+10;
    Graph *g;
    void solve(){
        ios::sync_with_stdio(false);
        g=new Graph();
        g->read();
        int S,T;
        cin>>S>>T;
        g->dijstra(S);
        if(g->d[T][0]==0x3f3f3f3f)cout<<-1;
        else cout<<g->d[T][0]/3;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, d, a;
  cin >> n >> d >> a;
  vector<ll> x(n), h(n);
  REP(i, n) {
    cin >> x[i] >> h[i];
    h[i] = (h[i] + a - 1) / a;
  }
  vector<ll> ord(n), cnt(n + 5, 0);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](ll i, ll j) { return x[i] < x[j]; });

  ll ans = 0;
  REP(i, n) {
    ll j = ord[i];
    // h[j] - cnt[i]回攻撃
    ll t = max(h[j] - cnt[i], 0LL);
    ans += t;
    // x[j] + 2d まで攻撃可能
    ll ok = -1, ng = n;
    while (ok + 1 < ng) {
      ll m = (ok + ng) / 2;
      (x[ord[m]] <= x[j] + 2 * d ? ok : ng) = m;
    }
    cnt[i] += t;
    cnt[ng] -= t;
    cnt[i + 1] += cnt[i];
  }
  cout << ans << endl;
}

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


int main(){
    int M,D;
    cin>>M>>D;

    int count=0;
    for(int i=1;i<=D;i++){
        int d;
        int dd;
        d=i%10;
        dd=i/10;
        int ans;
        ans=d*dd;
        if(0<ans && ans<=M && d>1 && dd>1){
            count++;
        }
    } 
    cout<<count<<endl; 
}


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


void solve(long long N, long long A, long long B)
{
    long long p=A+B;
    long long num=N/p*A+min(N%p,A);
    cout<<num<<endl;
}

int main()
{
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
S = str(input())
slist=list(S)
year=""
mon=""
day=""
for i in range(10):
    if i < 4: 
        year+=slist[i]
    elif i < 7 and i!=4:
        mon+=slist[i]
    elif i < 10 and i!=4 and i!=7:
        day+=slist[i]
if int(year) <= 2019:
    if int(mon) <= 4:
        if int(day) <= 30:
            print("Heisei")
        else:
            print("TBD")
    else:
        print("TBD")
else:
    print("TBD")

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

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = 1e9;
    rep(i,n-m+1){
        int tmp = 0;
        rep(j,m){
            if(s[i+j] != t[j]) tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;
const int MAX = 100'000;

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

  int cnt = 0;
  for (int A = 1; A < N; ++A) {
    int B = (N - 1) / A;
    if (A * B < N) {
      cnt += B;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
int H, W;
char S[410][410];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool used[410][410];
void dfs(int x, int y, int &b, int &w){
	used[x][y] = true;
	if(S[x][y] == '#') b++;
	else w++;
	for(int i = 0; i < 4; i++){
		int rx = x + dx[i];
		int ry = y + dy[i];
		if(1 <= rx && rx <= H && 1 <= ry && ry <= W){
			if(S[x][y] != S[rx][ry] && !used[rx][ry]){
				dfs(rx, ry, b, w);
			}
		}
	}
}


int main(){
	cin >> H >> W;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			cin >> S[i][j];
		}
	}
	LL ans = 0;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			int b, w;
			b = w = 0;
			if(!used[i][j]){
				dfs(i, j, b, w);
			}
			ans += (LL)b * (LL)w;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10624
function main()
  
  s = split(readline(),"")
  ans = ["" for i in 1:(length(s)+1)]
  
  for i in 1:length(s)
    
    if s[i] == "B"
      pop!(ans)
    else
      push!(ans,s[i])
    end
    
  end
  
  for i in 1:length(ans)
  	print(ans[i])
  end
  
end

main()

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e7+100;

int main() {
  // 累積和の差分をとる
  // r,lを指定して、rの右側を順に見ていく
  int N;cin>>N;
  vector<ll> AS(N);
  REP(i,N) cin>>AS[i];
  vector<ll> sumAS(N+1,0);
  REP(i,N) sumAS[i+1]=sumAS[i]+AS[i];
  // DUMP(sumAS);

  map<ll,ll> mp;
  ll ans = 0;
  REP(i,N+1) {
    ans += mp[sumAS[i]];
    mp[sumAS[i]]++;
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int a,b;
    cin >> a >> b;
    if(b > a)swap(a,b);
    REP(i,a)cout <<b;
    cout << "\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S=sc.nextLine();
		String T=sc.nextLine();
      	String U=T.substring(0,S.length());
		if(U.equals(S)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 27028
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        
        if(a >= 3200){
            System.out.println(s);
        } else {
        System.out.println("red");
        }
    }
}


Measured memory_bytes: 35648
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
typedef long long ll;
typedef long double ld;

int main()
{
 int s, w;
 cin >> s >> w;

 if (w >= s)
 {
  cout << "unsafe" << endl;
 }
 else
 {
  cout << "safe" << endl;
 }
 return 0;
};


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e9 + 10;
const int N = 2e6 + 10;

struct pt {
    int x, y;
} a[N], b[N];

int main() {
    //freopen("a.in", "r", stdin);
    int r, c, n;
    cin >> r >> c >> n;
    vector <pair <int, int> > v1, v2, v3, v4;

    fr(i, n) {
        cin >> a[i].x >> a[i].y >> b[i].x >> b[i].y;
        if ((a[i].x == 0 || a[i].x == r || a[i].y == 0 || a[i].y == c) &&
            (b[i].x == 0 || b[i].x == r || b[i].y == 0 || b[i].y == c)) {
            if (a[i].x == 0)
                v4.pb(mp(a[i].y, i));
            else if (a[i].x == r)
                v2.pb(mp(a[i].y, i));
            else if (a[i].y == 0)
                v1.pb(mp(a[i].x, i));
            else
                v3.pb(mp(a[i].x, i));

            if (b[i].x == 0)
                v4.pb(mp(b[i].y, i));
            else if (b[i].x == r)
                v2.pb(mp(b[i].y, i));
            else if (b[i].y == 0)
                v1.pb(mp(b[i].x, i));
            else
                v3.pb(mp(b[i].x, i));
        }
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    sort(v3.begin(), v3.end());
    sort(v4.begin(), v4.end());
    reverse(v3.begin(), v3.end());
    reverse(v4.begin(), v4.end());

    vector <int> nums;
    fr(i, (int)v1.size()) nums.pb(v1[i].second);
    fr(i, (int)v2.size()) nums.pb(v2[i].second);
    fr(i, (int)v3.size()) nums.pb(v3[i].second);
    fr(i, (int)v4.size()) nums.pb(v4[i].second);

    stack <int> st;
    fr(i, (int)nums.size()) {
        if (st.size() == 0 || st.top() != nums[i])
            st.push(nums[i]);
        else
            st.pop();
    }

    if (st.size())
        cout << "NO";
    else
        cout << "YES";

}


Measured memory_bytes: 8552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();

            int ans = 0;
            int x = 0;
            for (int i = 0; x < n; i++) {
            	x = i * 1000;
            }
            
            ans = x - n;

            System.out.println(ans);

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}

Measured memory_bytes: 35684
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  const usize n = scan<usize>();
  usize count = 0_z;
  for (const auto i : rep(1_z, n + 1_z)) {
    if (scan<usize>() != i) {
      ++count;
    }
  }
  std::cout << (count <= 2_z ? "YES" : "NO") << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
A = [int(input()) for _ in range(n)]

import heapq

Q = [-a for a in A]
heapq.heapify(Q)

ans = []

for i in range(n):
    if -Q[0] == A[i]:
        tmp = heapq.heappop(Q)
        ans.append(-Q[0])
        heapq.heappush(Q, tmp)
    else:
        ans.append(-Q[0])

print(*ans)

Measured memory_bytes: 33536
#include <bits/stdc++.h>
    
#define int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define all(x) ((x).begin(), (x).end())
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(), (x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int srch(int n){
    if(n < 0) return INF;
    if(n == 0) return 0;

    int s = 1;
    while(s * 6 <= n){
        s *= 6;
    }

    int t = 1;
    while(t * 9 <= n){
        t *= 9;
    }

    return min(srch(n - s), srch(n - t)) + 1;
}

int32_t main(){
    int n;
    cin >> n;
    cout << srch(n) << endl;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    h, w = ns()
    mat = [list(input()) for _ in range(h)]
    dp = [[0 for _ in range(w)] for __ in range(h)]
    dp[0][0] = 1

    def calc(x, y, val):
        if x >= w or y >= h:
            return
        if mat[y][x] == "#":
            return
        dp[y][x] += val
        dp[y][x] %= MOD
        return

    for y in range(h):
        for x in range(w):
            calc(x + 1, y, dp[y][x])
            calc(x, y + 1, dp[y][x])
    print(dp[h - 1][w - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 58816
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	if((a<0&&b>0)||(a==0)||b==0)
	cout<<"Zero"<<endl;
	 else if((b-a+1)%2==0||(a>0)&&(b>0)) 
	cout<<"Positive"<<endl;
	else cout<<"Negative"<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
A =list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
total=0
i=0
for i in range(len(A)):
    total += B[A[i]-1]
    if i>0:
        if A[i]==A[i-1]+1:
            total += C[A[i]-2]
print(total)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  bool s=false;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(n==(i*j)){
        cout <<"Yes"<<endl;
        s=true;
        break;
      }
    }
    
    if(s){
      break;
    }
  }
  if(!s) {
    cout <<"No"<<endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    int min_x = 999, max_x = 0;
    int p, sum = 0, ans = 9999999;

    rep(i,n) min_x = min(min_x, x[i]);
    rep(i,n) max_x = max(max_x, x[i]);

    for(p=min_x; p<=max_x; p++){
        sum = 0;
        rep(i,n){
              sum += pow((x[i]-p),2.0);
        }
        if(sum < ans) ans = sum; 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

/*
#include <atcoder/all>
using namespace atcoder;
*/

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n + 1; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repr1(i, n) for (ll i = n; i > 0; i--)
#define FOR(i, j, n) for (ll i = j; i < n; i++)

const ll MOD = 1000000007; // 10^9+7
const ll MOD2 = 998244353;
const ll INF = 10000000000;

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i,n) cin >> a[i];

    deque<int> ans;
    rep(i,n){
        if(i % 2 == n % 2 ) ans.push_back(a[i]);
        else ans.push_front(a[i]);
    }

    rep(i,n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

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

eff = [list(map(int, input().split())) for _ in range(n)]

dp = [[float('-inf')] * 3 for _ in range(n)]

from copy import deepcopy

dp[0] = deepcopy(eff[0])

for i in range(1, n):
    for yi in range(3):
        for ti in range(3):
            if yi != ti:
                dp[i][ti] = max(dp[i][ti], dp[i-1][yi] + eff[i][ti])

print(max(dp[-1]))

Measured memory_bytes: 84824
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MX = 200005;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    rep(i,3) h.push_back(INF);
    int dp[MX];
    rep(i, n) dp[i] = INF;
    dp[0] = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<=k;++j){
            if(i-j>=0){
                dp[i] = min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


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

using namespace std;
typedef long long int lld;
#define MOD 1000000007
lld last[1000000];
int main(){
  int n;
  scanf("%d",&n);
  int arr[n];
  for(int i=0;i<n;i++)scanf("%d",&arr[i]);
  lld DP[n+1];
  DP[0]=1;
  DP[1]=1;
  for(int i=0;i<1000000;i++)last[i]=0;
  last[arr[0]]=1;
  for(int i=1;i<n;i++){
    if(arr[i]==arr[i-1]){
      DP[i+1]=DP[i];
    }else{
      DP[i+1]=DP[i]+last[arr[i]];
    }
    DP[i+1]%=MOD;
    last[arr[i]]=DP[i+1];
    //cout<<DP[i]<<endl;
  }
  printf("%lld\n",DP[n]);
  return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
        int x,y;
        Int(x,y);
        bool f=false;
        for(int i=0;i<=x;++i){
            int tot = i*2 + (x-i)*4;
            if(tot == y)f=true;
        }
        if(f)printf("Yes\n");
        else{
            printf("No\n");
        }

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3608
import java.awt.geom.*;
import java.io.*;
import java.util.*;

import javax.naming.BinaryRefAddr;

public class Main {
	//1958 cording
	int [] v = {200,300,500};
	int [] mv = {5,4,3};
	int [] v3 = {380, 550, 850};
	int [] v4 = {80, 85, 88};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] dp = new int[5001];
			int INF = 1 << 24;
			Arrays.fill(dp, INF);
			dp[0] = 0;
			for(int i = 0 ; i < n; i+= 100){
				for(int j = 0 ; j < 3; j++){
					int value = dp[i] + v3[j];
					int next = i + v[j];
					if(next > n) continue;
					dp[next] = Math.min(dp[next], value);
					value = dp[i] + (v3[j] * mv[j]) * v4[j] / 100;
					next = i + v[j] * mv[j];
					if(next > n) continue;
					dp[next] = Math.min(dp[next], value);
					
				}
			}
			System.out.println(dp[n]);
		}
	
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
    #include<math.h>
    main()
    {
    int a,b,f,k=0,i,x=0,y=0,z=0,count=0,n,w;
    scanf("%d %d %d",&n,&a,&b);
    for(i=1;i<=n;i++)
    {
    w=floor(i*1.000/10000);
    x=floor((i-(w*10000))*1.000/1000);
    y=floor((i-(x*1000)-(w*10000))*1.000/100);
    z=floor((i-(y*100)-(x*1000)-(w*10000))*1.000/10);
    k=floor(i-(y*100)-(z*10)-(x*1000)-(w*10000));
    f=x+y+z+k+w;
    if(f>=a&&f<=b)
    {
    count=count+i;
    }
     
     
    }
    printf("%d",count);
    }

Measured memory_bytes: 128
# coding: utf-8
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()
for i in range(n):
    if i % 2 == (n-1) % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(' '.join(map(str, b)))


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  int ans = 1000 - (n % 1000);
  if(ans == 1000) {
    ans = 0;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
s = input()
for _ in range(int(input())):
  q = input()
  if q.startswith('replace'):
    q, a, b, p = q.split()
    a = int(a)
    b = int(b)
    s = s[:a]+p+s[b+1:]
  elif q.startswith('reverse'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    s = s[:a]+s[a:b+1][::-1]+s[b+1:]
  elif q.startswith('print'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    print(s[a:b+1])

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
const int maxn =1e5+100;
char ax[maxn],bx[maxn];
vector<int> ac[30];
long long ans = 0;
int main(){
    scanf("%s",ax+1);
    scanf("%s",bx+1);
    int len1 = strlen(ax+1),len2 = strlen(bx+1);
    for(int i = 1;i<=len1;i++){
        ac[ax[i]-'a'].PB(i);
    }
    int nowpos = 0;
    for(int i = 1;i<=len2;i++){
        int now = bx[i] - 'a';
        if(ac[now].size()==0){
            printf("-1");
            return 0;
        }
        int k = ac[now].size()-1;
        if(nowpos>=ac[now][k]){
            ans+=len1-nowpos;
            nowpos=ac[now][0];
            ans+=nowpos;
            continue;
        }
        int pos = upper_bound(ac[now].begin(),ac[now].end(),nowpos) - ac[now].begin();
        ans+=ac[now][pos] - nowpos;
        nowpos = ac[now][pos];
    }
    printf("%lld\n",ans);
    return 0;
}
/*
abc
abc
*/


Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc167/tasks/abc167_d
# コンテスト中は周期性を用いたが、今回はdoublingで解いてみる

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def ints(): return list(map(int, read().split()))


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

N, K = ints()
A = mina(*ints())
# 10^18のは60bitで表せるのでnxt tableをつくるのに最大1.2 * 10^7 ぐらい。ギリ間に合いそう


nxt = [[-1] * N for _ in ra(K.bit_length())]  # [k][v]...vから2^k回移動したノード
# 初期化
for v, nx in enu(A):
    nxt[0][v] = nx

# テーブル埋め
for k in ra(K.bit_length() - 1):
    for v in ra(N):
        nxt[k + 1][v] = nxt[k][nxt[k][v]]

# 答えの取得
now = 0  # はじめは0地点にいる
for k in ra(K.bit_length()):
    if (K >> k) & 1:
        # kbit目が立ってたらこの回数分だけ移動
        now = nxt[k][now]
print(now + 1)


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


int main (){
    int n ;
    cin >> n ;
    vector<ll> a (n) ;
    rep(i, n){
        cin >> a[i] ;
    }
    sort(a.begin(), a.end()) ;
    reverse(a.begin(), a.end()) ;
    vector<ll> b ; 
    rep(i, n){
        if(i == 0){
            b.push_back(a[i]) ;
        }
        else {
            b.push_back(a[i]) ;
            b.push_back(a[i]) ;
        }
    } 
    ll ans = 0 ;
    rep(i, n - 1){
        ans += b[i] ;
    }
    cout << ans << endl ;
    return 0 ;
}

Measured memory_bytes: 9012
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#define pi 2*acos(-1)
typedef long long ll;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 5;
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
#define mod 10e9
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x,y;
    x=c;
    y=a;
    ll flag=0;
    while(1)
    {
        x-=b;
        if(x<=0)
        {
            flag=1;
            break;
        }
        y-=d;
        if(y<=0)
        {
            flag=2;
            break;
        }
    }
    if(flag==1)
    {
        cout<<"Yes";
    }
    else if(flag==2)
    {
        cout<<"No";
    }
}


Measured memory_bytes: 3568
import itertools
def f(s):
 for a,b,c,d in itertools.permutations(s):
  for x,y,z in itertools.product('+-*',repeat=3):
   yield f"({a} {x} {b}) {y} ({c} {z} {d})"
   yield f"(({a} {x} {b}) {y} {c}) {z} {d}"
   yield f"{a} {x} ({b} {y} ({c} {z} {d}))"
   yield f"({a} {x} ({b} {y} {c})) {z} {d}"
   yield f"{a} {x} (({b} {y} {c}) {z} {d})"
for e in iter(input,'0 0 0 0'):
 s=list(map(int,e.split()));a=0
 for m in f(s):
  if eval(m)==10:a='('+m+')';break
 print(a)


Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)

/*

各山に降った雨を2*x[i]とすると、
x[0]+x[1]=a[0]
x[1]+x[2]=a[1]
x[2]+x[3]=a[2]
...
x[n-2]+x[n-1]=a[n-2]
x[n-1]+x[0]=a[n-1]

例えば、n=5とする
x[0]+x[1]=a[0]
x[1]+x[2]=a[1]
x[2]+x[3]=a[2]
x[3]+x[4]=a[3]
x[4]+x[0]=a[4]
aの総和をSとすると、
x[0]=a[0]+a[2]+a[4]-S/2

一般に、
x[0]=a[0]+a[2]+...+a[n-1]-S/2
以降、各i=1~n-1について、
x[i]=a[i-1]-x[x-1]
*/

void solve(){
    int n;
    cin >> n;
    int a[n+10];
    rep(i,n){
        cin >> a[i];
    }
    int sum=0;
    rep(i,n){
        sum += a[i];
    }
    vector<int> x;
    int tmp=0;
    for(int i=0; i!=n+1; i += 2){
        tmp += a[i];
    }
    x.emplace_back(tmp - (sum)/2);
    for(int i=1; i<=n-1; i++){
        x.emplace_back(a[i-1]-x[i-1]);
    }
    x.emplace_back(a[n]-x[0]);

    rep(i,n){
        cout << 2 * x[i] << " ";
    }
    cout << endl;
}

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

Measured memory_bytes: 2168
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r)
{
  int x,i,j,t;
  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++)
  {
    if(A[j] <= x)
    {
      i = i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
 return i+1;
}

  int main()
  {
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
    q = partition(0,n-1);

    for(i=0;i<n;i++)
    {
      if(i)printf(" ");
      if(i==q)printf("[");
      printf("%d",A[i]);
      if(i==q)printf("]");
    }
    printf("\n");
    return 0;
  }



Measured memory_bytes: 2108
import java.util.Scanner;

//D - We Love ABC
public class Main {
    private static final long M = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        dp(s);
        sc.close();
    }

    public static void dp(String s) {
        long[][] dp = new long[s.length()][3];
        long a = 1;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == 'A' || ch == '?') {
                dp[i][0] = a;
            }
            if (ch == '?') a = (a * 3) % M;
        }
        a = dp[0][0];
        for (int i = 1; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == 'B' || ch == '?') {
                dp[i][1] = a;
            }
            if (ch == '?')
                a = (dp[i][0] + a * 3) % M;
            else
                a = (dp[i][0] + a) % M;
        }

        a = dp[1][1];
        for (int i = 2; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == 'C' || ch == '?') {
                dp[i][2] = a;
            }
            if (ch == '?')
                a = (dp[i][1] + a * 3) % M;
            else
                a = (dp[i][1] + a) % M;
        }
        long total = 0;
        a = 1;
        for (int i = s.length() - 1; i >= 2; i--) {
            char ch = s.charAt(i);
            if (dp[i][2] > 0)
                total = (total + dp[i][2] * a) % M;
            if (ch == '?') a = (a * 3) % M;
        }
        System.out.println(total);
    }

}


Measured memory_bytes: 31176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		int w = sc.nextInt();


		for(int i = 0; i < S.length(); i = i + w) {
		String ans = S.substring(i,i+1);

		System.out.print(ans);
		}
		sc.close();
	}

}

Measured memory_bytes: 23764
def get_divisors(x):
    i = 1
    ret = set()
    while i * i <= x:
        if x % i == 0:
            ret.add(i)
            ret.add(x // i)

        i += 1

    return ret


n, k = map(int, input().split())
a = list(map(int, input().split()))

sm = sum(a)
divs = get_divisors(sm)

ans = 0
for div in divs:
    mods = [e % div for e in a]
    mods.sort()
    p = 0
    m = n * div - sum(mods)
    for mod in mods:
        p += mod
        m -= div - mod
        if p == m:
            if p <= k:
                ans = max(ans, div)
            break

print(ans)


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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const ll N = (ll)1e5+7;
const ll inf = (ll) 1e17+7;
const ll mod = (ll) 998244353;
const ld pi = acos(-1);

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

ll n,m,k,x,y;
string a,b;
map<ll,char> mp;

int main() {
    fast;
    cin>>n>>m>>a>>b;
    k = n*m/gcd(n,m);
    for(ll i = 0,j=0;i<k;i+=k/n,j++) {
        mp[i] = a[j];
    }
    for(ll i=0,j=0;i<k;i+=k/m,j++){
        if(mp[i]){
            if(mp[i]!=b[j]){
                puts("-1");
                return  0;
            }
        }
    }
    cout<<k<<endl;
    return 0;
}


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

int main() { 
    long long int l, r, m, min = 3000, mod = 2019;
    cin >> l >> r;
    for(long long int i = l; i <= r; ++i) {
        for(long long int j = i+1; j <= r; ++j) {
            m = i*j%mod;
            if(m < min) min = m;
            if(min == 0) {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    cout << min << '\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;

int bubbleSort(int A[],int N){
  bool flag=1;
  int sw=0;

  for(int i=0;flag;i++){
    flag=0;
    for(int j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	sw++;
	flag=1;
      }
    }
  }
  return sw;
}

int main(void){
  int N,A[MAX];
  int sw=0;

  cin>>N;

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

  sw=bubbleSort(A,N);

  for(int i=0;i<N;i++){
    if(i)cout<<" ";
    cout<<A[i];
  }
  cout<<endl<<sw<<endl;

  return 0;
}
  

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  string a, b;
  cin >> a >> b;
  
  if(a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else if(a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  } else {
    for(int i = 0; i < a.size(); i++) {
      char s = a.at(i);
      char t = b.at(i);
      int x = (unsigned char)s;
      int y = (unsigned char)t;
      if(x > y) {
        cout << "GREATER" << endl;
        return 0;
      } else if(x < y) {
        cout << "LESS" << endl;
        return 0;
      } else {
        continue;
      }
    }
    cout << "EQUAL" << endl;
  }
}

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

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

    let exec_time = 100 * (n - m) + 1900 * m;

    let count = 2_usize.pow(m as u32);
    println!("{}", exec_time * count);
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

vvi G;
vi col;

void dfs(int k,int c,int p=-1) {
  col[k]=c;
  for(int q:G[k]) {
    if(q==p) continue;
    dfs(q,!c,k);
  }
}
  
int main() {
  int N;
  cin >> N;
  G = vvi(N);
  rep(i,N-1) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  col=vi(N);
  dfs(0,0);
  vvi m(3);
  rep(i,N) {
    m[(i+1)%3].push_back(i);
  }
  int rc=0;
  rep(i,N) {
    rc += col[i];
  }
  int bc = N-rc;
  vi ans(N,-1);
  if(rc*3<N) {
    rep(i,N) {
      if(!col[i]) continue;
      ans[i]=m[0].back();
      m[0].pop_back();
    }
    rep(i,N) {
      if(ans[i]>=0) continue;
      if(!m[0].empty()) {
        ans[i]=m[0].back();
        m[0].pop_back();
      } else if(!m[1].empty()) {
        ans[i]=m[1].back();
        m[1].pop_back();
      } else {
        ans[i]=m[2].back();
        m[2].pop_back();
      }
    }
  } else if(bc*3<N) {
    rep(i,N) {
      if(col[i]) continue;
      ans[i]=m[0].back();
      m[0].pop_back();
    }
    rep(i,N) {
      if(ans[i]>=0) continue;
      if(!m[0].empty()) {
        ans[i]=m[0].back();
        m[0].pop_back();
      } else if(!m[1].empty()) {
        ans[i]=m[1].back();
        m[1].pop_back();
      } else {
        ans[i]=m[2].back();
        m[2].pop_back();
      }
    }
  } else {
    rep(i,N) {
      if(!col[i]) continue;
      if(!m[1].empty()) {
        ans[i]=m[1].back();
        m[1].pop_back();
      } else {
        ans[i]=m[0].back();
        m[0].pop_back();
      }
    }
    rep(i,N) {
      if(col[i]) continue;
      if(!m[2].empty()) {
        ans[i]=m[2].back();
        m[2].pop_back();
      } else {
        ans[i]=m[0].back();
        m[0].pop_back();
      }
    }
  }
  rep(i,N) {
    cout << ans[i]+1 << " ";
  }
  cout << endl;
  return 0;
}

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

struct Node{
  int key;
  struct Node *p;
  struct Node *l;
  struct Node *r;
};
typedef struct Node * Nodepointer;

Nodepointer root,nil;

void insert(int i){
  Nodepointer x = root;
  Nodepointer y = nil; /*parent*/
  Nodepointer z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = i;
  z->l = nil;
  z->r = nil;

  while(x != nil){
    y = x;
    if(x->key > z->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == nil) root = z;
  else{
    if(y->key > z->key) y->l = z;
    else y->r = z;
  }

}

void inorder(Nodepointer x){
    if(x == nil) return;
    inorder(x->l);
    printf(" %d",x->key);
    inorder(x->r);
}

void preorder(Nodepointer x){
    if(x == nil) return;
    printf(" %d",x->key);
    preorder(x->l);
    preorder(x->r);
}

Nodepointer find(Nodepointer x,int i){
  while(x != nil && i != x->key){
    if(x->key > i) x = x->l;
    else x = x->r;
  }
  return x;
}

int main(){
  int n,i,num;
  char c[20];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",&c);
    if(c[0] == 'i'){
      scanf("%d",&num);
      insert(num);
    }
    else if(c[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(c[0] == 'f'){
      scanf("%d",&num);
      if(find(root,num) != nil) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}




Measured memory_bytes: 20612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  string S[3];
  cin >> S[0] >> S[1] >> S[2];
  int i[3] = {0, 0, 0};
  int s[3] = {S[0].size(), S[1].size(), S[2].size()};
  int t = 0;
  while(true) {
    if(i[t] >= s[t]) { cout << char('A' + t) << endl; break; }
    else t = S[t][i[t]++] - 'a';
  }
  return 0;
}



Measured memory_bytes: 256
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

def dfs(e,s,d,tr)
	stack = [] # stack
	# init
	d[s]=0
	tr[s]=s
	e[s].each{|v|
		nxtv = v[0]
		nxtd = v[1]
		nxtp = 0
		# for multiple edge
		if(d[nxtv].nil?)
			stack.push([nxtv,nxtp,nxtd])
		else
			return false if d[nxtv] != nxtd
		end
	}
	while(!stack.empty?)
		# p stack
		curv,curp,curd = stack.pop
		d[curv]=curd
		tr[curv]=curp
		# dputs "(curv,curp,curd) = (#{curv},#{curp},#{curd})"
		e[curv].each{|v|
			nxtv = v[0]
			nxtp = curv
			nxtd = curd + v[1]
			next if nxtv == curp
			# dputs "(nxtv,nxtp,nxtd) = (#{nxtv},#{nxtp},#{nxtd})"
			if(d[nxtv].nil?)
				stack.push([nxtv,nxtp,nxtd])
			else
				return false if d[nxtv] != nxtd
			end
			}
	end
	return true
end

N,M=gets.chomp.split(' ').map{|n| n.to_i}
E = Array.new(N){[]}
1.upto(M){
	p=gets.chomp.split(' ').map{|n| n.to_i}
	p[0]-=1
	p[1]-=1
	E[p[0]].push([p[1],p[2]])
	E[p[1]].push([p[0],-p[2]])
}

d = Array.new(E.size){nil}
tr = Array.new(E.size){nil}
for i in 0..(E.size-1)
	if(d[i].nil?)
		flg = dfs(E,i,d,tr)
		if(!flg)
			puts "No"
			exit(0)
		end
	end
end
puts "Yes"


Measured memory_bytes: 55548
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
        int team;
	int z;
	int q = scan.nextInt();
	for(int i=1;i<=q;i++){
	    team = 0;
	    z = 0;
	    int c = scan.nextInt();
	    int a = scan.nextInt();
	    int n = scan.nextInt();
	    while(true){
		if(z == 1) break;
		if(c >= 1  && a >= 1 && n >= 1){
		    team = team +1;
		    c = c - 1;
		    a = a - 1;
		    n = n - 1;
		}else if(c >= 2 && a >= 1){
		    team = team + 1;
		    c = c - 2;
		    a = a - 1;
		}else if(c >= 3){
		    team = team + 1;
		    c = c -3;
		}else{
		    z = z + 1;
		}
	    }
	    System.out.println(team);
	    c = 0; a = 0; n = 0;
	}
    }
}

Measured memory_bytes: 20820
x,y = map(int,input().split())
ans = 0
if abs(y) > abs(x):
  if x < 0:ans += 1
  if y < 0:ans += 1
  ans += (abs(y)-abs(x))
else:
  if x > 0:ans += 1
  if y > 0:ans += 1
  ans += (abs(x)-abs(y))
print(ans)

Measured memory_bytes: 3064