akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

#define ll long long

using namespace std;

int 
main() {

  ll n, k;
  cin>>n>>k;

  vector<ll> a(n);
  for (int i=0; i<n; i++) 
    cin>>a[i];
  sort(a.begin(), a.end());

  vector<ll> f(n);
  for (int i=0; i<n; i++)
    cin>>f[i];
  sort(f.begin(), f.end(), greater<ll>());

  ll start = -1, end = 1e12 + 1;
  while (1) {
    if (start + 1 == end) break;

    ll mid = (start + end) / 2;
    ll now = k;

    for (int i=0; i<n; i++) {
      ll need = mid / f[i];
      if (need < a[i])
        now -= a[i] - need;
      if (now < 0)
        break;
    }

    if (now < 0)
      start = mid;
    else
      end = mid;
  }

  cout<<end<<endl;
  return 0;
}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};


signed main(){

    int n; cin >> n;
    int ans = 0;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    int sum = 0;

    for(int i = 0; i < n; i++){
        if(a[i] < b[i]){
            ans++;
            sum += b[i] - a[i];
            a[i] = -1;
        }
    }

    vector<int> p;
    for(int i = 0; i < n; i++){
        if(a[i] != -1){
            p.push_back(a[i] - b[i]);
        }
    }

    int m = (int)p.size();
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    for(int i = 0; i < m; i++){
        if(sum <= 0) break;
        sum -= p[i];
        ans++;

    }

    if(sum <= 0) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 2936
#!/usr/bin/env python3
import os
from sys import stdin, stdout

MOD = int(1e9) + 7

def solve(tc):
    s = int(stdin.readline().strip())

    dp = [0 for i in range(2001)]
    dp[0] = 1
    dp[1] = dp[2] = 0
    dp[3] = dp[4] = dp[5] = 1
    for i in range(6, s+1):
        for j in range(3, i+1):
            dp[i] += dp[i-j]
            dp[i] %= MOD
    
    print(dp[s])


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1


Measured memory_bytes: 65260
#include <bits/stdc++.h>
#define NMAX 200005
#define LOGMAX (int)log2(NMAX)+2
#define MOD 998244353
/*#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
*/
using namespace std;
typedef long long ll;
vector<ll> edg[NMAX];
bool visited[NMAX];
void dfs(ll x){
    visited[x]=1;
    for(auto it : edg[x]){
        if(!visited[it]){
            visited[it]=1;
            dfs(it);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,m,scc=0;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    for(ll i=1;i<=n;i++){
        if(!visited[i]){
            scc++;
            dfs(i);
        }
    }
    cout<<scc-1;
    return 0;
}


Measured memory_bytes: 12780
#include <stdio.h>
int main(){
    int a,b,c;
    int x = a;
    int i = 0;

    scanf("%d %d %d",&a,&b,&c);

    for(x = a; x <= b; x++ ){
        if (c % x == 0){
            i = i + 1;
        }
    }
    
    printf("%d\n",i);

    return 0;
}

Measured memory_bytes: 596
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = sc.nextInt();
		Arrays.sort(p);
		int s = 0;
		for (int i = 0; i < N - 1; i++)
			s += p[i];
		s += p[N - 1]/2;
		System.out.println(s);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22996
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    bool judge = true;
    int n;
    vector<string> w;
    string tmp;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> tmp;
        w.push_back(tmp);
    }
    for(int i = 0;i < n - 1;i++)
    {
        if(w[i][w[i].size() - 1] != w[i + 1][0])
        {
            judge = false;
            break;
        }
        for(int j = i + 1;j < n;j++)
        {
            if(w[i] == w[j]){judge = false; break;}
        }
    }
    if(judge){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl;exit(0);}


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

    ll n;
    cin >> n;
    vector <ll> a(n + 1);

    for(int i = 1; i < n; i++)cin >> a[i];

    ll ans = a[1];

    for(int i = 1; i < n - 1; i++)ans += min(a[i], a[i + 1]);

    ans += a[n - 1];
    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int havecard;
    int card[4][13] = {0};
    int i;
    char mark = 0;
    int number = 0;
    int j;
    scanf("%d",&havecard);
    for(i=1;i<=havecard*2;i++){
        scanf("%c %d",&mark,&number);
        if(mark=='S'){
            card[0][number-1]=1;
        }
        if(mark=='H'){
            card[1][number-1]=1;
        }
        if(mark=='C'){
            card[2][number-1]=1;
        }
        if(mark=='D'){
            card[3][number-1]=1;
        }
    }
    /*for(i=0;i<=3;i++){
        for(j=0;j<=12;j++){
            printf("%d",card[i][j]);
        }
        printf("\n");
    }*/
    for(i=0;i<=3;i++){
        if(i==0){
            mark = 'S';
            for(j=0;j<=12;j++){
                if(card[i][j]==0){
                    printf("%c %d\n",mark,j+1);
                }
            }
        }
         if(i==1){
            mark = 'H';
            for(j=0;j<=12;j++){
                if(card[i][j]==0){
                    printf("%c %d\n",mark,j+1);
                }
            }
        }
         if(i==2){
            mark = 'C';
            for(j=0;j<=12;j++){
                if(card[i][j]==0){
                    printf("%c %d\n",mark,j+1);
                }
            }
        }
         if(i==3){
            mark = 'D';
            for(j=0;j<=12;j++){
                if(card[i][j]==0){
                    printf("%c %d\n",mark,j+1);
                }
            }
        }
    }
    return 0;
}

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

using namespace std; 
#define fr for(int i = 0;i < n;i++)
#define pb push_back
#define ll long long int 
void printVector(vector<int>x){
    for(auto i:x){
        cout << i << endl;
    }
    cout << endl;
}
string reverseString(string str,int n){
    string res = "";
    for (int i = n-1; i >= 0; i--)
    {
        res += str[i];
       
    }
    return res;
    
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
        int n,x;
        string str;
        cin >> n;
        map<string,int>mapping;

        for (int i = 0; i < n; i++)
        {
            cin >> str;
            mapping[str]++;
        }
        cout << "AC" << " x " << mapping["AC"] << endl;
        cout << "WA" << " x " << mapping["WA"] << endl;
        cout << "TLE" << " x " << mapping["TLE"] << endl;
        cout << "RE" << " x " << mapping["RE"] << endl;
   
    

}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

//階乗先に計算
long long int kaizyou[200005] = { 1 };
long long int kai(long long int a, long long int b, long long int mod) {
	long long int tmp = 1;
	for (long long int i = a; i <= b; i++) {
		tmp *= i;
		tmp %= mod;

		kaizyou[i] = tmp;
	}
	return tmp;
}


//累乗(繰り返し2乗法)　aのb乗(mod)を求める。
long long int rui(long long int a, long long int b, long long mod) {
	int memo[65] = {};
	long long int A[65] = {};
	long long int tmp = 1;
	for (int i = 0; i < 65; i++) {
		memo[i] = b % 2;
		b /= 2;
	}

	A[0] = a;
	A[0] %= mod;

	for (int i = 1; i < 65; i++) {
		A[i] = A[i - 1] * A[i - 1];
		A[i] %= mod;
	}
	for (int i = 0; i < 65; i++) {
		if (memo[i] == 1) {
			tmp *= A[i];
			tmp %= mod;
		}
	}
	tmp %= mod;
	return tmp;
}

//コンビネーション計算
long long int comb(long long int n, long long int r, long long int mod) {
	long long int tmp;

	tmp = (kaizyou[n] * rui(kaizyou[r], mod - 2, mod)) % mod;
	tmp *= rui(kaizyou[n - r], mod - 2, mod);
	tmp %= mod;
	if (tmp < 0) { tmp = (mod - tmp) % mod; }
	return tmp;
}


int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n, a, b, c, d, dp[1005][1005] = {}, RUI[1005][1005];
	cin >> n >> a >> b >> c >> d;
	kai(1, 1400,mod);

	for (int i = 0; i <= 1000; i++) {
		for (int j = 0; j <= 1000; j++) {
			RUI[i][j] = rui(kaizyou[i], mod - j - 1, mod);
		}
	}

	dp[a - 1][n] = 1;
	for (int i = a; i <= b; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] += dp[i - 1][j];
			for (int k = c; k * i <= j && k <= d; k++) {
				long long int tmp = kaizyou[j] * RUI[i][k];
				tmp %= mod;
				tmp *= RUI[j - i * k][1];
				tmp %= mod;
				tmp *= RUI[k][1];
				tmp %= mod;
				dp[i][j - i * k] += dp[i - 1][j] * tmp;
				dp[i][j - i * k] %= mod;
			}
		}
	}
	cout << dp[b][0] << endl;

}


