akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    cin.tie(0);
ios::sync_with_stdio(false);
    int n; cin>>n;
    vector <vector<int>> data(n,vector <int>(n-1));
    
    int susumi[1002] = {};
    rep(i,n)rep(j,n-1) {cin>>data[i][j]; data[i][j]--;}
    int ans = 0;
    bool add = true;
    int z = 0;
    while(1){
        add = false;
        bool p[1005] = {};
        rep(i,n){
            z++;
            if(p[i]) continue;
            if(susumi[i]==n-1) continue;
            int vs = data[i][susumi[i]];
            if(p[vs]) continue;
            if(susumi[vs]==n-1) {cout<<-1<<endl; return 0;}
            if(data[vs][susumi[vs]]==i){
                add=true; susumi[i]++, susumi[vs]++;
                p[i]=true, p[vs]=true;
            }
        }
        if(add||z==1002000) {ans++; continue;}
            else{
                rep(i,n) { if(susumi[i] != n-1) {cout<<-1<<endl; return 0;} }
                cout<<ans<<endl; return 0;
            }
    }
    
}


Measured memory_bytes: 10112
while True:
    h, w = map(int, input().split())

    if h == 0 and w == 0:
        break
    else:
        for i in range(h):
            if i % 2 == 0:
                for ii in range(w):
                    if ii % 2 == 0:
                        print('#', end='')
                    else:
                        print('.', end='')

            else:
                for ii in range(w):
                    if ii % 2 == 0:
                        print('.', end='')
                    else:
                        print('#', end='')

            print()
        print()



Measured memory_bytes: 7008
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) 
{
    ll n;
    cin >> n;
    
    vll p(n);
    
    ll r = 0;
    
    rep(i, n) {
        cin >> p[i];
    }
    
    if (p[n-1] == n) swap(p[n-1], p[n-2]), r++;
    
    rep(i, n-1) {
        if (p[i] == i+1) {
            swap(p[i], p[i+1]);
            r++;
        }
    }
    
    mes(r);
   
    
}


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

int w,h;
int fd[50][50];

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

void dfs(int x, int y){
	fd[y][x] = 0;
	for(int i=0; i<8; i++){
		int mx = x+dx[i];
		int my = y+dy[i];
		if(0<=mx && mx<w && 0<=my && my<h && fd[my][mx])
			dfs(mx, my);
	}
}

