akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let v = i.read_vec::<usize>(n);

    writeln!(o, "{}", solve(&v)).unwrap();
}
fn solve(v: &[usize]) -> usize {
    let mut c0 = HashMap::new();
    let mut c1 = HashMap::new();

    for i in 0..v.len() {
        let c = if i % 2 == 0 { &mut c0 } else { &mut c1 };
        *c.entry(v[i]).or_insert(0) += 1;
    }

    let m0 = get_modify(c0);
    let m1 = get_modify(c1);

    if m0.key != m1.key {
        m0.count + m1.count
    } else {
        min(m0.count + m1.count_next, m0.count_next + m1.count)
    }
}
fn get_modify(m: HashMap<usize, usize>) -> Modify {
    let (&key1, &key_count1) = m.iter().max_by_key(|&x| x.1).unwrap();
    let sum: usize = m.values().sum();

    let key_count2 = if let Some((&_key2, &key_count2)) =
        m.iter().filter(|&x| *x.0 != key1).max_by_key(|&x| x.1)
    {
        key_count2
    } else {
        0
    };
    Modify {
        key: key1,
        count: sum - key_count1,
        count_next: sum - key_count2,
    }
}
#[derive(Debug)]
struct Modify {
    key: usize,
    count: usize,
    count_next: usize,
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 14200
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B, C, D;

int main()
{
    cin >> A >> B >> C >> D;
    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }

        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
 
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
 
using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;
 
static long long INF = (1LL<<62);
 
LL dp[10000000L+2] = {0};
int p[10000000+2] = {0};
 
long long N;
vector<LL> PR;
 
void PINIT(long long n){
	for(int i=2; i<=n; i++){
		if(p[i] > 0) continue;
		for(int j=2; i*j <= n; j++){
			p[i*j]++;
		}
	}
	for(int i=2; i<=n; i++){
		if(p[i] == 0){
			dp[i] = 2;
			PR.push_back((long long)i);
		}
	}
}
 
LL f(LL x){
	if(x == 1) return 1;
	if(dp[x] > 0) return dp[x];
 
	LL ret = 1, p;
	for(int i=0; i<PR.size(); i++){
		if((x % PR[i]) == 0){
			p = PR[i];
			break;
		}
	}
	int e = 1;
	LL tmp = x;
	while(true){
		tmp = tmp / p;
		if((tmp % p) !=0){
			break;
		}
		e++;
	}
	ret = f(tmp) * (e + 1);
	dp[x] = ret;
	return ret;
}
 
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	PINIT(N);
	long long ans = 0;
	for(int k=1; k<=N; k++){
		ans += (k * f(k));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 125628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    double H, A;
    cin >> H >> A;
    cout << ceil(H / A);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  
  int i,A,B,K;
  scanf("%d%d%d",&A,&B,&K);
  
  if(2 * K >= B - A + 1){
    for(i = A ; i <= B ; i++){
      printf("%d\n",i);
    }
  }else{
    for(i = A ; i <= A + K - 1 ; i++){
      printf("%d\n",i);
    }
    for(i = B - K + 1 ; i <= B ; i++){
      printf("%d\n",i);
    }
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L
 
long double a,b,h,m,c,d1,d2;
int main()
{
	cin>>a>>b>>h>>m;
	d1=(long double)m/360.0+(long double)h/6;
	d2=(long double)m/30;
	d2=(d1-d2);
	c=sqrt(2*a*b)*sqrt((a*a+b*b)/(2*a*b)-cos(d2*PI));
	cout<<fixed<<setprecision(20)<<c; 
}


Measured memory_bytes: 4108
#include <iostream>
#include <set>

using namespace std;

int main (){
  int q,t,x;
  set<int> a;

  cin >> q;

  for (int i = 0; i < q; i++){
    cin >> t;
    cin >> x;
    if (t==0){
      a.insert(x);
      cout << a.size() << endl;
    }else{
      cout << a.count(x) << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 12460
def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print(int(w * (h/2)) if h % 2 == 0 else int(w*(h//2) + (w+1)//2))


if __name__ == '__main__':
    main()


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

int main(){
    int N, M;
    cin >> N >> M;
    int i;
    for(i=1; i<=M/2; i++){
        cout << i << " " << M-i+1 << endl;
    }
    for(i=1; i<=(M+1)/2; i++){
        cout << M+i << " " << 2*M+1-i+1 << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) {return log(b) / log(a);}

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << endl;

}


Measured memory_bytes: 256
def gcd(x,y,z):
    for i in range(x, 0, -1):
        if x%i==0 and y%i==0 and z%i==0:
            #print(i)
            return i
            break
            
    

def main():
    import sys
    N = int(sys.stdin.readline())
    total=0
    for i in range(1, N+1):
        for j in range(i, N+1):
            for k in range(j, N+1):
                if i==j and j==k:
                    total +=gcd(i, j, k)
                elif i==j or j==k or i==k:
                    total +=gcd(i, j, k)*3
                else:
                    total +=gcd(i, j, k)*6
                
    print(total)
    


if __name__=='__main__':
    main()

Measured memory_bytes: 74348
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main() 
{
    fastio
    int l,r,d; cin>>l>>r>>d; 
    cout<< r/d - l/d + (l%d==0); 
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,a,b,c;scanf("%d",&n);
  int dp[n][3] = {};scanf("%d%d%d",&dp[0][0],&dp[0][1],&dp[0][2]);
  for(i=1;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a;
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b;
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c;
  }
  printf("%d",max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));
}

Measured memory_bytes: 1408
import math
a, b, h, m = map(int, input().split())

small = 6*m
big = 30*h + 0.5*m
angle = min(360-abs(big-small), abs(big-small))
#print(angle)

cos_c = math.cos(math.radians(angle))

c = math.sqrt(a*a + b*b - 2*a*b*cos_c)
print(c)

Measured memory_bytes: 62212
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int comp(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return (*(int*)a<*(int*)b)-(*(int*)a>*(int*)b);}

uint32_t nextpint(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint64_t nextplong(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint32_t nextstr(char *s){ char c=getc_unlocked(stdin); while(c==' '||c=='\n') c=getc_unlocked(stdin); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getc_unlocked(stdin); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}
inline int abs2(const int a){return a>=0?a:-a;}

int main(void){
	long n=nextplong();
	long k=nextplong();
	if(n>=k){
		n=n%k;
	}
	long a=n;
	long b=k-n;
	printf("%ld\n", a<b?a:b);
}


Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << ((b - a) % 2 == 0 ? "Alice" : "Borys") << '\n';
}


Measured memory_bytes: 256
x , y = map(int,input().split())
n = max(x , y)
if x == y == 1:
    print(1000000)
elif min(x , y) == 1:
    if n == 2:
        print(500000)
    elif n == 3:
        print(400000)
    else:
        print(300000)
elif min(x , y) == 2:
    if n == 2:
        print(400000)
    elif n == 3:
        print(300000)
    else:
        print(200000)
elif min(x , y) == 3:
    if n == 3:
        print(200000)
    else:
        print(100000)
else:
    print(0)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;


using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	ll sum;
	ll mx = -1;

	ll k, n;
	cin >> k >> n;
	ll in1, in2 = -1,in0;
	rep(i, n) {
		cin >> in1;
		if (in2 >= 0) {
			mx = max(mx, in1 - in2);
		}
		else in0 = in1;
		in2 = in1;
	}
	sum = k - max(mx, k - in1 + in0);
	cout << sum << endl;

	return 0;
}


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

int main()
{
	int cycle[10] = { 1, 5, 3, 3, 3, 3, 3, 4, 3, 4 };
	char c[10][5] =
	{
		{ '0' },
		{ '.', ',', '!', '?', ' ' },
		{ '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 n;
	cin >> n;
	while (n--)
	{
		string s;
		cin >> s;

		int count = 0;
		char output = '0';

		for (char i : s)
		{
			if (i == '0' && output != '0')
			{
				cout << output;
				output = '0';
				count = 0;
			}
			output = c[i - '0'][count];
			count++;
			if (count >= cycle[i - '0']) count = 0;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2996
n = int(input())
alis = list(map(int, input().split()))
lis = [0]*n
for a in alis:
    lis[a-1] += 1
ans = 0
for i in lis:
    ans += i*(i-1)//2
lis2 = [0]*n
for i in range(n):
    lis2[i] = ans + 1 - lis[i]
for a in alis:
    print(lis2[a-1])

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

int main() {

    int k, a, b;
    scanf("%d %d %d", &k, &a, &b);

    if (a % k == 0) {
        printf("OK");
    } else {

        int sho = a / k;
        sho++;
        //printf("%d\n",sho);

        if (sho * k >= a && sho*k<=b) {
            printf("OK");
        } else {
            printf("NG");
        }


    }




    return 0;

}

Measured memory_bytes: 1708
from collections import Counter

H, W = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

ctr = Counter(sum(A, []))
ans = 0
for i, c in ctr.items():
    if i == -1:
        continue
    ans += graph[i][1] * c
print(ans)


Measured memory_bytes: 96348
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	int n, m;
	int l[100500], r[100500];
	set<int> key;
	cin >> n >> m;
	rep(i, m) cin >> l[i] >> r[i];
	
	int max_l = -1;
	int min_r = n;
	rep(i, m) {
		max_l = max(max_l, l[i]);
		min_r = min(min_r, r[i]);
	}
	int ans = min_r - max_l + 1;
	ans = max(ans, 0);
	cout << ans << endl;
	return 0;

}

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

int main() {

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

  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<long long>> g(n + 5, vector<long long> (n + 5, 1e15));
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;

    g[u][v] = g[v][u] = c;
  }

  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (g[i][j] <= l) g[i][j] = 1;
      else g[i][j] = 10000;
    }
  }

  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int q;
  cin >> q;

  while (q--) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    
    if (g[u][v] > 1000) cout << -1 << '\n';
    else cout << g[u][v] - 1 << '\n';
  }
}



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

int gcd(int n, int m) {
    int r;
    if (n < m) swap(n, m);
    
    while( m > 0 ){
        r = n % m;
        n = m;
        m = r;
    }
    return n;
}

int main(void){
    int n, x, y;
    cin >> n;
    cin >> x;
    for (int i = 0; i < n - 1; i++) {
        cin >> y;
        x = x * y / gcd(x, y);
    }
    cout << x << endl;;
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const lint INF = 1LL << 60;

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

    lint res = INF;

    for (lint i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res = min(res, i+(n/i)-2);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
c = n.times.map{gets.to_i}
dp = Array.new(n+1,0)
dp[0] = 1
a = Hash.new(-1)
mod = 10**9+7
n.times do |i|
    dp[i+1] = dp[i]
    if a[c[i]] != -1 && a[c[i]] != i-1
        dp[i+1] += dp[a[c[i]]+1]
        dp[i+1] %= mod
    end
    a[c[i]] = i
end
puts dp[n]

Measured memory_bytes: 17916
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#define MOD 1000000007
#define oo 987654321
#define INT long long int
using namespace std;

INT n, c, k, a[200010], ans;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>c>>k;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i];
    sort(a, a+n);
    for(int i = 0 ; i < n ; ans++ )
    {
        int f = a[i], cnt = 0;
        while( cnt < c and a[i]-f <= k and i < n ) cnt++, i++;
    }
    cout<<ans<<endl;
    return 0;
}


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, m;
    cin >> n >> m;
    vector<queue<ll>> g(n); // グラフ
    vector<bool> v(n, false); // 訪れたか
    vector<ll> ans(n); // 出力用
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push(b);
        g[b].push(a);
    }
    queue<ll> que;
    que.push(0);
    v[0] = true;
    while(!que.empty()) {
        ll t = que.front(); // t+1が道しるべ
        que.pop();
        while(!g[t].empty()) {
            ll tmp = g[t].front();
            g[t].pop();
            // 未到達点
            if(!v[tmp]) {
                ans[tmp] = t+1;
                v[tmp] = true;
                que.push(tmp);
            }
        }
    }
    cout << "Yes" << endl;
    frep(i, 1, n-1) {
        cout << ans[i] << endl;
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 72168
# -*- coding: utf-8 -*-

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

def sum_length(x, n):
    all_sum = 0
    prev_sum = 0
    for i in range(1, n):
        cur_sum = prev_sum + (x[i] - x[i-1]) * i
        all_sum = all_sum + cur_sum
        prev_sum = cur_sum
    return all_sum

sumx = sum_length(x, n)
sumy = sum_length(y, m)
print(sumx * sumy % 1000000007)

Measured memory_bytes: 18624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
  
class Main {
    public static void main(String[] args)throws IOException {
        //経過週の取得
        int n = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 64).readLine()); 

        //借金の金額
        int result = 100000;
          
        //n週後の借金の残高を演算する
        //一週間ごとに 5% の利子を借金に加え、さらに借金の 1,000 円未満を切り上げる。
        if (n != 0) {
            for(int i = 0; i < n;i++){
                //借金の5% を利子として追加
                result =(int)(result + (result * 0.05));
                //借金の 1,000 円未満を切り上げ
                if((result % 1000) != 0 ){
                    result = ((int)(result / 1000) + 1) * 1000;
                }
            }
        }
        //結果の出力
        System.out.println(result);
    }
}

Measured memory_bytes: 16836
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws Exception{
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y = input.nextInt();
        int z = input.nextInt();
        if(x < y && y < z){
            System.out.println("Yes");
        }else
            System.out.println("No");
    }
}

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

int main(){
    int n, m; cin >> n >> m;
    vector<pair<int, pair<int, int>>> p(m);
    vector<pair<int, int>> ans(m);
    for (auto i = 0; i < m; i++) { cin >> p[i].first >> p[i].second.first; p[i].second.second = i; }
    sort(p.begin(), p.end());
    int cnt = 1, prev = 0;
    for (auto & elm : p) {
        if(prev != elm.first) cnt = 1;
        else cnt++;
        prev = elm.first;
        ans[elm.second.second] = {elm.first, cnt};
    }
    cout << setfill('0') << right;
    for (auto & elm : ans) cout << setw(6) << elm.first << setw(6) << elm.second << endl;
    return 0;
}

Measured memory_bytes: 5108
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxv = 3e3+5;
int out[maxv],parent[maxv],leafchld[maxv];

int main()
{
    int a,b;
    while (cin >> a >> b) {
        int x = b;
        while (x) {
            x /= 10;
            a *= 10;
        }
        const int c = a+b;
        int good = 0;
        for (int i = 0; i*i <= c; i++) {
            if (i*i == c)
                good = 1;
        }
        if (good)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
s = sorted([int(input()) for _ in range(N)])

l10 = []
l = []

for i in s:
    if i%10:
        l.append(i)
    else:
        l10.append(i)

ss = l + l10
# print(s)
# print(ss)
if sum(ss)%10 == 0:
    while sum(ss)%10 == 0:
        # print(s)
        if ss:
            ss.pop(0)
        else:
            break
    ans = sum(ss)
else:
    ans = sum(ss)
print(ans)


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

typedef long long ll;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    int i;
    for(i = 0;i < n;++i){
        cin >> h.at(i);
    }
    sort(h.begin(),h.end());
    if(n <= k){
        cout << 0 << endl;
    }else{
        ll sum = 0;
        for(i = 0;i < n-k;++i){
            sum += h.at(i);
        }
        cout << sum << endl;
    }
    return 0;
}

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

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int, int>> data; //{市番号,県,年,内部順序}
    for(size_t i = 0; i < m; i++)
    {
        int p, y;
        scanf("%d %d", &p, &y);
        data.push_back(make_tuple(i + 1, p, y, -1));
    }
    int cnt[n+1] = {};

    sort(data.begin(), data.end(),
        [](tuple<int, int, int, int> l, tuple<int, int, int, int> r) {
            return get<2>(l) < get<2>(r);
        });
    
    for(size_t i = 0; i < m; i++)
    {
        cnt[get<1>(data[i])]++;
        data[i] = make_tuple(get<0>(data[i]), get<1>(data[i]), get<2>(data[i]), cnt[get<1>(data[i])]);
    }

    sort(data.begin(), data.end(),
         [](tuple<int, int, int, int> l, tuple<int, int, int, int> r) {
             return get<0>(l) < get<0>(r);
         });
    
    
    for(size_t i = 0; i < m; i++)
    {
        cout << setw(6) << setfill('0') << get<1>(data[i]) << setw(6) << setfill('0') << get<3>(data[i]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3568
// @idea:
//  dp(i, mask) : #ways of matching man i with women bitmask, mask
//                  given that [0, i-1] men already matched
//  dp(i, mask) = sum {dp(i - 1, mask.clear(j)) | j <- mask.ones, a[i][j] == 1}

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

const int NMAX = 21 + 2;
const int MOD  = 1e9 + 7;

int n, a[NMAX][NMAX];

int solve(void)
{
    vector<vi> dp(1LL << n, vi(n + 1, 0));

    dp[0][0] = 1;
    for (int mask = 1; mask < (1LL << n); ++mask)
    {
        for (int i = 1; i <= n; ++i)
        {
            if (__builtin_popcount(mask) != i)
                continue;
            for (int j = 1; j <= n; ++j)
            {
                if (((mask >> (j - 1)) & 1LL) and a[i - 1][j - 1])
                {
                    dp[mask][i] =
                        (dp[mask][i] + dp[mask ^ (1LL << (j - 1))][i - 1]) %
                        MOD;
                }
            }
        }
    }

    return dp[(1 << n) - 1][n];
}

int main(void)
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 248968
import java.io.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val n = nextLong()
    val set: MutableSet<Long> = mutableSetOf()
    var ans = 0

    for (i in 1L..n){
        if(i * i > n) break
        if(n % i == 0L){
            set.add(i)
            set.add(n / i)
        }
        if((n - 1) % i == 0L){
            set.add(i)
            set.add((n - 1) / i)
        }
    }

    for (k in set){
        if(k == 1L) continue
        var tmp = n
        while(tmp >= k){
            if(tmp % k == 0L){
                tmp /= k
            } else if(tmp % k == 1L) {
                tmp = 1L
            } else {
                break
            }
        }
        if(tmp == 1L) ans++
    }

    println(ans)
}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!

Measured memory_bytes: 35960
#include <iostream>
using namespace std;
int main(){
	int n,a[100000];
	cin >> n;
	for(int i=0 ; i<n ; i++ )
		cin >> a[i];
	int x=1,one[100000]={0},count=0;
	while(1){
		if(x==2){
			cout << count << endl;
			return 0;
		}
		if(one[x-1]==256){
			cout <<"-1"<<endl;
			return 0;
		}
		one[x-1]=256;
		x=a[x-1];
		count++;
	}
	return 0;
}

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

int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0) {if(a<b) swap(a,b); a = a%b;} return max(a,b);
}


int main(){
  int w,h,n;
  cin>>w>>h>>n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  rep(i,n) cin >> x[i] >> y[i] >> a[i];
  
  int u=h, d=0, r=w, l=0;
  rep(i,n){
    if(a[i]==1) l=max(l,x[i]);
    if(a[i]==2) r=min(r,x[i]);
    if(a[i]==3) d=max(d,y[i]);
    if(a[i]==4) u=min(u,y[i]);
  }
  int ans;
  if(r-l>0&&u-d>0) ans = (r-l)*(u-d);
  else ans = 0;
  
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

struct State
{
    int len;
    char c;
    pair<int, int> prev;
    State()
    {
        // Nothing to do here.
    }
    State(int len, char c, int i, int j) :
            len(len), c(c), prev(make_pair(i, j))
    {
        // Nothing to do here.
    }
};

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

    int t = 1;
    // cin >> t;
    while (t--)
    {
        string a, b;
        cin >> a >> b;

        int n = a.length();
        int m = b.length();

        State dp[n + 1][m + 1];

        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= m; j++)
            {
                if (!i || !j)
                    dp[i][j] = State(0,0,0,0);
                else if (a[i - 1] == b[j - 1])
                    dp[i][j] = State(dp[i - 1][j - 1].len + 1, a[i - 1], i - 1, j - 1);
                else
                {
                    if (dp[i - 1][j].len > dp[i][j - 1].len)
                        dp[i][j] = State(dp[i - 1][j].len,
                                    '$', i - 1, j);
                    else
                        dp[i][j] = State(dp[i][j - 1].len,
                                    '$', i, j - 1);
                }
            }
        }

        State curr = dp[n][m];
        stack<char> s;
        for (curr; curr.c != 0; curr = dp[curr.prev.first][curr.prev.second])
            if (curr.c != '$')
                s.push(curr.c);
        while (!s.empty())
        {
            cout << s.top();
            s.pop();
        }
    }
    return 0;
}

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

int main(){
  int n,temp,sum=0;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x.at(i);
  rep(i,n){
    cin >> temp;
    if(x.at(i)-temp > 0) sum += x.at(i)-temp;
  }
  cout << sum << endl;
  return 0;
}

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

int main(void){
	const int MAXNUM = 20;
	const int MAXN = 100;
	int N;
	long long dp[MAXN][MAXNUM+1];
	int nums[MAXN];

	// init
	for(int i=0; i<MAXN; i++){
		for(int j=0; j<=MAXNUM; j++){
			dp[i][j] = 0;
		}
	}

	// in
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> nums[i];
	}

	// calc
	dp[0][nums[0]] = 1;
	for(int i=0; i<N-2; i++){
		for(int j=0; j<=MAXNUM; j++){
			if( dp[i][j] == 0 )
				continue;

			for(int k=0; k<2; k++){
				int temp = k ? j + nums[i+1] : j - nums[i+1];
				if( temp < 0 || MAXNUM < temp )
					continue;
				dp[i+1][temp] += dp[i][j];
			}
		}
	}

	// out
	cout << dp[N-2][nums[N-1]] << endl;
	
	return 0;
}

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

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

  int p=max(n,m), q=min(n,m);
  if(p-q>1){cout<<0; return 0;}

  mint ans=1;
  rep(i,p) ans*=(i+1);
  rep(i,q) ans*=(i+1);

  if(p==q) ans*=2;
  cout << ans;
}

Measured memory_bytes: 3620
#include <stdio.h>
 
int main(void){
	int a;
	char s[100];
  scanf("%d", &a);
  scanf("%s", s);
  
  if(3200 <= a && a <= 5000)
  {printf("%s", s);}
else if (2800 <= a && a < 3200)
{printf("red");}
  else {printf("nothing");}
  return 0;
}

Measured memory_bytes: 128
<?php
$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$p = (int)$input[1];

$max = floor(sqrt($p));
$as = [];

if ($n === 1) {
	echo $p;
	exit();
}
for ($i=2; $i <= $max; $i++) { 
	while ( $p % $i === 0) {
		if (empty($as[$i])) {
			$as[$i] = 1;
		}else{
			$as[$i] += 1;
		}
		$p = floor($p/$i);
	}
}
$min = 1;
foreach ($as as $key => $value) {
	if ($value >= $n) {
		$jo = floor($value / $n);
		$min *= pow($key, $jo);
	}
}
echo $min;

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

#define PRINT(x) cout << x << endl;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(vec) vec.begin(), vec.end()

using namespace std;
typedef long long ll;

ll N, K;
int main() {
	cin >> N >> K;

	vector<ll> A;
	vector<ll> F;

	REP(i, N) {
		ll tmp;
		cin >> tmp;
		A.push_back(tmp);
	}

	REP(i, N) {
		ll tmp;
		cin >> tmp;
		F.push_back(tmp);
	}

	sort(ALL(A));
	sort(ALL(F));
	reverse(ALL(A));

	ll l = 0, r = A[0] * F[N - 1];
	ll mid = 0;

	while (l < r) {
		mid = (l + r) / 2;
		ll k = K;

		REP(i, N) {
			ll a = A[i], f = F[i];
			if (a * f <= mid) continue;

			ll x = ceil(-mid / f + a);

			k -= x;
			if (k < 0) break;
		}
		if (k < 0) l = mid + 1;
		else r = mid;
	}

	PRINT(r);

	return 0;
}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		int tmp = 0;
		int div = i;
		while (div) {
			tmp += div % 10;
			div /= 10;
		}
		if (A <= tmp && tmp <= B) {
			sum += i;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	cin >> N >> M;

	vector<int> ans(N, 0);
	for (int i = 0; i < M * 2; i++)
	{
		int tmp;
		cin >> tmp;
		ans[tmp - 1]++;
	}

	for (auto out : ans)
	{
		cout << out << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = []
h = list(map(int, input().split()))
ans = [0]*n
for i in range(m):
  a, b = map(int, input().split())
  if h[a-1] > h[b-1]:
    ans[b-1] = 1
  elif h[a-1] < h[b-1]:
    ans[a-1] = 1
  else:
    ans[a-1] = 1
    ans[b-1] = 1

print(ans.count(0))

Measured memory_bytes: 20120
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

int dp[100100][3];

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

	int N=in();
	
	for(int day=0;day<N;day++){
		int a[3];
		a[0]=in(),a[1]=in(),a[2]=in();
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(i==j) continue;
				chmax(dp[day+1][i],dp[day][j]+a[i]);
			}
		}
	}
	