Measured memory_bytes: 16000
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var ans = 0
    for (n in 1..N step 2) {
        var cnt = 0
        for (i in 1..n) {
            if (n % i == 0) cnt++
        }
        if (cnt == 8) ans++
    }
    println(ans)
}

Measured memory_bytes: 33604
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 107;
int n, c, k, t, a, b;
char s[N];

int main() {
	rds(s, n), rd(k);
	for (int l = 1, r = 1; l <= n; l = ++r) {
		while (s[r+1] == s[l]) ++r;
		t += (r - l + 1) >> 1, ++c;
		if (!a) a = r - l + 1;
		b = r - l + 1;
	}
	if (s[1] != s[n]) print(1ll * k * t);
	else if (c == 1) print((1ll * n * k) >> 1);
	else {
		t -= (a >> 1) + (b >> 1);
		t += (a + b) >> 1;
		print(1ll * k * t - ((a & 1) && (b & 1)));
	}
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <math.h>

int main() {

  double a,b,c;
  double S,L2, L, h;

  scanf("%lf %lf %lf",&a,&b,&c);

  S = 0.5*a*b*sin(c*3.14159265359/180);
  L2 = a*a+b*b-2*a*b*cos(c*3.1415926359/180);
  L = sqrt(L2)+a+b;
  h = 2*S/a;

  printf("%.11lf\n%.11lf\n%.11lf\n",S ,L,h); 

  return 0;
}


Measured memory_bytes: 2948
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int main(){

   int N;
   cin >> N;
   int r = N;
   int sum = 0;
   while(N){
	   sum += N%10;
	   N = N/10;
   }

   if(r%sum == 0){
	   cout << "Yes" << endl;
   }else{
	   cout << "No" << endl;
   }

   return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,q,i,j,ind;
    cin>>n>>k>>q;
    int a[q],b[n];
    for(i=1; i<=n; i++)
        b[i]=k;
    for(i=1; i<=q; i++)
    {
        cin>>a[i];
        ind=a[i];
        b[ind]+=1;
    }
    for(j=1; j<=n; j++)
    {
        b[j]-=q;
    }

    for(i=1; i<=n; i++)
    {
        if(b[i]>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>

char s[100000];
int k;

int distance(char c){
  if(c=='a') return 0;
  else return 123-c;
}

int main(){
  scanf("%s",s);
  scanf("%d",&k);
  int i=0;
  while(s[i]!='\0'){
    if(distance(s[i])<=k){
      k-=distance(s[i]);
      s[i] = 'a';
    }
    i++;
  }
  if(k>0){
    if(s[i-1]+k%26>122) s[i-1] = s[i-1]+k%26-26;
    else s[i-1]+=k%26;
  }
  printf("%s\n",s);
  return 0;
}


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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923

int main()
{
    boost;
    time_t tic, toc;

    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, d, h, w, u, v, x, y;
    ll l = 0, r = 0;
    ll ans = 0;

    bool poss = true;

    string s;

    // cin >> tt;
    tic = clock();
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> n;
        vi arr(n);

        ll txor = 0;
        loop(z, arr) cin >> z, txor ^= z;

        for(i = 0; i < n; i++){
            cout << (txor^arr[i]) sps;
        }
    } 
    // cerr << (clock() - tic*1.0) / CLOCKS_PER_SEC << nl;
    return 0;
}

Measured memory_bytes: 4788
#include <iostream>
using namespace std;
int main() {
    string n;
    cin >> n;
    int cnt = 0;
    for (int i=0; i<(int)n.length(); i++) {
        cnt += (int)(n[i]-'0');
        cnt %= 9;
    }
    cout << ((cnt==0)? "Yes" : "No") << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int happy = 0;
    for (int i = 0; i+1 < n; ++i) {
        if (s[i] == s[i+1]) {
            ++happy;
        }
    }
    cout << min(happy + 2*k, n-1) << endl;
    return 0;
}


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

int main(){
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n,vector <int> (d));
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x.at(i).at(j);
        }
    }
    int ans=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                sum+=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
            }
                int c=sqrt(sum);
                int b=c;
                //cout<<i<<","<<j<<" ";
                if(b*b==sum){
                    ans++;
                    //cout<<b<<endl;
                }
                else{
                    //cout<<"n"<<b<<endl;
                }
            
        }
    }
    cout<<ans<<endl;
                
            
}

