akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  priority_queue<ll> q;
  for(int i=0;i<N;i++){
    ll a;
    cin >> a;
    q.push(a);
  }

  /*while(!q.empty()){
    cout << q.top() << " ";
    q.pop();
  }
  cout << endl;*/

  pair<ll, ll> p[M];
  for(int i=0;i<M;i++){
    ll b,c;
    cin >> b >> c;
    p[i].first = c;
    p[i].second = b;
  }

  sort(p, p+M);
  reverse(p, p+M);
  priority_queue<ll, vector<ll>, greater<ll> > queue;
  int cnt = 0;
  for(int i=0;i<M;i++){
    if(p[i].second + cnt <= N){
      for(int j=0;j<p[i].second;j++) queue.push(p[i].first);
      cnt += p[i].second;
    }
    else if(cnt >= N) break;
    else{
      for(int j=0; j < N - cnt; j++){
        queue.push(p[i].first);
      }
      break;
    }
  }
  //cout << queue.size();
  int sz = queue.size();
  if(sz < N){
    for(int i=0;i<N - sz;i++) queue.push(-1);
  }

  /*while(!queue.empty()){
    cout << queue.top() << " ";
    queue.pop();
  }
  cout << endl;*/

  for(int i=0;i<N;i++){
    ll a = q.top();
    q.pop();
    ll b = queue.top();
    queue.pop();

    if(a > b){
      queue.push(a);
    }
    else{
      queue.push(b);
      break;
    }
  }

  ll ans = 0LL;
  for(int i=0;i<N;i++){
    int b = queue.top();
    queue.pop();
    //cout << b << endl;
    ans += b;
  }

  cout << ans << endl;
  return 0;



}


Measured memory_bytes: 4084
program main
implicit none
integer :: i, j, k
integer :: n
integer , allocatable :: a(:), b(:)

read(*,*) n
allocate( a(n), b(n) )
do i = 1, n
   read(*,*) a(i)
   b(i) = a(i)
end do
call heapsort( n, b )
do i = 1, n
   if( a(i) /= b(n) ) then
      write(*,'(i0)') b(n)
   else
      write(*,'(i0)') b(n-1)
   end if
end do

stop
contains
subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  integer :: t

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        end if
     end if
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        end if
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        end if
     end do
     array(i)=t
  end do
end subroutine heapsort
end program main


Measured memory_bytes: 3200
#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(){
	int h, n;
	cin >> h >> n;
	vector<int> ar(h, 1000000000);
	rep(i, n){
		int a, b;
		cin >> a >> b;
		rep(j, h){
			ar.at(j) = min(ar.at(j), (j/a+1)*b);
			if(j >= a) ar.at(j) = min(ar.at(j), ar.at(j-a) + b);
		}
	}
	cout << ar.at(h-1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int d, t, s;
	cin >> d >> t >> s;
	int x = s * t;
	if (d <= x) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

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

    int N;
    cin >> N;
    string result = "No";

    for(int i=1;i<10;i++){
        for(int j=i;j<10;j++){
            if(N == i*j){
                result = "Yes";
                break;
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc178
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc178A();
            Console.Out.Flush();
        }

        public static void solve_abc178B()
        {

        }

        public static void solve_abc178A()
        {
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(x == 0 ? 1 : 0);
        }
    }
}

Measured memory_bytes: 28472
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break

    if m ==-1 or f == -1:
        print("F")

    elif m+f >= 80:
        print("A")

    elif 80 > m+f >= 65:
        print("B")

    elif 65 > m+f >= 50:
        print("C")

    elif 50 > m+f >=30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std;

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
inline int getint(){int w=0,q=0; char c=getchar(); while((c<'0'|c>'9') && c!='-') c=getchar();if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;}

int n,a[100100];

int main()
{
    scanf("%d",&n);int ret=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",a+i);
        if(a[i]&1) ret++;
    }
    if(ret%2==0) puts("YES");else puts("NO");
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] s = { { 0, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 1, 1, 0 }, { 1, 0, 1, 1, 0, 1, 1 },
                { 1, 0, 0, 1, 1, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 1 },
                { 1, 1, 1, 1, 1, 0, 1 }, { 0, 1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 0, 1, 1, 1, 1 } };
        for (;;) {
            int n = sc.nextInt();
            int[] a = new int[7];
            if (n == -1) {
                break;
            }
            while (n-- > 0) {
                int m = sc.nextInt();
                for (int i = 0; i < 7; i++) {
                    System.out.print((a[i] ^ s[m][i]) + (i == 6? "\n" : ""));
                }
                a = s[m].clone();
            }
        }
    }
}


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