int main(void){
	while(cin >> w >> h, w|h){
		for(int y=0; y<h; y++)
			for(int x=0; x<w; x++)
				cin >> fd[y][x];

		int count=0;
		for(int y=0; y<h; y++)
			for(int x=0; x<w; x++)
				if(fd[y][x]){
					count++;
					dfs(x,y);
				}
		
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
n,m = map(int,input().split())
h = list(map(int,input().split()))
load = {x : [] for x in range(1,n+1)}
ans = h[:]
cnt = 0
for i in range(m):
    a,b = map(int,input().split())
    if b in load[a]:
        pass
    else:
        load[a].append(b)
        load[b].append(a)
        if ans[a - 1] == 0:
            pass
        else:
            if h[a-1] > h[b-1]:
                pass
            else:
                ans[a-1] = 0
                
        if ans[b - 1] == 0:
            pass
        else:
            if h[b-1] > h[a-1]:
                    pass
            else:
                ans[b-1] = 0
                
                
for i in ans:
    if i:
        cnt += 1
print(cnt)


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

int main(){
    int N;
    cin >> N;
    int a;
    int i;
    int check[9]={0};
    for(i=0; i<N; i++){
        cin >> a;
        if(a<400) check[0]++;
        else if(a<800) check[1]++;
        else if(a<1200) check[2]++;
        else if(a<1600) check[3]++;
        else if(a<2000) check[4]++;
        else if(a<2400) check[5]++;
        else if(a<2800) check[6]++;
        else if(a<3200) check[7]++;
        else check[8]++;
    }

    int count=0;
    for(i=0; i<8; i++){
        if(check[i]>0) count++;
    }

    int max,min;
    min=count;
    if(min==0) min=1;
    max=count+check[8];

    cout << min << ' ' << max << endl;

    return 0;
}

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

int main() {
    ll n,ans=1LL;
    cin>>n;
    for(int i=0; i<n; i++) {
        ll t; cin>>t;
        ll g = __gcd(ans, t);
      	ans = ans / g * t;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int N, M;
vector<pair<int, int>> V;
bool flag[10];
ll ans = 0;

void flagInit(){
	for(int i = 1; i <= N; i ++)flag[i] = false;
}
bool checkAllFlagTrue(){
	for(int i = 1; i <= N; i ++)if(!flag[i])return false;
	return true;
}
void search(int node){
	flag[node] = true;
	if(checkAllFlagTrue()){
		ans ++;
		return;
	}
	for(int i = 1; i <= M; i ++){
		if(V[i].first == node && !flag[V[i].second]){
			search(V[i].second);
			flag[V[i].second] = false;
		}
		if(V[i].second == node && !flag[V[i].first]){
			search(V[i].first);
			flag[V[i].first] = false;
		}
	}
}

int main(){

	cin >> N >> M;
	V.pb(make_pair(0, 0));
	for(int i = 1; i <= M; i ++){
		int a, b;
		cin >> a >> b;
		V.pb(make_pair(a, b));
	}
	flagInit();
	search(1);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 255001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

string s;

signed main(){
    cin >> s;
    int x=0,y=0;
    for(int i = 0 ; i < s.size() ; i++){
        if(s[i]=='E')x|=1;
        if(s[i]=='W')x|=2;
        if(s[i]=='N')y|=1;
        if(s[i]=='S')y|=2;
    }
    if(x==1||x==2||y==1||y==2)return puts("No"),0;
    puts("Yes");


}


Measured memory_bytes: 256
def gcd(a,b):
    if ( b==0 ):
        return a
    else:
        return (gcd(b, a%b))

input()
A = list(map(int, input().split()))

left_gcd = [A[0]]
for i in A[1:]:
    left_gcd.append(gcd(left_gcd[-1],i))

right_gcd = [A[-1]]
for i in reversed(A[0:-1]):
    right_gcd.append(gcd(right_gcd[-1],i))
right_gcd.reverse()

gcd_lst = [right_gcd[1]] + [gcd(right_gcd[i+1], left_gcd[i-1]) for i in range(1,len(A)-1)] + [left_gcd[-2]]
print(max(gcd_lst))

Measured memory_bytes: 14436
#include <bits/stdc++.h>
//#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, H;
int x[100], y[100], h[100], d[100];

int main() {
    cin >> N;
    int cx, cy;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    int xs, ys, hs;
    for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
            xs = x[i];
            ys = y[i];
            hs = h[i];
        }
    }
    bool flag;
    for (cx = 0; cx <= 100; cx++) {
        for (cy = 0; cy <= 100; cy++) {
            flag = 1;
            H = hs + abs(cx - xs) + abs(cy - ys);
            for (int i = 0; i < N; i++) {
                if (max(H - abs(cx - x[i]) - abs(cy - y[i]), 0) != h[i]) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                break;
            }
        }
        if (flag) {
            break;
        }
    }
    cout << cx << ' ' << cy << ' ' << H << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define MOD 10e9+7

int main(){
    int X, A, B; cin >> X >> A >> B;
  	if(0 >= B - A) cout << "delicious";
    else if(X >= B - A) cout << "safe";
    else cout << "dangerous";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = /*1000000007 */ 998244353;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
#include <cstdint>
template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while(exp) {
            if(exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
using mint = modint<MOD>;
void solve() {
    vector<mint> beki;
    beki.pb(1);
    rep(i, n) { beki.pb(beki.back() * 2); }

    mint dp[n + 1][k + 1];
    rep(i, k + 1) { dp[0][i] = 0; }
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, k + 1) {
            if(j < A[i]) {
                dp[i + 1][j] = dp[i][j] * 2;
            } else {
                dp[i + 1][j] = dp[i][j] * 2 + dp[i][j - A[i]];
            }
        }
    }

    cout << dp[n][k].a << endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, n) {
        cin >> x;
        A.pb(x);
    }
    solve();
}

Measured memory_bytes: 74104
import java.util.Scanner;

class Main{
     public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	double r = scan.nextDouble();
    	double pi = 3.141592653589;
    	
    	System.out.println(String.format("%8f", r*r*pi) + " " + String.format("%8f", 2.0*r*pi));
    	
     }
}

Measured memory_bytes: 28172
#include<iostream>

using namespace std;
int main() {
	int L=0, R=0, d=0,count=0;
	cin >> L >> R >> d;
	for (int i=L;i <= R;i++) {
		if (i % d == 0)count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
int main() {
  int n;
  int ans = 1;
  cin >> n;
  vector<int> l(n);
  for(int i = 0; i < n;i++) cin >> l[i];
  int m = l[0];
  for(int i = 1; i < n; i++) {
    if(l[i] >= m) ans += 1;
    m = max(l[i], m);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: i64 = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let sum: i64 = a.iter().sum();
    let mut candidates = vec![];
    for i in 1.. {
        if sum < i * i {
            break;
        }
        if sum % i == 0 {
            candidates.push(i);
            if i * i != sum {
                candidates.push(sum / i);
            }
        }
    }
    candidates.sort();
    candidates.reverse();
    for &candidate in candidates.iter() {
        let mut add = vec![];
        let mut sum = 0;
        for &a in a.iter() {
            let upper = (a + candidate - 1) / candidate * candidate;
            sum += upper - a;
            add.push(upper - a);
        }
        add.sort();
        add.reverse();
        let mut negative = 0;
        if sum <= k && negative <= k {
            println!("{}", candidate);
            return;
        }
        for &a in add.iter() {
            sum -= a;
            negative += candidate - a;
            if sum <= k && negative <= k {
                println!("{}", candidate);
                return;
            }
        }
    }
    unreachable!()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4476
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
constexpr Int Mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<=en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


int n,m,_,x,y,q,key;
string s,sb;
bool ok;

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

  cin>>n>>m; WeightedGraph<int>g(10);
	rep(i,10)rep(j,10){
		cin>>x; if(!x)continue;
		g[i].eb(j,x);
	}
	V(int)d[10];
	rep(i,10)d[i]=dijkstra(g,i);
	int ans=0;
	rep(i,n)rep(j,m){
		cin>>x; if(x==-1)continue;
		ans+=d[x][1];
	}
	END
}

Measured memory_bytes: 256
#include<cstdio>
#define N 110000
inline char gc(){
	static char now[1<<16],*T,*S;
	if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
	return *S++;
}
inline int read(){
	int x=0;char ch=gc();
	while (ch<'0'||ch>'9') ch=gc();
	while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
	return x;
}
int n,a[N],differ[N];
int main(){
	//freopen("box.in","r",stdin);
	n=read();long long sum=0;long long sum1=0;
	if (n==1){printf("YES");return 0;}
	sum1=(long long)n*(n+1)>>1;
	for (int i=1;i<=n;++i) a[i]=read(),sum+=a[i];a[n+1]=a[1];
	for (int i=1;i<=n;++i) differ[i]=a[i+1]-a[i];int k=sum/sum1;
	if (sum%sum1){printf("NO");return 0;}
	for (int i=1;i<=n;++i){
		double x=(differ[i]-k)/(-1.0*n);
		if (x<0){printf("NO");return 0;}
		int xx=x;if (xx!=x){printf("NO");return 0;}
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100000001
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int n, m, a[10], ans;
map<int,int> mp;

int solve(int tmp[4], int k, int sum, int p){
	int t, u[4];
	rep(i,4)u[i] = tmp[i];
	u[k++] = p;
	if(a[p] >= 10)sum = sum*100+a[p];
	else sum = sum*10+a[p];
	
	if(m == k){
		if(mp[sum]==0)ans++;
		mp[sum] = 1;
		return 0;
	}
	
	for(int i = 0;i < n;i++){
		t = 1;
		rep(j,k)if(u[j] == i)t = 0;
		if(t)solve(u, k, sum, i);
	}
	return 0;
}

int main(){
	int u[4] = {0,0,0,0};
	while(1){
		ans = 0;
		mp.clear();
		scanf("%d%d", &n, &m);
		if(!n)break;
		rep(i,n)scanf("%d", &a[i]);
		for(int i = 0;i < n;i++){
			solve(u, 0, 0, i);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

using namespace std;





int main(){

    int n,q,j;
    int s[10001];
    int t[500];
    int counter=0;

    cin >> n;
    for(int i=0;i<n;i++) cin >> *(s+i);
    cin >> q;
    for(int i=0;i<q;i++) cin >> *(t+i);
    
    for(int i=0;i<q;i++){
        *(s+n) = *(t+i);
        j=0;
        while(s[j] != t[i]){ j++; }
        if(j != n){ counter++; }
    }

    cout << counter << endl;

    return 0;
}



Measured memory_bytes: 3108
n = int(input())
A = list(map(int,input().split()))
for i, a in enumerate(A):
    temp = a
    i -= 1
    while i >= 0 and A[i] >temp:
        A[i+1] = A[i]
        A[i] = temp
        i -= 1
    L=[str(a) for a in A]   
    p = ' '.join(L)
    print(p)


Measured memory_bytes: 5604
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INF=(1<<21);
static const int APE=0;
static const int MID=1;
static const int BOT=2;

int n, M[MAX][MAX];

void dijkstra(){
  int mv, i, u, v;
  int d[MAX], c[MAX];

  for(i=0;i<n;i++){
    d[i]=INF;
    c[i]=APE;
  }

  d[0]=0;
  c[0]=MID;
  while(1){
    mv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(mv>d[i]&&c[i]!=BOT){
        u=i;
        mv=d[i];
      }
    }
    if(u==-1)break;
    c[u]=BOT;
    for(v=0;v<n;v++){
      if(c[v]!=BOT&&M[u][v]!=INF){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          c[v]=MID;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1 : d[i])<<endl;
  }
}

int main(){
  int i, j, k, c, u, v;

  cin>>n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v>>c;
      M[u][v]=c;
    }
  }
  dijkstra();

  return 0;
}


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

long int cb(long int n,long int k){
  
  return (n-k+1)*k + 1;
}

int main() {
  long int N, K;
  cin >> N >> K;
  long int combos = 0;
  for(int i=K;i<=N+1;i++){
    combos += cb(N,i);
  }
  
  cout << combos % 1000000007 << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

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

    if (n == 25) cout << "Christmas" << endl;
    else if (n == 24) cout << "Christmas Eve" << endl;
    else if (n == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if( a * c > b) cout << b / a << endl;
    else cout << c << endl;

}

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

for i in range(n):
    a, b, c = list(map(int, input().split()))
    if min(a*a+b*b, min(a*a+c*c, c*c+b*b)) == max(a*a, max(b*b, c*c)):
        print ("YES")
    else:
        print ("NO")

Measured memory_bytes: 7540
/*
  kadai4_3 stone_monument
  unomi
*/
#include <stdio.h>
#include <math.h>

int convert_snow_height(int n, int east_height){
    int east_tower_height=0;
    // (east_height - west_height)本目(東側)と(east_height - west_height - 1)本目(西側)の間で高さ測定
    // 1 ~ nまでの和を計算 -> 東側の(east_height - west_height)本目の塔の高さ
    east_tower_height = n*(1+n)/2;
    // 積雪の高さ = 東側の塔の高さ - 東側の雪に埋もれていない部分の高さ
    return east_tower_height - east_height;
}

int main(void){
    int west_height=0,east_height=0;
    // west_height(a), east_height(b) の入力を取得
    scanf("%d %d",&west_height, &east_height);

    printf("%d\n",convert_snow_height(east_height-west_height, east_height));

    return 0;
}

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Objects;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int L = scanner.nextInt();

    UnionFind ufk = new UnionFind(N);
    UnionFind ufl = new UnionFind(N);
    for (int i = 0; i < K; i++) {
      int p = scanner.nextInt() - 1;
      int q = scanner.nextInt() - 1;
      ufk.union(p, q);
    }

    for (int i = 0; i < L; i++) {
      int p = scanner.nextInt() - 1;
      int q = scanner.nextInt() - 1;
      ufl.union(p, q);
    }

    HashMap<Pair, Integer> count = new HashMap<>();
    for (int i = 0; i < N; i++) {
      Pair p = new Pair(ufk.find(i), ufl.find(i));
      count.put(p, count.getOrDefault(p, 0) + 1);
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) sb.append(count.get(new Pair(ufk.find(i), ufl.find(i)))).append(' ');
    System.out.println(sb.toString());
  }

  static class Pair {
    public final int k;
    public final int l;

    Pair(int k, int l) {
      this.k = k;
      this.l = l;
    }

    @Override public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Pair pair = (Pair) o;
      return k == pair.k &&
          l == pair.l;
    }

    @Override public int hashCode() {
      return Objects.hash(k, l);
    }
  }

  static class UnionFind {
    private final int[] table;
    private final int[] ranks;
    private final int[] sizes;

    public UnionFind(int size) {
      this.table = new int[size];
      this.ranks = new int[size];
      this.sizes = new int[size];
      for (int i = 0; i < size; i++) {
        table[i] = i;
        sizes[i] = 1;
      }
    }

    public int find(int x) {
      if (table[x] != x) {
        table[x] = find(table[x]);
      }
      return table[x];
    }

    public void union(int x, int y) {
      int xRoot = find(x);
      int yRoot = find(y);
      if (xRoot == yRoot) return;

      if (ranks[xRoot] < ranks[yRoot]) {
        int tmp = xRoot;
        xRoot = yRoot;
        yRoot = tmp;
      }

      table[yRoot] = xRoot;
      sizes[xRoot] += sizes[yRoot];
      if (ranks[xRoot] == ranks[yRoot]) ranks[xRoot]++;
    }
  }
}


Measured memory_bytes: 148568
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  bool ans = true;
  if(S[0]!='A')
  {
    ans = false;
  }
  rep(i,26)
  {
    if(S[1]==Alphabet[i])
    {
      ans = false;
    }
    else if(S[N-1]==Alphabet[i])
    {
      ans = false;
    }
  }
  int count = 0;
  rep(i,N-2)
  {
    rep(j,26)
    {
    if(S[i+2]==alphabet[j])
    {
      continue;
    }
    else if(S[i+2]=='C')
    {
      count ++;
      break;
    }
    
    }
  }
  if(ans==true&&count==1)
  {
    cout << "AC" << endl;
  }
  else
  {
    cout << "WA" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int N, K;
int A[200001];

//---------- にぶたん[f,f,f,f,'t',t,t,t] ----------
bool isOK(int len)
{
	if (len == 0) return false;

	int cut_cnt = 0;
	REP(i, N)
	{
		int d = (A[i] - 1) / len;
		cut_cnt += d;
	}
	return cut_cnt <= K;
}

int binary_search(int n)
{
	int left = -1;
	int right = n;
	while (right - left > 1)
	{
		int mid = left + (right - left) / 2;
		if (isOK(mid))
			right = mid;
		else
			left = mid;
	}
	return right;
}

signed main()
{
	cin >> N >> K;
	REP(i, N)
	{
		cin >> A[i];
	}
	cout << binary_search(1000000001) << endl;
}



Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=1e9;cin>>n;
  string s;cin>>s;
  lvector Sb(n+1,0);
  rep(i,n) Sb[i+1]=Sb[i]+((s[i]=='#')?1:0);
  ll nblack=Sb[n];
  rep(i,n+1) {
    ll cost=Sb[i]+n-i-(nblack-Sb[i]);
    ans=min(ans,cost);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 2196
#include <cstdio>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 2000000000000LL
using namespace std;

typedef long long Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool shortestPath(Graph &g,
    Matrix &dist, vector<vector<int> > &prev) {
  int n = g.size();
  Array h(n);
  h.assign(n-1,INF+INF);
  REP(i,n) g[n-1].push_back(Edge(n,i,0));
  REP(k,n) REP(i,n) FOR(e,g[i]) {
    if (h[e->src]<INF && e->weight<INF && h[e->dst] > h[e->src] + e->weight) {
      h[e->dst] = h[e->src] + e->weight;
      if (k == n-1) return false; // negative cycle
    }
  }
  REP(i,n) FOR(e,g[i]) e->weight += h[i] - h[e->dst];
  dist.assign(n, Array(n, INF));
  prev.assign(n, vector<int>(n, -2));
  REP(s, n) {
    priority_queue<Edge> Q;
    Q.push(Edge(s, s, 0));
    while (!Q.empty()) {
      Edge e = Q.top(); Q.pop();
      if (prev[s][e.dst] != -2) continue;
      prev[s][e.dst] = e.src;
      FOR(f,g[e.dst]) {
        if (e.weight<INF && f->weight<INF && dist[s][f->dst] > e.weight + f->weight) {
          dist[s][f->dst] = e.weight + f->weight;
          Q.push(Edge(f->src, f->dst, e.weight + f->weight));
        }
      }
    }
    REP(u, n) {
      if(dist[s][u]<INF)dist[s][u] += h[u] - h[s];
    }
  }
  return true;
}

int main(){
	int r,T,V,E,s,t,e,i,j;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d",&V,&E);
		Graph g(V+1);
		Matrix dist;
		vector<vector<int> > prev;
		for(i=0;i<V;i++)g[i].push_back(Edge(i,i,0));
		for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e));
		if(!shortestPath(g,dist,prev))puts("NEGATIVE CYCLE");
		else for(i=0;i<V;i++)for(j=0;j<V;j++){
			/*if(i==j)printf("0");
			else*/ if(dist[i][j]>=INF)printf("INF");
			else printf("%lld",dist[i][j]);
			printf(j<V-1?" ":"\n");
		}
	//}
}

Measured memory_bytes: 1392
// Solution by ** Abhishek Mittal **
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vll vector<long long>  

#define all(c) c.begin(), c.end()

// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())

// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO
    
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];

    for(int i=0;i<n-k;i++){
        if(arr[i] < arr[i+k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


    return 0;

}

Measured memory_bytes: 4604
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 100000000
int d[101][101],n,m,s,g1,g2;
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
void warsall_floyd(){//warsall_floyd 中継地点のループを一番外側にしてみた
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}	
		}
	}
	return;
}
int main(){
	while(1){
		int a,b,c,ans=INF;
		cin>>n>>m>>s>>g1>>g2;
		if(n+m+s+g1+g2==0)break;
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				d[i][j]=INF;
			}
			d[i][i]=0;
		}
		for(int i=0;i<m;i++){
			cin>>a>>b>>c;
			d[a][b]=c;
		}
		warsall_floyd();
		for(int i=1;i<=n;i++){
			ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
		}
		cout<<ans<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;cin >> n;
vector<ll>a(n);
vector<ll>b(1e5+10);
ll sum = 0;
for(int i = 0;i<n;i++){
    cin >> a[i];
    b[a[i]]++;
    sum += a[i];
}
int t;cin >> t;
while(t--){
    ll r;ll d;
    cin >> r >> d;
    sum += (d-r)*b[r];
    b[d] += b[r];
    b[r] = 0;
    cout << sum <<endl;
}
return 0;
}

Measured memory_bytes: 4836
#include<stdio.h>
#include<string.h>
int main()
{
    char s[1000000];
    scanf("%s",s);
    int a=0,count=0;
    for(int i=1;i<strlen(s);i++){
        if(s[a]==s[i]){
            count=count+(i-a-2);
            a=i;
        }
        else if(i==strlen(s)-1&&s[i]!=s[a]){
        count=count+1+(i-a-2);
        }
    }
    if(count%2==0) printf("Second");
    else printf("First");
    return 0;

}


Measured memory_bytes: 1836
#include <stdio.h>


int main(void){
    long long N;
    scanf("%lld", &N);
    long long x, sum;
    x = 1;
    sum = 0;
    while(x * (x + 1) < N){
        if(N % x == 0){
            sum += N / x - 1;
        }
        x++;
    }
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
X = input()
pc = X.count("1")

if pc == 1:
    if X[-1] == "0":
        for i, s in enumerate(X):
            if i == N - 1:
                print(2)
            elif s == "0":
                print(1)
            else:
                print(0)
    else:
        ans = [2] * (N - 1) + [0]
        print(*ans, sep="\n")
    exit()


m01 = 0
m10 = 0
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
    if s == "1":
        m01 += b01
        m01 %= pc + 1
        m10 += b10
        m10 %= pc - 1
    b01 *= 2
    b01 %= pc + 1
    b10 *= 2
    b10 %= pc - 1


def pop_count(T):
    T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
    T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
    T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
    T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
    T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
    return T


memo = [0] * (N + 10)
for i in range(1, N + 10):
    p = pop_count(i)
    memo[i] = memo[i % p] + 1


ans = [0] * N
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
    if s == "0":
        m = m01
        m += b01
        m %= pc + 1
    else:
        m = m10
        m -= b10
        m %= pc - 1
    ans[i] = memo[m] + 1
    b01 *= 2
    b01 %= pc + 1
    b10 *= 2
    b10 %= pc - 1

print(*ans[::-1], sep="\n")

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

ans = False
count = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    
    if count >= 3:
        ans = True


if ans:
    print("Yes")
else:
    print("No")

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

//1点更新,区間和
class SegmentTree {
public:
    SegmentTree(int64_t n, int64_t value) {
        n_ = (int64_t)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, value);
    }

    void add(int64_t x, int64_t diff) {
        nodes_[x + n_ - 1] += diff;
        if (x + n_ - 1 == 0) {
            return;
        }
        for (int64_t i = (x + n_ - 2) / 2; ; i = (i - 1) / 2) {
            nodes_[i] = nodes_[2 * i + 1] + nodes_[2 * i + 2];
            if (i == 0) {
                break;
            }
        }
    }

    int64_t getSum(int64_t a, int64_t b, int64_t k = 0, int64_t l = 0, int64_t r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return 0;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        int64_t lv = getSum(a, b, 2 * k + 1, l, (l + r) / 2);
        int64_t rv = getSum(a, b, 2 * k + 2, (l + r) / 2, r);
        return lv + rv;
    }

private:
    //2のべき乗
    int64_t n_;
    vector<int64_t> nodes_;
};

struct Query {
    int64_t l, r, index;
};

int main() {
    int64_t N, Q;
    cin >> N >> Q;
    vector<int64_t> c(N);
    for (int64_t& C : c) {
        cin >> C;
        C--;
    }

    vector<Query> queries(Q);
    for (int64_t i = 0; i < Q; i++) {
        cin >> queries[i].l >> queries[i].r;
        queries[i].l--;
        queries[i].index = i;
    }

    sort(queries.begin(), queries.end(), [](Query& lhs, Query& rhs) {
        return lhs.r < rhs.r;
    });

    vector<int64_t> ans(Q);

    int64_t r = 0;
    SegmentTree st(N, 0);
    vector<int64_t> pos(N, -1);

    for (Query& query : queries) {
        while (r < query.r) {
            //c[r]が加わる
            if (pos[c[r]] != -1) {
                //2回目以降の出現の場合、以前の記録を消す
                st.add(pos[c[r]], -1);
            }

            //今回のものを記録
            pos[c[r]] = r;
            st.add(r, 1);

            r++;
        }

        ans[query.index] = st.getSum(query.l, query.r);
    }

    for (int64_t a : ans) {
        cout << a << endl;
    }
}

Measured memory_bytes: 35464
#include <stdio.h>
  int main(void){
      double a,b,c,d,e,f,x,y;
      while(scanf( "%lf %lf %lf %lf %lf %lf" , &a , &b , &c , &d , &e , &f ) != -1 ){
          y = (d*c - a*f) / ( d*b - a*e );
          x  = ( c - ( b * y) ) / a;

          printf( "%.3lf %.3lf\n" , x , y );
      }
  }


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

int main(){
  int x;
  cin >> x;
  for(int i=0;i<3;i++){
    if(x%10==7){
      cout << "Yes" << endl;
      return 0;
    }
    x/=10;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi 3.14159265358979323846
#define INF 100000000000000000

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

int main(){
	ll n;cin>>n;
	vector<vector<ll>> abc(n,vector<ll>(3));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			cin>>abc[i][j];
		}
	}

	vector<vector<ll>> dp(n+1,vector<ll>(3,0));

	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){//前にjを使った
			chmax(dp[i+1][(j+1)%3],dp[i][j]+abc[i][j]);
			chmax(dp[i+1][(j+2)%3],dp[i][j]+abc[i][j]);
		}
	}

	ll MAX=-1;
	for(ll j=0;j<3;j++){
		chmax(MAX,dp[n][j]);
	}

	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 11136
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll cr=0,cg=0,cb=0,i,j,k;
	for(i=0;i<n;i++)
	{
		if(s[i]=='R')
			cr++;
		else if(s[i]=='G')
			cg++;
		else
			cb++;
	}
	ll ans=cr*cg*cb;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				k=2*j-i;
				if(k<n)
				{
					if(s[i]!=s[k]&&s[k]!=s[j])
						ans--;
				}
			}
		}
	}
	cout<<ans;

	return 0;
}

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