Measured memory_bytes: 256
r, g, b, n = gets.split.map(&:to_i)
rs = (0..n).map{|x| x%r==0 ? 1 : 0}
rgs = (0..n).map{|y| (0..y/g).map{|t|rs[y-t*g]}.reduce(:+)}
p (0..n/b).map{|t| rgs[n-t*b]}.reduce(:+)

Measured memory_bytes: 20348
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := 0
	for i := 1; i <= n; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main(void)
{
	int n, k;
	scanf("%d %d",&n, &k);
	int *h;
	h = (int *)malloc(sizeof(int)*(n));
	int i = 0;
	while (i < n)
	{
		scanf("%d",&h[i]);
		i++;
	}
	int sum = 0;
	i = 0;
	while (i < n)
	{
		if(h[i] >= k)
		{
			sum++;
		}
		i++;
	}
	printf("%d\n",sum);
	return (0);
}


Measured memory_bytes: 512
class BIT():
  def __init__(self,n):# 0-indexed
    self.n=n
    self.bit=[0]*(n+1)
  def add(self,i,x):
    i+=1
    while i<=self.n:
      self.bit[i]+=x
      i+=i&-i
  def _sum(self,i):
    s=0
    while i>0:
      s+=self.bit[i]
      i-=i&-i
    return s
  def get(self,i,j):# get sum between [i,j)
    return self._sum(j)-self._sum(i)