const long long MOD = 1000000007;

long long f[4005], fi[4005];

long long mod_pow(long long x, long long n, long long mod = 1000000007){
    long long res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

void init(int n){
    f[0] = 1;
    for(int i = 1; i <= n; i++){
        f[i] = f[i-1] * i % MOD;
    }
    fi[n] = mod_pow(f[n], MOD-2);
    for(int i = n; i > 0; i--){
        fi[i-1] = fi[i] * i % MOD;
    }
}

long long comb(int r, int c){
    if(r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r-c] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    init(n*2);
    for(int i = 1; i <= k; i++){
        int x = k-i;
        int y = n-k-(i-1);
        if(y < 0){
            cout << 0 << endl;
            continue;
        }
        cout << comb(y+i, i) * comb(x+i-1, i-1) % MOD << endl;
    }
    return 0;
}

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

int main()
{
    int N;
    int A[100000] = {0};
    int use[100000] = {0};

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

    for (int i = 0; i < N; i++)
    {
        if (N % 2 == 1)
        {
            if (i == 0 && use[i] != 1)
            {
                cout << 0 << endl;
                return 0;
            }
            else if (i != 0 && i % 2 == 0 && use[i] != 2)
            {
                cout << 0 << endl;
                return 0;
            }
            else if (i % 2 == 1 && use[i] != 0)
            {
                cout << 0 << endl;
                return 0;
            }
        }
        else
        {
            if (i % 2 == 0 && use[i] != 0)
            {
                cout << 0 << endl;
                return 0;
            }
            else if (i % 2 == 1 && use[i] != 2)
            {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    long long ans = 1LL;
    long long mod = 1e9 + 7;
    for (int i = 0; i < N / 2; i++)
    {
        ans *= 2;
        if (ans > mod)
        {
            ans %= mod;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define MAXN 5010
int dist[MAXN], n;
vector<ii> adjList[MAXN];
bool infinite;
int INF = 1e9;
int pred[MAXN];

int bellm(int s, int t){
	for(int i=0; i<MAXN; ++i){
		dist[i] = INF;
		pred[i] = -1;
	}
	dist[s] = 0;
	pred[s] = s;
	infinite = false;
	for(int i=0, v, w; i<n; ++i){
		for(int u=0; u<n; ++u){
			for(auto _x:adjList[u]){
				v = _x.ff;
				w = _x.ss;
				if(i==n-1 and dist[v]>dist[u]+w)
					infinite = true;
				else{
					dist[v] = min(dist[v], dist[u]+w);
					pred[v] = u;
				}
			}
		}
	}
	return dist[t];
}
set<int> canH[MAXN];
int main(){
	int m, p;
	scanf("%d %d %d", &n, &m, &p);
	for(int i=0; i<m; ++i){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		adjList[a-1].push_back(ii(b-1, p-c));
	}

	for(int i=0; i<n; ++i){
		canH[i].insert(i);
		queue<int> q;
		q.push(i);
		while(not q.empty()){
			int u = q.front(); q.pop();
			for(auto _x:adjList[u]){
				int v = _x.ff;
				if(v<i){
					canH[i].insert(canH[v].begin(), canH[v].end());
				}
				else if(canH[i].find(v)==canH[i].end()){
					canH[i].insert(v);
					q.push(v);
				}
			}

		}
	}
	set<int> ed;
	for(auto u:canH[0]){
		if(canH[u].find(n-1)!=canH[u].end())
			ed.insert(u);
	}
	for(int i=0; i<n; ++i){
		if(ed.find(i)==ed.end())
			adjList[i].clear();
	}
	int ans = max(0, -bellm(0, n-1));
	if(infinite)
		printf("-1\n");
	else
		printf("%d\n", ans);
}


Measured memory_bytes: 293888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

int n, m;
Graph g;
int color[100010];

bool dfs(int v, int c) {
    color[v] = c;
    bool res = true;
    for(auto &e : g[v]){
        if(color[e.dst] == -c) continue;
        if(color[e.dst] == c) res = false;
        if(color[e.dst] == 0) if(!dfs(e.dst, -c)) res = false;
    }
    return res;
}

signed main(){
    while(cin >> n >> m){
        memset(color, 0, sizeof color);
        g.assign(n, {});
        rep(i, m){
            int a, b;
            cin >> a >> b;
            --a; --b;
            add_edge(g, a, b);
        }
        int a = 0, b = 0, c = 0;
        rep(i, n){
            if(color[i]) continue;
            if(g[i].size() == 0){
                ++a;
            } else {
                if(dfs(i, 1)) ++b; else ++c;
            }
        }
        dump(a, b, c);
        int ans = 0;
        ans += a*a;
        ans += 2*a*(n-a);
        ans += (b+c)*(b+c);
        ans += b*b;
        cout << ans << endl;
    }
}


Measured memory_bytes: 25984
#include <iostream>
using namespace std;
#define MAX 250

int main() {
    int n;
    int x;
    int H[MAX];

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

    for(int i=0; i<n; i++) {
        cout << "node " << i+1 << ": ";
        cout << "key = " << H[i] << ", ";
        //親が存在するかを判定
        if(i>0) {
            cout << "parent key = " << H[((i+1)/2-1)] << ", ";
        }
        if((2*(i+1))<=n) {
            cout << "left key = " << H[2*(i+1)-1] << ", ";
        }
        if((2*(i+1)+1)<=n) {
            cout << "right key = " << H[2*(i+1)] << ", ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3064
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=LI()
    p=aa[0]
    q=aa[1]
    j=1
    dl=abs(p-q)
    k=3
    r=aa[2]
    s=sum(aa[3:])
    dr=abs(r-s)
    while abs(r-s+aa[k]*2)<dr:
        r+=aa[k]
        s-=aa[k]
        dr=abs(r-s)
        k+=1
    ans=max(p,q,r,s)-min(p,q,r,s)
    for i in range(3,n-1):
        q += aa[i - 1]
        dl = abs(p - q)
        while abs(p - q + aa[j] * 2) < dl:
            p += aa[j]
            q -= aa[j]
            dl = abs(p - q)
            j += 1

        r -= aa[i - 1]
        dr = abs(r - s)
        while abs(r-s+aa[k]*2)<dr:
            r+=aa[k]
            s-=aa[k]
            dr=abs(r-s)
            k+=1
        cur=max(p,q,r,s)-min(p,q,r,s)
        if cur<ans:ans=cur
    print(ans)

main()

Measured memory_bytes: 24556
using System;
using System.Linq;

namespace AtCoderMake.ABC170
{
    class ABC170B
    {
        static void Main(string[] args)
        {
            var na = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();

            if (na[0] * 2 <= na[1] &&na[0]*4>=na[1]&&na[1]%2==0)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 28304
import java.io.*;
import java.util.*;

public class Main {

    public void solve() throws IOException {
        int n = nextInt();
        int cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < n; i++) {
            int x = nextInt();
            if(x % 4 == 0){
                cnt1++;
            }else if(x % 4 != 2){
                cnt2++;
            }
        }
        if(cnt1 >= cnt2 || (cnt2 == cnt1 + 1 && cnt1 + cnt2 == n)){
            out.print("Yes");
        }else{
            out.print("No");
        }
    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("sum2.in"));
//            out = new PrintWriter(new File("sum2.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}

Measured memory_bytes: 36480
function Main(input) {
  var inputs = input.split("\n");
  var result = 0;

  for (var fivehundred = 0; fivehundred <= inputs[0]; fivehundred++) {
    for (var onehundred = 0; onehundred <= inputs[1]; onehundred++) {
      for (var fifty = 0; fifty <= inputs[2]; fifty++) {
        if (500 * fivehundred + 100 * onehundred + 50 * fifty == inputs[3]) result++;
      }
    }
  }

  console.log(result);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 100001;
vector<int> d[N],r[N];

int main()
{
    int n,m;
    cin >>n >>m;
    vector<int> a(n);
    rep(i,n)
    {
        cin >>a[i];
        --a[i];
    }

    ll ans = 0;
    int dec = 0;

    rep(i,n-1)
    {
        int D = a[i+1]-a[i];
        if(D<0) D = a[i+1]+m-a[i];

        if(D>1)
        {
            // dbg(a[i+1]);
            r[a[i+1]].pb(i);

            int idx = a[i+1] - D+2;
            if(idx<0) idx += m;
            // printf(" D %d idx %d\n", D,idx);

            d[idx].pb(i);
            if(idx==0 || idx>a[i+1]) ++dec;
        }

        ans += min(D,1+a[i+1]);
    }
    // dbg(ans);

    ll t = ans;

    for(const auto v:r[0])
    {
        int D = a[v+1]-a[v];
        if(D<0) D = a[v+1]+m-a[v];

        --dec;
        // dbg(D);
        t += D-1;
    }

    for(int x=1; x<m; ++x)
    {
        for(const auto &v:d[x]) ++dec;

        t -= dec;
        ans = min(ans,t);

        // printf(" x %d: dec = %d, t %lld\n", x,dec,t);

        for(const auto v:r[x])
        {
            int D = a[v+1]-a[v];
            if(D<0) D = a[v+1]+m-a[v];

            --dec;
            // dbg(D);
            t += D-1;
        }
    }

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


Measured memory_bytes: 9984
from sys import stderr
import json

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))

ab_roads_fromto = [map(int, input().split()) for _ in range(m_roads_num)]


class ObservatoryController():
    observatories_by_id = {}

    def add(self, a_observatory):
        self.observatories_by_id[a_observatory.id] = a_observatory

    def connect_by_id(self, a_id, b_id):
        observatory_a = self.observatories_by_id[a_id]
        observatory_b = self.observatories_by_id[b_id]

        observatory_a.connect_to(observatory_b)
        observatory_b.connect_to(observatory_a)

    
    def count_good_observatories(self):
        result = 0
        for id, a_observaotry in self.observatories_by_id.items():
            if a_observaotry.is_good():
                result += 1
        return result


class Observatory():
    def __init__(self, id, height):
        self.id = id
        self.height = height
        self.connected_to_by_id = {}

    def __repr__(self):
        construct = json.dumps({
            'id': self.id,
            'height': self.height,
        })
        return "<Observatory '%s'>" % (construct)

    def connect_to(self, a_observaotry):
        self.connected_to_by_id[a_observaotry.id] = a_observaotry

    def is_good(self):
        for a_connected_observatory in self.connected_to_by_id.values():
            if self.height <= a_connected_observatory.height:
                return False
        return True

observatoryController = ObservatoryController()

for i, height in enumerate(hi_heights):
    id = i + 1
    observatory = Observatory(id, height)
    observatoryController.add(observatory)

for a, b in ab_roads_fromto:
    observatoryController.connect_by_id(a, b)

result = observatoryController.count_good_observatories()

print(result)


Measured memory_bytes: 92940
#include<stdio.h>
main(){
  int i,j,hmax,wmax,sumsum=0;
  int a[100][100],sum[100]={};
  scanf("%d%d",&hmax,&wmax);
  for(i=0;i<hmax;i++){
    for(j=0;j<wmax;j++){
      scanf("%d",&a[i][j]);
      sum[i]+=a[i][j];
    }
  }
  for(i=0;i<hmax;i++){
    for(j=0;j<wmax;j++){
      printf("%d ",a[i][j]);
    }
    sumsum+=sum[i];
    printf("%d\n",sum[i]);
  }
  for(j=0;j<wmax;j++){
    sum[j]=0;
    for(i=0;i<hmax;i++){
      sum[j]+=a[i][j];
    }
    printf("%d ",sum[j]);
  }
  printf("%d\n",sumsum);
  return 0;
}

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

int main() {
    long long x;
    cin >> x;

    long long temp = 100;
    int cnt = 0;

    while (x > temp) {
        temp += (long long)(temp * 0.01);
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), t = 0;
		while (n-->0) {
			int a = sc.nextInt(), b = sc.nextInt();
			if (a==b) t++; else t=0;
			if (t==3) break;
		}
		System.out.println(t==3 ? "Yes" : "No");
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35812
import itertools

n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i, j, k in itertools.combinations(L, 3):
    if i == j or j == k or i == k:
        continue
    if i + j > k and j + k > i and k + i > j:
        cnt += 1
print(cnt)

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

#define F(i, a, b) for (int i = a; i <= b; i ++)
#define G(i, a, b) for (int i = a; i >= b; i --)
#define out4(x, y, z, w) { if (debug) printf(#x" = "),W(x),printf(" "#y" = "),W(y),printf(" "#z" = "),W(z),printf(" "#w" = "),W(w),putc('\n'); }
#define out3(x, y, z) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), printf(" "#z" = "), W(z), putc('\n'); }
#define out2(x, y) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), putc('\n'); }
#define out1(x) { if (debug) printf(#x" = "), W(x), putc('\n'); }
#define outline(x) { if (debug) puts("-------------------------------------------"#x"----------------------------------------"); }
#define outarr(a, L, R) { if (debug) { printf(#a"[%d..%d] = ", L, R); F(i, L, R) W(a[i]), putc(' '); putc('\n'); } }
#define Assert(x) { if ((debug) && (!(x))) { puts("Wrong Answer"); exit(0); } }
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define lowbit(x) ((x) & (-(x)))
#define abs(x) ((max(x, - (x))))
#define get getchar()
#define pb push_back
#define putc putchar
#define inf 2e9

template <typename Int>
void R(Int &x) {
	char c = get; x = 0; Int t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void W(Int x) {
	if (x < 0) { putc('-'); x = - x ; }
	if (x > 9) W(x / 10); putc(x % 10 + '0');
}

#define debug (1)

using namespace std;

const int mo = 1e9 + 7;
const int N = 5e5 + 10;
char ch[N]; int a[N], f[N], s[N];

void add(int &x, int y) { x = (x + y) % mo; }

int main() {
//	freopen("data.in", "r", stdin);

	scanf("%s", ch + 1);
	int n = strlen(ch + 1);
	F(i, 1, n) a[i] = ch[i] - 'a' + 1, s[i] = s[i - 1] + a[i];
	int sum = 0;
	F(i, 1, n - 1) sum += a[i] == a[i + 1];
	if (!sum) {
		puts("1");
		return 0;
	}
	int Ans = 0, top = 1, bz = 0;
	f[0] = 1;
	F(i, 0, n - 1) {
		add(f[i + 1], f[i]);
		int v = 3 - a[i + 1];
		if (top <= i + 1) bz = 0;
		while (!bz && top < n)
			bz = a[top] == a[top + 1], top ++;
		if (bz) {
			F(j, top, n)
				if ((s[j] - s[i]) % 3 == v) {
					add(f[j], f[i]);
					break;
				}
		}
		if ((s[n] - s[i + 1]) % 3 == 0)
			add(Ans, f[i + 1]);
	}

	W(Ans);
}

Measured memory_bytes: 5032
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=ja

# ダイクストラ
from heapq import heappush, heappop


class PriorityQueue:
    def __init__(self):
        self._queue = []

    def push(self, value):
        heappush(self._queue, value)

    def pop(self):
        return heappop(self._queue)

    @property
    def empty(self):
        return not self._queue

    def __len__(self):
        return len(self._queue)

    def __contains__(self, item):
        return item in self._queue


V, E, R = map(int, input().split())
edge = [[] for _ in range(V)]
for _ in range(E):
    f, t, d = map(int, input().split())
    edge[f].append((d, t))

queue = PriorityQueue()
queue.push((0, R))
visited = [float('inf')] * V
visited[R] = 0

while True:
    d, v = queue.pop()
    dist = visited[v]
    for e in edge[v]:
        if (e[0] + dist) < visited[e[1]]:
            visited[e[1]] = e[0] + dist
            queue.push((e[0] + dist, e[1]))

    if queue.empty:
        break
        
for i in visited:
    if i == float('inf'):
        print('INF')
    else:
        print(i)



Measured memory_bytes: 90452
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

string s;
int dp[200010][3];

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> s;
    if (s.size() == 1) {
        cout << 1 << endl;
        return 0;
    }
    MINUS(dp);
    dp[0][1] = dp[0][2] = 1;
    REP(i, s.size()) {
        FOR(j, 1, 3) if (i + j <= s.size() && dp[i][j] < INF) {
            string last = s.substr(i, j);
            FOR(k, 1, 3) if (i + j + k <= s.size()) {
                string newLast = s.substr(i + j, k);
                if (newLast != last) {
                    CHMAX(dp[i + j][k], dp[i][j] + 1);
                }
            }
        }
    }
    cout << max(dp[s.size() - 2][2], dp[s.size() - 1][1]) << endl;

    return 0;
}

Measured memory_bytes: 5268
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(a+b==c+d)
    cout<<"Balanced"<<endl;
  else if(a+b<c+d)
    cout<<"Right"<<endl;
  else
    cout<<"Left"<<endl;
return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
di = defaultdict(list)

for n in range(1, N + 1):
    S, P = input().split()
    P = int(P)
    di[S].append({n: P})

li = sorted(di.items(), key=lambda x: x[0])

di2 = {}

for tu in li:
    for mini_dict in tu[1]:
        for k, v in mini_dict.items():
            di2[k] = v
    sorted_di2 = sorted(di2.items(), key=lambda x: x[1], reverse=True)
    for tup2 in sorted_di2:
        print(tup2[0])

    sorted_di2 = []
    di2 = {}


Measured memory_bytes: 3316
<?php
fscanf(STDIN, "%d", $num);
$sum = 0;
for ($i = 0; $i < $num; $i++) {
    $otoshidama = trim(fgets(STDIN));
    $otoshidama_arr = explode(" ", $otoshidama);
    if ($otoshidama_arr[1] == "BTC") {
        $sum += $otoshidama_arr[0]*380000;
    } else {
        $sum += $otoshidama_arr[0];
    }
}

echo $sum;
?>

Measured memory_bytes: 3576
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
void failed()
{
	printf("-1\n");
	exit(0);
}
void add(int x,int y)
{
	printf("%d %d\n",x,y);
}
char s[1000010];
int n;
int main()
{
	open2("e");
	scanf("%s",s+1);
	n=strlen(s+1);
	if(s[1]=='0'||s[n]=='1')
		failed();
	for(int i=1;i<=n-i;i++)
		if(s[i]!=s[n-i])
			failed();
	int last=1;
	for(int i=2;i<=n-1;i++)
		if(s[i]=='1')
		{
			add(last,i);
			for(int j=last+1;j<i;j++)
				add(j,i);
			last=i;
		}
	add(n-1,n);
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int dp[5003][5003];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));
    
    set<int> s;
    rep(i, n) s.insert(v[i]);
    
    map<int, int> mp;
    rep(i, n) mp[v[i]] = i; // v[i]は1通り
    
    
    fill_n(*dp, 5003 * 5003, 2);
    int ans = 2;
    
    rep(j, n) rep3(i, j + 1, n) {
        if (s.find(2 * v[i] - v[j]) != s.end()) {
            int k = mp[2 * v[i] - v[j]];
            chmax(dp[k][i], dp[i][j] + 1);
            chmax(ans, dp[k][i]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 101424
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
  vector<pair<long long, long long> > res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) { ++num; n /= p; }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

ll g(ll x, ll N, vector<ll> &A) {
  ll ans = 1;
  for(ll i=1; i*i<=x; i++) {
    if(x%i==0) {
      ll cnt=0;
      bool f = true;
      for(ll j=0; j<N; j++) {
	if(A[j]%i!=0) {
	  if(cnt==0) {
	    cnt++;
	  } else {
	    f = false;
	    break;
	  }
	}
      }
      if(f)
	ans = max(ans, i);
      cnt = 0;
      f = true;
      for(ll j=0; j<N; j++) {
	if(A[j]%(x/i)!=0) {
	  if(cnt==0)
	    cnt++;
	  else {
	    f = false;
	    break;
	  }
	}
      }
      if(f)
	ans = max(ans, x/i);
    }
  }
  return ans;
}


void solve(long long N, std::vector<long long> A){
  sort(A.begin(), A.end());
  std::cout << max(g(A[0], N, A), g(A[1], N, A)) << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}



Measured memory_bytes: 1024
S = gets.chomp.split("").map(&:to_s)
if ((S[0]+S[1]).to_i <= 12)  && ((S[0]+S[1]).to_i >= 1)
    if ((S[2]+S[3]).to_i <= 12) && ((S[2]+S[3]).to_i >= 1)
        puts "AMBIGUOUS"
    else
        puts "MMYY"
    end
else
    if ((S[2]+S[3]).to_i <= 12) && ((S[2]+S[3]).to_i >= 1)
        puts "YYMM"
    else
        puts "NA"
    end
end


Measured memory_bytes: 1788
import sys
input = sys.stdin.readline

MOD = 10**9 + 7
N = int(input())

dp = [0] * (N+10)
dp_cum = [0] * (N+10)

dp[1] = N-1; dp_cum[1] = N-1
dp[2] = N-1; dp_cum[2] = 2*(N-1)
for n in range(3,N+1):
    dp[n] = dp[n-1] + dp_cum[n-3]
    dp_cum[n] = (dp_cum[n-1] + dp[n]) % MOD

answer = sum(dp[1:N])*N + dp[N] + 1
answer %= MOD
print(answer)

Measured memory_bytes: 97808
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e5;
int d[61][31][2];

int main() {
    int w, h;
    while (cin >> w >> h && w){
        VVI a(h, VI(w));
        VI sx, sy, gx, gy;
        REP(i,h) REP(j,w) {
            char x;
            cin >> x;
            if (x == 'X') a[i][j] = -1;
            else if (x == 'S'){
                sx.push_back(i);
                sy.push_back(j);
            }else if (x == 'T'){
                gx.push_back(i);
                gy.push_back(j);
            }else{
                a[i][j] = x - '0';
            }
        }
        REP(i,h) REP(j,w) REP(k,2) d[i][j][k] = INF;
        priority_queue<pair<P,P>, vector<pair<P,P> >, greater<pair<P,P> > > q;
        REP(i,sx.size()) REP(k,2) {
            d[sx[i]][sy[i]][k] = 0;
            q.push(make_pair(P(0,k), P(sx[i],sy[i])));
        }
        while (!q.empty()){
            pair<P,P> pp = q.top();
            q.pop();
            int i = pp.second.first, j = pp.second.second;
            int f = pp.first.second;
            if(d[i][j][f] < pp.first.first) continue;
            FOR(dj,1,3) FOR(di,-3+dj,3-dj){
                int ii = i + di, jj = j;
                if (f == 0) jj += dj;
                else jj -= dj;
                if (ii < 0 || jj < 0 || ii >= h || jj >= w || a[ii][jj] == -1) continue;
                if (d[ii][jj][f^1] > d[i][j][f] + a[ii][jj]){
                    d[ii][jj][f^1] = d[i][j][f] + a[ii][jj];
                    q.push(make_pair(P(d[ii][jj][f^1],f^1), P(ii,jj)));
                }
            }
        }
        int ans = INF;
        REP(i,gx.size()) REP(k,2){
            ans = min(ans, d[gx[i]][gy[i]][k]);
        }
        cout << (ans == INF ? -1 : ans) << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  
  long long n, k, t;
  cin >> n >> k;
  t = n % k;
  t = min(t, abs(t - k));
  
  cout << t << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

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

int main(){
  ll n,k; cin >> n >> k;
  ll ans=min(n%k,k-n%k);
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

void test_case(){
	long double a,b;
	cin >> a >> b;
	cout << (ll)( a*b + 0.001 ) << endl;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	// cin >> t;

	while(t--) test_case();
	
	return 0;
}



Measured memory_bytes: 3808
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int h[3][100000];

ll dp[3][100000];

void solve(){
	rep(i,3)
		dp[i][0] = h[i][0];
	reps(i,N-1){
		rep(j,3){
			dp[j][i]=max(dp[(j+1)%3][i-1],dp[(j+2)%3][i-1])+h[j][i];
		}
	}
	ll ans = 0;
	rep(i,3)
		chmax(ans, dp[i][N - 1]);
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N) {
		cin>>h[0][i]>>h[1][i]>>h[2][i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 3840
n,m=map(int,input().split())
a_list=list(map(int,input().split()))
ref=[0,2,5,5,4,5,6,3,7,6]
num=[0,0,0,0,0,0]
for i in a_list:
    if i>num[ref[i]-2]:
        num[ref[i]-2]=i
num_s=[]
for i in range(6):
    num_s.append([num[i],i])
num_s.sort(reverse=True)
temp=[0,0,0,0,0,0]
dp=[[0,0,0,0,0,0]]
for i in range(n):
    sub_list=[-1,-1,-1,-1,-1,-1]
    dp.append(sub_list)
for i in range(1,n+1):
    for j in range(6):
        if i-(j+2)>=0 and not num[j]==0:
            if dp[i-j-2][0]>=0:
                if sum(dp[i-j-2])+1>sum(dp[i]):
                    for k in range(6):
                        dp[i][k]=dp[i-j-2][k]
                    dp[i][j]=dp[i][j]+1
                elif sum(dp[i-j-2])+1==sum(dp[i]):
                    for h in range(6):
                        temp[h]=dp[i-j-2][h]
                    temp[j]=temp[j]+1
                    for k in num_s:
                        if temp[k[1]]>dp[i][k[1]]:
                            for h in range(6):
                                dp[i][h]=temp[h]
                            break
                        elif temp[k[1]]==dp[i][k[1]]:
                            pass
                        else:
                            break
                else:
                    pass
ans=''
for i in num_s:
    ans=ans+str(i[0])*dp[n][i[1]]
print(ans)


Measured memory_bytes: 46956
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n;
	cin >> n;
	V<int> a(n);
	RBF(ai, a) {
		cin >> ai;
	}

	V<int> peak(n, 0);
	bool up = false;
	if (a[0] < a[1]) {
		up = true;
		peak[0] = -1;
	}
	RNG(i, 1, n - 1) {
		if (up) {
			if (a[i] > a[i + 1]) {
				up = false;
				peak[i] = 1;
			}
		}
		else {
			if (a[i] < a[i + 1]) {
				up = true;
				peak[i] = -1;
			}
		}
	}
	if (up) {
		peak[n - 1] = 1;
	}

	LL yen = 1000, kabu = 0;
	REP(i, n) {
		if (peak[i] == -1) {
			kabu = yen / a[i];
			yen -= a[i] * kabu;
		}
		else if (peak[i] == 1) {
			yen += a[i] * kabu;
			kabu = 0;
		}
	}

	col(yen);
	return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
signed main(){
    int a[5];
    int b=0,i;
    for(i=0;i<5;i++){
        scanf("%d",&a[i]);
        if(a[i]==0){
            b=i;
        }
    }
    printf("%d\n",b+1);
    return(0);
}

Measured memory_bytes: 1724
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {
    int p, left, right;
};

struct Node T[MAX];
int n;

void Preorder(int);
void Inorder(int);
void Postorder(int);


int main() {
    int i, v, l, r, root = 0;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++) {
        scanf("%d%d%d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) root = i;
    }

    printf("Preorder\n");
    Preorder(root);
    printf("\n");
    printf("Inorder\n");
    Inorder(root);
    printf("\n");
    printf("Postorder\n");
    Postorder(root);
    printf("\n");

    return 0;
}


void Preorder(int u) {
    if (u == NIL) return;

    printf(" %d", u);
    Preorder(T[u].left);
    Preorder(T[u].right);
}

void Inorder(int u) {
    if (u == NIL) return;

    Inorder(T[u].left);
    printf(" %d", u);
    Inorder(T[u].right);
}

void Postorder(int u) {
    if (u == NIL) return;

    Postorder(T[u].left);
    Postorder(T[u].right);
    printf(" %d", u);
}


Measured memory_bytes: 2136
def is_ok(W, limit_num, track_num):
    cu_vol = 0
    cu_tr = 0
    
    for i in range(len(W)):
        if cu_vol + W[i] > limit_num:
            cu_vol = W[i]
            cu_tr += 1
        else:
            cu_vol += W[i]
    if cu_vol:
        cu_tr += 1
    
    return track_num >= cu_tr

n, k = [int(i) for i in input().split()]
W = [int(input()) for _ in range(n)]

top = max(W)
tail = sum(W)
limit_num = 0

while top < tail:
    limit_num = (top + tail) // 2
    if is_ok(W, limit_num, k):
        tail = limit_num
    else:
        top = limit_num + 1

print(tail)




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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int H,W;
int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      string str;
      cin >> str;
      if (str == "snuke"){
	char row = 'A' + j;
	cout << row << i + 1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 764
var sx,sy,tx,ty,i:Integer;
begin
	read(sx,sy,tx,ty);
	for i:=sy+1 to ty do write('U');
	for i:=sx+1 to tx do write('R');
	for i:=sy+1 to ty do write('D');
	for i:=sx to tx do write('L');
	for i:=sy to ty do write('U');
	for i:=sx to tx do write('R');
	write('DR');
	for i:=sy to ty do write('D');
	for i:=sx to tx do write('L');
	write('U');
end.


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

int main() {
  int A,B;
  char op;
  cin >> A >> op >>B;
  // ここにプログラムを追記
  if(op=='+'){
    cout << A+B << endl;
  }else{
    cout << A-B << endl;
  }
}

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

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

  intl rootN = sqrt(n);
  for (intl i = rootN; i > 0; i--) {
    if (n % i == 0) {
      cout << n / i + i - 2 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256