int main() {
    int n, k;
    int score = 1;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        if (score < k)  score *= 2;
        else score += k;
    }
    cout << score << endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] d = new int[N];
		for(int i = 0;i < N;i++) {
			d[i] = scn.nextInt();
		}
		Arrays.sort(d);
		int dd = d[N/2-1];
		int du = d[N/2];
		int ans = 0;
		if(dd!=du) {
			ans = du-dd;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 49680
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
const ll INF = 1E+16;

ll dp[200005][3];

ll f(ll a, ll v) {
    if (a==-INF) return -INF;
    else return a+v;
}

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

    if (n==2) {
        ans = max(a[0], a[1]);
        cout << ans << endl;
        return 0;
    }
    

    dp[0][0] = a[0];
    
    dp[1][1] = a[1];
    dp[2][0] = a[0] + a[2];
    dp[2][2] = a[2];

    rep(i, n) rep(j, 3) {
        if (i<=2) continue;
        if (j==0) {
            if (i%2==1) continue;
            dp[i][j] = dp[i-2][j]+a[i];
        }
        if (j==1) {
            if (i%2==0) continue;
            dp[i][j] = max(dp[i-2][j]+a[i], dp[i-3][j-1]+a[i]);
        }
        if (j==2) {
            if (i%2==1) continue;
            dp[i][j] = max(dp[i-4][j-2]+a[i], max(dp[i-2][j]+a[i], dp[i-3][j-1]+a[i]));
        }
        //cout << i << " " << j << " " << dp[i][j] << endl;
    }
    
    
    if (n%2==0) {
        ans = max(dp[n-1][1], dp[n-2][0]);
    }
    else {
        ans = max(dp[n-3][0], max(dp[n-1][2], dp[n-2][1]));
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9596
#include <iostream>
#include <queue>
#include <utility>

using namespace std;
int usize[100001];
int dst[100001];
int uindex[100002];
int main() {
    int N, M;
    int u[100001], v[100001];
    int S, T;
    cin >> N >> M;
    for (int i=0; i<M; i++) cin >> u[i] >> v[i];
    cin >> S >> T;


    for (int i=0; i<M; i++) {
        usize[u[i]]++;
    }
    int acc = 0;
    for (int i=1; i<=N; i++) {
        uindex[i] = acc;
        acc += usize[i];
    }
    uindex[N+1] = acc;

    {
        int _uindex[100002];
        for (int i=1; i<=N+1; i++) _uindex[i] = uindex[i];
        for (int i=0; i<M; i++) {
            dst[ _uindex[u[i]] ] = v[i];
            _uindex[u[i]]++;
        }
    }

    int step[100001][3];
    for (int i=0; i<100001; i++) {
        for (int j=0; j<3; j++) step[i][j] = -1;
    }
    queue<pair<int, int>> q;
    q.push(make_pair(S, 0));
    step[S][0] = 0;
    
    while (!q.empty()) {
        int pos = q.front().first;
        int st = q.front().second;
        q.pop();
        for (int idx = uindex[pos]; idx < uindex[pos+1]; idx++) {
            int dpos = dst[idx];
            if (step[dpos][(st+1) % 3] == -1) {
                step[dpos][(st+1) % 3] = st + 1;
                q.push(make_pair(dpos, st+1));
            }
        }
    }
    if (step[T][0] != -1) cout << step[T][0]/3 << endl;
    else cout << -1 << endl;
    return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll A, B, N; cin >> A >> B >> N;
  ll ans = 0;
  if(N < B) {
    ll tmp = A * N;
    ans = tmp / B;
  } else {
    ll tmp3 = A * (B - 1);
    ll E = tmp3 / B;

    ll tmp = A * N;
    ll C = tmp / B;
    ll tmp2 = N / B;
    ll D = A * tmp2;
    ans = max(E, C - D);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#ABC096-D Five, Five Everywhere
"""
問題：
55555以下の異なる素数をN個出力せよ。
但し、N個のうちどの5つの素数を組み合わせても素数にならないように
しなければならない。
このような数列は必ず作れるものと仮定して良い。(5<=N<=55)
解法：
5で割って1余る素数の個数は55555以下のうち1408個存在する。
よってこのうち適当にN個とって出力すれば良い。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

import math
#nまでの素数のリスト
def eratosthenes(n): #必要な分だけ用意
    if n < 2: #1は素数ではない
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p: #limit=root(n)
            return prime + data #root(n)まで判定すれば、残りは全て素数であると言える
        prime.append(p)
        data = [e for e in data if e % p != 0] #エラトステネスのふるい

primes = eratosthenes(55555+1)

#debug
"""
res = 0
for i in primes:
    if i%5==1:
        res += 1
print(res) #1408
"""
ans = []
for i in primes:
    if n <= 0:
        break
    if i%5==1:
        ans.append(i)
        n -= 1

print(*ans)

Measured memory_bytes: 42604
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int *, int);
void inputVector(vector<int> *, int);
template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n;
    cin >> n;
    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
    return 0;
}

int inputValue() {
    int a;
    cin >> a;
    return a;
}

void inputArray(int *p, int a) {
    rep(i, a) { cin >> p[i]; }
}

void inputVector(vector<int> *p, int a) {
    rep(i, a) {
        int input;
        cin >> input;
        p->push_back(input);
    }
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

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


Measured memory_bytes: 256