n,k=map(int,input().split())
a=[int(input()) for i in range(n)]
cumsum_a=[0]*(n+1)
for i in range(n):
  cumsum_a[i+1]=cumsum_a[i]+a[i]
for i in range(n+1):
  cumsum_a[i]-=k*i
  
def compress(list1):
  list2=sorted(set(list1))
  memo={value:index for index,value in enumerate(list2)}
  for i in range(len(list1)):
    list1[i]=memo[list1[i]]
  return list1
cumsum_a=compress(cumsum_a)
bit=BIT(n+1)
ans=0
for i in range(n+1):
  ans+=bit.get(0,cumsum_a[i]+1)
  bit.add(cumsum_a[i],1)
print(ans)

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

int main() {
  int n,k;
  cin >> n >> k;
  if(n % k != 0) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,ans=0;
    cin>>n;
	for(int i=1,a,b;i<=n;i++)
	{
		cin>>a>>b;
		ans+=abs(a-b)+1;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
	readLine()
	val v = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	val c = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	var sum = 0
	for (i in v.indices) if (v[i] - c[i] > 0) sum += v[i] - c[i]
	println(sum)
}

Measured memory_bytes: 37832
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;

signed main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    std::ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> *gr = new vector<int>[n + 1];
    vector<int> ans(n + 1, 0);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        gr[a].push_back(b);
        gr[b].push_back(a);
    }
    queue<int> q;
    q.push(1);
    while (q.size() > 0) {
        int x = q.front();
        q.pop();
        for (auto i : gr[x]) {
            if (ans[i] == 0) {
                ans[i] = x;
                q.push(i);
            }
        }
    }
    bool f = true;
    for (int i = 2; i <= n; i++) {
        if (ans[i] == 0) {
            f = false; break;
        }
    }
    if (!f) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int i = 2; i <= n; i++) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 13056
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,k;
	cin>>n>>k;
	int d[k];
	bool f[n];
	fill(f,0);
	rep(i,k){
		cin>>d[k];
		rep(j,d[k]){
			int a;
			cin>>a;
			f[a-1]=1;
		}
	} 
	int cnt=0;
	rep(i,n){
		if(!f[i]){
			cnt++;
		}
	}
	cout<<cnt;
	re 0;
}

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