	cout << *max_element(dp[N],dp[N]+3) << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
vector<int> operator*(const vector<int> &lhs, vector<int> rhs) {
    for (int &i : rhs)
        i = lhs[i];
    return rhs;
}
vector<int> inverse(const vector<int> &a) {
    vector<int> b(a.size());
    for (int i = 0; i < a.size(); ++i)
        b[a[i]] = i;
    return b;
}
vector<int> power(vector<int> a, int k) {
    vector<bool> visited(a.size());
    for (int i = 0; i < a.size(); ++i) {
        if (visited[i])
            continue;
        vector<int> b;
        for (int j = i; !visited[j]; visited[j] = true, j = a[j])
            b.push_back(j);
        for (int j = 0; j < b.size(); ++j)
            a[b[j]] = b[(j + k) % b.size()];
    }
    return a;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    --k;
    vector<int> p(n), q(n);
    for (int &i : p) {
        cin >> i;
        --i;
    }
    for (int &i : q) {
        cin >> i;
        --i;
    }
    vector<int> a, b;
    a = power(q * inverse(p) * inverse(q) * p, k / 6);
    vector<vector<int>> c(6);
    c[0] = a * p * inverse(a);
    c[1] = a * q * inverse(a);
    for (int i = 2; i < 6; ++i)
        c[i] = c[i - 1] * inverse(c[i - 2]);
    for (int i : c[k % 6])
        cout << i + 1 << " \n"[i == c[k % 6].back()];
    return 0;
}

Measured memory_bytes: 4356
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int main()
{
  int64_t N, M;
  vector<int64_t> A;

  cin >> N >> M;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end(), std::greater<int>());
  int64_t sum = accumulate(A.begin(), A.end(), 0LL);

  int64_t item_count = 0;
  for (auto &&i : A) {
    if (i * 4 * M >= sum) {
      item_count++;
    }
    else {
      break;
    }
  }

  if (item_count >= M) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    for(int i=0; i<n; ++i)
        cin >> b[i];

    if(accumulate(a.begin(), a.end(), 0LL) < accumulate(b.begin(), b.end(), 0LL)){
        cout << -1 << endl;
        return 0;
    }
    
    long long sum = 0;
    int ans = 0;
    vector<int> v;
    for(int i=0; i<n; ++i){
        if(a[i] < b[i]){
            sum += b[i] - a[i];
            ++ ans;
        }
        else{
            v.push_back(a[i] - b[i]);
        }
    }
    sort(v.rbegin(), v.rend());

    for(int i=0; sum>0; ++i){
        sum -= v[i];
        ++ ans;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
ll n,len=1;
string s="";

signed main(){
	cin>>n;
/*	while(n){
		n--;
		s+=char('a'+n%26);
		n/=26;
	}*/
	while(n>pow(26,len)){
		n-=pow(26,len);
		len++;
	}n--;
	for(int i=0;i<len;i++){
		s+=char('a'+n%26);
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}


Measured memory_bytes: 4036
#b
n=int(input())
a=list(map(int,input().split()))

ans=1
for aa in a:
    if aa%2==0:
        if aa%3==0 or aa%5==0:
            pass
        else:
            ans=0
    
if ans==1:
    print("APPROVED")
else:
    print("DENIED")

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

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int [] game = new int [N];
		int [] vote = new int [N];
		int M = in.nextInt();
		int [] member = new int [M];
		for(int i = 0; i < N; i++){
			game[i] = in.nextInt();
		}
		for(int i = 0; i < M; i++){
			member[i] = in.nextInt();
		}
		for(int i = 0; i < M; i++){
			for(int k = 0; k < N; k++){
				if(game[k] <= member[i]){
					vote[k]++;
					break;
				}
			}
		}
		int max = 0;
		int idx = 0;
		for(int i = 0; i < N; i++){
			if(max < vote[i]){
				max = vote[i];
				idx = i;
			}
		}
		System.out.println(idx + 1);
	}

}

Measured memory_bytes: 25284
#include<bits/stdc++.h>
using namespace std;
#define maxn 40005
#define inf 1e9
int n,med,sz;
double a[maxn], b[maxn], c[maxn];
pair<double,double> p[maxn];
int tree[maxn];
map<double,int> mp;

void cpidx() {
    int i;
    map<double,int>::iterator it;
    mp.clear(); sz = 0;
    for(i=1;i<=n;i++) mp[p[i].second];
    for(it=mp.begin();it!=mp.end();++it) it->second = ++sz;
    for(i=1;i<=n;i++) p[i].second = mp[p[i].second];
}

void add(int x,int val) {
    while(x<=sz) {
        tree[x] += val;
        x += x&-x;
    }
}

int sum(int x) {
    int ans = 0;
    while(x>0) {
        ans += tree[x];
        x -= x&-x;
    }
    return ans;
}

bool check(double x) {
    int i,cnt = 0;
    int ans = 0;
    for(i=1;i<=n;i++) p[i] = {(c[i]-x*a[i])/b[i],-a[i]/b[i]};
    cpidx();
    sort(&p[1],&p[n+1]);
    memset(tree,0,sizeof(tree));
    for(i=1;i<=n;i++) {
        ans += sum(p[i].second);
        add(p[i].second,1);
    }
    return (ans>=med);
}

main() {
    int i;
    double l,r,mid,ansx,ansy;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
    med = (n*(n-1)/2 + 1)/2;
    //X
    l = -inf; r = inf;
    for(i=0;i<80;i++) {
        mid = (l+r)/2;
        if(check(mid)) {
            ansx = mid;
            r = mid;
        }
        else l = mid;
    }
    //Y
    for(i=1;i<=n;i++) swap(a[i],b[i]);
    l = -inf; r = inf;
    for(i=0;i<80;i++) {
        mid = (l+r)/2;
        if(check(mid)) {
            ansy = mid;
            r = mid;
        }
        else l = mid;
    }
    printf("%.15lf %.15lf",ansx,ansy);
}


Measured memory_bytes: 4608
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''

N = int(input())
H = int(input())
W = int(input())

print((N-H+1)*(N-W+1))

Measured memory_bytes: 5344
from bisect import bisect_left, bisect_right # 2文探索法モジュール
N = int(input())
a = sorted(list(map(int, input().split()))) # ソートしておく
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split()))) # ソートしておく

count = 0
for b_item in b:
    i = bisect_left(a, b_item) # リストaのb_itemより小さい要素の数
    j = N - bisect_right(c, b_item) # リストcのb_itemより大きい要素の数
    count += (i * j)
print(count)


Measured memory_bytes: 24224