int main() {
	string tw, hw;	
	int c, r, ts = 0, hs = 0;
	cin >> c;
	while (c--) {
		cin >> tw >> hw;
		r = tw.compare(hw);
		if (r > 0) ts += 3;
		else if (r < 0) hs += 3;
		else ts++, hs++;
	}
	cout << ts << " " << hs << endl;
	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<stdlib.h>
#define c 10001

void CountingSort(int *,int *,int);
int N;

int main(){
  int i,k=0;
  int *A,*B;

  scanf("%d",&N);

  A=(int*)malloc((N+1)*sizeof(int));
  B=(int*)malloc((N+1)*sizeof(int));
  for(i=1;i<=N;i++){
    scanf("%d",&A[i]);
    if(k<A[i]){
      k=A[i];
    }
  }
  CountingSort(A,B,k);
  return 0;
}

void CountingSort(int *A,int *B,int k){
  int i,j,C[c];

  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=N;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=N;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=N;i++){
    if(i==N){
      printf("%d\n",B[i]);
    }
    else{
      printf("%d ",B[i]);
    }
  }
}
  

  



Measured memory_bytes: 17420
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	H:=readInt()
	W:=readInt()
	A:=make([][]byte, H)
	count := 0
	for i:=range A{
		A[i] = readBytes()
		for j:=range A[i]{
			if A[i][j] == '#' {
				count++
			}
		}
	}
	if count == H+W-1 {
		println("Possible")
	} else{
		println("Impossible")
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vi v(n);
	rep(i,0,n)cin >> v[i];
	sort(all(v));
	int x = (n-1)/2;
	cout << v[x+1] - v[x] << '\n';
}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int N, K;

struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

vector<int> dist;

bool bellman_ford(int n, int s) {
    dist = vector<int>(n, INF);
    dist[s] = 0;
    REP(i, n){
        REP(v, n){
            REP(k, graph[v].size()) {
                Edge e = graph[v][k];

                if(dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = dist[v] + e.cost;
                    if(i == n-1) return true;
                }
            }
        }
    }
    return false;
}

int main() {
    //cout << fixed << setprecision(15);

    int V, E, r; cin >> V >> E >> r;

    graph = AdjList(V);

    REP(i, E){
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back(Edge(t, d));
    }

    if(bellman_ford(V, r)){
        cout << "NEGATIVE CYCLE" << endl;
    }else{
        for(int i=0; i<V; ++i){
            if(dist[i]==INF){
                cout << "INF" << endl;
            }else
                cout << dist[i] << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3152
import java.util.*;

class DFS {
	
	public static int totalVertex;
	public static LinkedList<LinkedList<Integer>> adjList;
	public static int[] d;
	public static int[] f;
	//adjacency list of edges
	public DFS() { 
		totalVertex = 0;
		}
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		d = new int[totalVertex];
		f = new int[totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			d[i] = -1;
			f[i] = -1;
		}
		in.close();
	}
	
	public static int getDFS(int vertex, int time) {
		LinkedList<Integer> adjacencies = adjList.get(vertex);
	
			d[vertex] = time;
		
			for (int adj : adjacencies) {
				if(d[adj] == -1) {
					time = getDFS(adj, time+1);
				}
			}
		
		
		f[vertex] = time + 1;
		
		return time + 1;
	}
}

public class Main {

	public static void main(String[] args) {
		DFS g = new DFS();
		g.loadAdjList();
		int time = 1;
		for (int i = 0; i < g.totalVertex; i++) {
			if(g.d[i] == -1) {
				time = g.getDFS(i, time) + 1;
			}
		}
		for (int i = 1; i < g.totalVertex + 1; i++) {
			System.out.println(i + " " + g.d[i - 1] + " " + g.f[i - 1]);
		}
	}

}



Measured memory_bytes: 28300
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=0,n=0,k=0;
        n=sc.nextInt();
        k=sc.nextInt();
        int a[]=new int[n];
        int dp[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
            dp[i]=1000000000;
        }
        
        dp[0]=0;
        for(int i=0;i<n;i++)
        {
            for(int j=1;j<=k;j++)
            {
                if(i+j<n)
           dp[i+j]=Math.min(dp[i+j],(dp[i]+Math.abs(a[i+j]-a[i])));
        }
    }
     System.out.println(dp[n-1]);
}
}


Measured memory_bytes: 50772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const ld Pi=acos(-1);
int main(){
  char N;
  cin>>N;
  if(N=='a')cout<<"b"<<endl;
  if(N=='b')cout<<"c"<<endl;
  if(N=='c')cout<<"d"<<endl;
  if(N=='d')cout<<"e"<<endl;
  if(N=='e')cout<<"f"<<endl;
  if(N=='f')cout<<"g"<<endl;
  if(N=='g')cout<<"h"<<endl;
  if(N=='h')cout<<"i"<<endl;
  if(N=='i')cout<<"j"<<endl;
  if(N=='j')cout<<"k"<<endl;
  if(N=='k')cout<<"l"<<endl;
  if(N=='l')cout<<"m"<<endl;
  if(N=='m')cout<<"n"<<endl;
  if(N=='n')cout<<"o"<<endl;
  if(N=='o')cout<<"p"<<endl;
  if(N=='p')cout<<"q"<<endl;
  if(N=='q')cout<<"r"<<endl;
  if(N=='r')cout<<"s"<<endl;
  if(N=='s')cout<<"t"<<endl;
  if(N=='t')cout<<"u"<<endl;
  if(N=='u')cout<<"v"<<endl;
  if(N=='v')cout<<"w"<<endl;
  if(N=='w')cout<<"x"<<endl;
  if(N=='x')cout<<"y"<<endl;
  if(N=='y')cout<<"z"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b="CODEFESTIVAL2016";
int ans;
int main()
{
	cin>>a;
	for(int s=0;s<16;s++)
	{
		if(a[s]!=b[s])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int r;

  cin >> r;

  if(r < 1200){
    cout << "ABC" << endl;
  }else if(r < 2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
  return 0;
}


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

using namespace std;

int N, M;
bool feeld[25][25];

void solve() {
	int x = 10, y = 10;
	for (int i = 0; i < M; i++) {
		char c;
		int d;
		
		cin >> c >> d;
		if (c == 'N') {
			for (int j = 0; j < d; j++) {
				feeld[++y][x] = 0;
			}
		}
		if (c == 'E') {
			for (int j = 0; j < d; j++) {
				feeld[y][++x] = 0;
			}
		}
		if (c == 'S') {
			for (int j = 0; j < d; j++) {
				feeld[--y][x] = 0;
			}
		}
		if (c == 'W') {
			for (int j = 0; j < d; j++) {
				feeld[y][--x] = 0;
			}
		}
	}
	
	bool isok = true;
	for (int i = 0; i <= 20; i++) {
		for (int j = 0; j <= 20; j++) {
			isok *= !feeld[i][j];
		}	
	}
	
	if (isok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main() {
	while (1) {
		cin >> N; if (N == 0) break;
		
		memset(feeld, 0, sizeof(feeld));
		for (int i = 0; i < N; i++) {
			int x, y; cin >> x >> y;
			feeld[y][x] = 1;
		}
		
		cin >> M;
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(abs(a-b)<=w){
        cout<<0<<endl;
    }else{
        cout<<min(abs(a-(b+w)),abs(b-(a+w)))<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll dp[100010][3];
ll hap[100010][3];

void solve() {

	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> hap[i][0] >> hap[i][1] >> hap[i][2];
	}

	dp[1][0] = hap[1][0];
	dp[1][1] = hap[1][1];
	dp[1][2] = hap[1][2];
	for (int i = 2; i <= N; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j] = -1;
			for (int k = 0; k < 3; k++) {
				if (j == k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + hap[i][j]);
			}
		}
	}

	cout << max({ dp[N][0], dp[N][1], dp[N][2] }) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 4992
using System;

class AOJ {
    static void Main()
    {
        double ans = 100000;
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
            ans = Math.Ceiling(ans * 1.05 / 1000) * 1000;

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 9116
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var a = IO.RSInt;

            var b = new int[n];
            if (n % 2 == 0)
            {
                for (int i = 0; i < n / 2; i++)
                {
                    b[i] = a[(n - 1) - 2 * i];
                }
                for (int i = 0; i < n / 2; i++)
                {
                    b[i + n / 2] = a[2 * i];
                }
                IO.OutJoinSpace(b);
            }
            else
            {
                for (int i = 0; i < n / 2 + 1; i++)
                {
                    b[i] = a[(n - 1) - 2 * i];
                }
                for (int i = 0; i < n / 2; i++)
                {
                    b[i + n / 2 + 1] = a[1 + 2 * i];
                }
                IO.OutJoinSpace(b);
            }
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 48440
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

        while (input.hasNext()) {
        	int N = input.nextInt();
        	int M = input.nextInt();
			ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>(N + 1);
        	
        	for (int i = 0; i < N + 1; ++i) {
        		g.add(new ArrayList<Integer>());
        	}
        	
        	for (int i = 0; i < M; ++i){
        		int A = input.nextInt();
        		int B = input.nextInt();
        		
        		g.get(A).add(B);
        		g.get(B).add(A);
        	}
        	
        	int[] nextRoom = new int[N + 1];
        	Arrays.fill(nextRoom, -1);
        	Queue<Integer> q = new LinkedList<Integer>();
        	q.add(1);
        	
        	while (q.isEmpty() == false) {
        		int currentRoom = q.poll();
        		ArrayList<Integer> neighborRoom = g.get(currentRoom);
        		
        		for (int i = 0; i < neighborRoom.size(); ++i) {
        			if (nextRoom[neighborRoom.get(i)] == -1) {
        				nextRoom[neighborRoom.get(i)] = currentRoom;
        				q.add(neighborRoom.get(i));
        			}
        		}
        	}
        	
        	System.out.println("Yes");
        	for (int i = 2; i < nextRoom.length; ++i) {
        		System.out.println(nextRoom[i]);
        	}
        }
	}
}


Measured memory_bytes: 67008
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("ouut.txt","w",stdout);
  #endif
}

int main()
{
  fast_io
  go();
  int n;cin>>n;
  string s;cin>>s;
  int c=0;
  for0(i,s.size())
  {
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    {
      c++;
      i+=2;
    }
  }
  cout << c <<"\n";

}



Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

const int mod=1e9+7;

int main(){
	ll a,b,c,d,e,f,g;	cin>>a>>b>>c>>d>>e>>f>>g;
	ll ret=b;
	ll tmp=((a&(-2))+(d&(-2))+(e&(-2)));
	ll tmp2=0;
	if(a&&d&&e){
		a--;	d--;	e--;
		tmp2=3+((a&(-2))+(d&(-2))+(e&(-2)));
	}
	cout<<ret+max(tmp,tmp2)<<endl;
	return 0;
}


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

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); 

	int k;
	cin >> k;
	string s, ans = "";
	cin >> s;
	int sizes = s.size();
	if (sizes <= k){
		cout << s;
	} else {
		for (int i = 0; i < k; i++){
			ans+=s[i];
		}
		ans+="...";
		cout << ans;
	}

}

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

int main(){
	long long min, max, sum, n, i;
	cin >> n;
	int a[n];
	
	for(i = 0; i <= n-1; i++){
		cin >> a[i];
	}
	
	min = a[0];
	max = a[0];
	sum = a[0];
	
	for(i = 1; i <= n-1; i++){
		if(min > a[i]){
			min = a[i];
		}
	}
	
	for(i = 1; i <= n-1; i++){
		if(max < a[i]){
			max = a[i];
		}
	}
	
	for(i = 1; i <= n-1; i++){
		sum += a[i];
	}
	
	printf("%lld %lld %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

int imin(int a, int b){
  if(a<b) return a;
  else return b;
}

int main()
{
  int i,n;
  int b[100];
  int pts=0;
  scanf("%d", &n);
  for (i = 0; i < n-1; i++) scanf("%d", &b[i]);
  pts=b[0];
  for (i = 0; i < n-2; i++){
    pts+=imin(b[i],b[i+1]);
  }
  pts+=b[n-2];
  printf("%d\n",pts);  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

       while(true){
           String s = sc.next();
           if(s.equals("0"))
             break;
           int answer = 0;
           for(int i=0; i< s.length(); i++){
               answer += Character.digit(s.charAt(i), 10);
           }  
           System.out.println(answer);

       }
    }
}


Measured memory_bytes: 26444