akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long int
#define sc(a) scanf("%lld",&a)
const int mod=998244353;
using namespace std;
const int inf=1e9+7;
const int maxn=2e5+10;
 
ll n,m;
int sum,t,p,res;
int a[maxn],b[maxn],c[maxn];
ll x,y;
ll dp[110][110];
ll maxx=-1,num=-1;
char str[maxn],s[maxn],ss[maxn];
 
int gcd (int a,int b){
    while(b){
        int t=a%b;
        a=b;
        b=t;
    }
    return a;
}
 
int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);//x
     
    b[1]=a[1];
    for(int i=2;i<=n;i++)
        b[i]=gcd(b[i-1],a[i]);//前缀gcd 
     
    c[n]=a[n];
    for(int i=n-1;i>=1;i--)//后缀gcd 
        c[i]=gcd(c[i+1],a[i]);
     
    for(int i=2;i<n;i++)
        sum=max(gcd(b[i-1],c[i+1]),sum);
     
    cout<<max(sum,max(c[2],b[n-1]))<<endl;
    return 0;
}


Measured memory_bytes: 4848
S = input()

count = 0
hantei = 0

if S[0] == "A":
    count += 1

for i in range(2,len(S)-1):
    if S[i] == "C":
        count += 1
        break

for i in range(1,len(S)):
    if "C"!= S[i] and S[i].isupper() == 1:
        hantei = 1
        break


if count == 2 and S.count("C") == 1 and hantei == 0:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = (x2 - x1), dy = (y2 - y1);
  int x3 = x2 - dy, y3 = y2 + dx, x4 = x1 - dy, y4 = y1 + dx;
  printf("%d %d %d %d", x3, y3, x4, y4);
}


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

int main() {
  char c;
  cin >> c;

  // ここにプログラムを追記
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
   cout << "vowel" << endl;
}
else{
  cout << "consonant" << endl;
}

}

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

using namespace std;

const int MAX = 1000000009;

int main(){
  int A, B, M;
  cin >> A >> B >> M;
  
  vector<int> a(A), b(B);
  int a_min = MAX, b_min = MAX;
  for(int i = 0; i < A; i++){
    cin >> a[i];
    a_min = min(a[i], a_min);
  }
  for(int i = 0; i < B; i++){
    cin >> b[i];
    b_min = min(b[i], b_min);
  }
  
  int p = a_min + b_min;
  for(int i = 0; i < M; i++){
    int x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    if(a[x] + b[y] - c < p){
      p = a[x] + b[y] - c;
    }
  }
  
  cout << p << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
int n;
vector<pair<int,int>> a;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        a.emplace_back(x,i);
    }
    sort(a.begin(),a.end());
    for(auto i:a)
        printf("%d ",i.second);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 1780
#include<cstdio>
#include<cstdlib>

using namespace std;
long long int a,b,x;
int main()
{
	scanf("%lld %lld %lld",&a,&b,&x);
	lldiv_t outa;
	outa=lldiv(a,x);
	lldiv_t outb;
	outb=lldiv(b,x);
	if(outa.rem==0) printf("%lld",outb.quot-outa.quot+1);
	else if(outa.rem!=0) printf("%lld",outb.quot-outa.quot);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
string s;
int main(void) {
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[3] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  string S; cin >> S;
  for(int i = 0; i < S.length(); i++) {
    if(S.find(S[i], i+1) != string::npos) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)){
	cout<<"Yes"<<endl;
  }else{
	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int a[N],n,m,ans,l,r,mid,bz;
int main()
{
	scanf("%d%d",&n,&m);
	fo(i,1,n*2)scanf("%d",&a[i]);
	sort(a+1,a+n*2+1);
	l=0,r=n;
	while(l<r)
	{
		int mid=(l+r)/2;
		bz=0;
		fo(i,mid*2+1,n*2)
			if(a[i]+a[(n+mid)*2+1-i]<m)
				{bz=1;break;}
		if(!bz)r=mid;else l=mid+1;
	}
	fo(i,1,r*2)ans=max(ans,a[i]+a[r*2+1-i]);
	fo(i,r*2+1,n*2)ans=max(ans,a[i]+a[(r+n)*2+1-i]-m);
	printf("%d\n",ans);
}

Measured memory_bytes: 4604
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1000000007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		long[][][] dp = new long[N + 1][N + 1][N + 1];
		dp[0][0][0] = 1;
		int idx = 0;
		for (int i = 0; i < N; ++i) {
			char v = sc.next().charAt(0);
			if (v == '-') continue;
			++idx;
			if (v == 'D') {
				for (int j = 0; j < idx; ++j) {
					for (int k = 1; k < idx; ++k) {
						dp[idx][j][k] += dp[idx - 1][j][k] * j % MOD;
						if (j > 0) dp[idx][j - 1][k - 1] += dp[idx - 1][j][k] * j * k % MOD;
					}
				}
			} else {
				for (int j = 0; j < idx; ++j) {
					for (int k = 0; k < idx; ++k) {
						dp[idx][j + 1][k + 1] += dp[idx - 1][j][k];
						dp[idx][j][k] += dp[idx - 1][j][k] * j % MOD;
					}
				}
			}
		}
		System.out.println(dp[idx][0][0] % MOD);
	}
}

Measured memory_bytes: 133796
import java.math.*;
import java.util.Scanner;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		ArrayList<Integer> arr=new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			int p = scn.nextInt();
			arr.add(p);
		}Collections.sort(arr);
		int ans=0;
		for(int i=0;i<k;i++) {
			ans+=arr.get(i);
		}System.out.println(ans);
	}
}	

Measured memory_bytes: 30540
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int choku,ei,don,no;
    choku = 0;
    ei = 0;
    don = 0;
    no = 0;
    while(true){
	int a,b,c;
	cin >> a >> b >> c;
	if(cin.eof()) break;
	if(a > c) swap(a,c);
	if(b > c) swap(b,c);
	if(a+b <= c) break;
	else{
	    a = a * a;
	    b = b * b;
	    c = c * c;
	    if(a + b == c) choku++;
	    else if(a + b < c) don++;
	    else if(a + b > c) ei++;
	}
    }
    printf("%d %d %d %d\n",choku+don+ei,choku,ei,don);
    return 0;
}

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

ll mod = 1e9 + 7;

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

    if (abs(n-m) > 1) {
        puts("0");
        return 0;
    }

    ll ans = 1;
    if (n == m) ans = 2;

    while (true) {
        ans = (ans * n) % mod;
        ans = (ans * m) % mod;

        if (n==1 || m == 1) break;
        --n, --m;

    }

    cout << ans << "\n";
}


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

int main(void)
{
	int i,n,mx,mi,a;
	scanf("%d",&n);
	mx=-1;	mi=9999;
	for(i=0;i<n;i++)	{
		scanf("%d",&a);
		mx=max(mx,a);
		mi=min(mi,a);
	}
	printf("%d\n",mx-mi);
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    bool exist = false;
    for (int i = 0; i <= N / 4; i++){
        for (int j = 0; j <= N / 7; j++){
            if (4 * i + 7 * j == N){
                exist = true;
            }
        }
    }
    if (exist){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    long long n = s.size();
    long long ans = 0,num = 0;
    for (long long i = 0; i < n; ++i) {
        if (s[i] == 'W') {
            ans += num;
        } else {
            ++num;
        }
    }
    cout << ans << endl;
}


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

int main() {
	long n,m,i,j,k,ans,cur,res;
	string s;
	cin >> s;
	vector<long> dp1(2019,0),dp2(2019,0),dp0(2019,0);
	
	long c;
	ans=0;
	for(i=0; i<s.size(); i++){
		c=s[i]-'0';
		for(j=0; j<2019; j++){
			dp2[(10*j)%2019]=dp1[j];
		}
		for(j=0; j<2019; j++){
			dp1[(j+c)%2019]=dp2[j];
		}
		dp1[c]++;
		ans+=dp1[0];
	}
	
	cout << ans;
	return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

signed main()
{
    

    int n;
    cin>>n;
    int ans=0;
    int c=0;

    ffor(i,0,n)
    {
        int x,y;
        cin>>x>>y;
        if(x==y) c++;
        else
        {
            ans=max(ans,c);
            c=0;
        }
    }
    ans=max(ans,c);
    if(ans>=3) cout<<"Yes";
    else cout<<"No";
    
    return 0;
}



Measured memory_bytes: 3568
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define Pi acos(-1.0)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=3e5+5;
int n,m;
struct node
{
	int x,y;
}a[N];
int cnt,q[N],len;
double ans;
bool flag;
bool cmp(node a,node b)
{
	return a.x<b.x;
}
int main()
{
	int x1,y1,y2,x2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	if (x2<x1)swap(x1,x2),swap(y1,y2);
	if (y1>y2)y1=-y1,y2=-y2,flag=1;
	scanf("%d",&n);
	fo(i,1,n)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if (flag)y=-y;
		if (x>=x1&&x<=x2&&y>=y1&&y<=y2)a[++cnt]=(node){x,y};
	}
	sort(a+1,a+1+cnt,cmp);
	fo(i,1,cnt)
	{
		int l=1,r=len,ans=0;
		while (l<=r)
		{
			int mid=(l+r)>>1;
			if (a[i].y>q[mid])l=mid+1,ans=mid;
			else r=mid-1;
		}
		if (ans==len)q[++len]=a[i].y;
		else q[ans+1]=min(q[ans+1],a[i].y);
	}
	ans=(x2-x1+y2-y1)*100.0;
	if (x1==x2||y1==y2)
	{
		if (cnt)ans+=10.0*Pi-20.0;
	}
	else
	{
		ans-=(20-5.0*Pi)*len;
		if (len==min(x2-x1,y2-y1)+1)ans+=5*Pi;
	}
	printf("%.13lf\n",ans);
	return 0;
 } 

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll n;
	ll q;
	std::string  s ;
	std::cin >> n >> q;
	std::cin >> s ;
	ll lq, rq;
	std::vector<int > tmpn(s.size());
	int tmpflgs = 0;
	int count = 0;
	for (int i = 0; i < s.size(); i++)
	{
		switch (s[i])
		{
		case 'A':
			tmpflgs = 1;
			break;
		case 'C':
			if (tmpflgs == 1) {
				count += 1;
			
			}
			tmpflgs = 0;
			break;
		default:
			tmpflgs = 0;
			break;
		}
		tmpn[i] = count;
	}
	for (int i = 0; i < q; i++)
	{
		std::cin >> lq >> rq;
		ll countmax = tmpn[rq-1] - tmpn[lq-1];
		std::cout << countmax << std::endl;
	
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,A,B;
int main(){
    cin >> N >> A >> B;
    int ans = 0;
    rep1(i,N){
        string s = to_s(i);
        int sum = 0;
        rep(i,sz(s)) sum += s[i] - '0';
        if(sum >= A && sum <= B) ans += i;
    }
    pr(ans);
}

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

int main() {
  char c;
  cin >> c;

if ( c == 'a'  || c == 'e' || c == 'i' || c == 'o' || c == 'u' ){
  cout << "vowel" <<  endl;
}
else {
  cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    cout << 3 * a * a << "\n";
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
buf=input().split()
a=[None for i in range(m)]
b=[None for i in range(m-1)]
for i in range(m):
    a[i]=int(buf[i])
a.sort()
if n==1:
    print(a[-1]-a[0])
else:
    for i in range(1,len(a)):
        b[i-1]=a[i]-a[i-1]
    b.sort()
    print(sum(b[:-n+1]))

Measured memory_bytes: 56328
import bisect


n = int(input())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    na = bisect.bisect_left(lst_A, b)
    nc = n - bisect.bisect_right(lst_C, b)
    ans += na * nc


print(ans)

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

int main(){
  int a,b,c,d;
  cin>>a>>b;
  c=0;
  for(int i=0;i<b;i++){
    cin>>d;
    c+=d;
  }
  if(a-c<0)cout<<-1;
  else cout<<a-c;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int N, M, R;
long long dist[210][210];
const long long INF = 1LL<<50;


int main() {
    while (cin >> N >> M >> R) {
        for (int i = 0; i < 210; ++i) {
            for (int j = 0; j < 210; ++j) {
                dist[i][j] = INF;
            }
            dist[i][i] = 0;
        }
        vector<int> vr;
        for (int i = 0; i < R; ++i) {
            int r;
            cin >> r;
            --r;
            vr.push_back(r);
        }
        for (int i = 0; i < M; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            --a, --b;
            dist[a][b] = c;
            dist[b][a] = c;
        }
        for (int k = 0; k < N; ++k) {
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j < N; ++j) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        
        long long res = 1LL<<50;
        sort(vr.begin(), vr.end());
        do {
            long long tmp = 0;
            for (int i = 1; i < vr.size(); ++i) {
                tmp += dist[vr[i]][vr[i-1]];
            }
            chmin(res, tmp);
        } while (next_permutation(vr.begin(), vr.end()));


        cout << res << endl;
    }
}















Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(0, i, N)
    {
        cin >> A.at(i);
    }

    ll ans = 1000;

    rep(0, i, N - 1)
    {
        if (A.at(i) < A.at(i + 1))
        {
            ll kabu = ans / A.at(i);
            ans -= (ans / A.at(i)) * A.at(i);
            ans += kabu * A.at(i + 1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Write and Erase
            int N = int.Parse(Console.ReadLine());
            var A = new Dictionary<long, int>();

            for(int i = 0; i < N; i++)
            {
                int Ai = int.Parse(Console.ReadLine());

                if (A.ContainsKey(Ai))
                {
                    A[Ai]++;
                }
                else
                {
                    A.Add(Ai, 1);
                }
            }

            int written = 0;

            foreach(var a in A)
            {
                if (a.Value % 2 == 1)
                {
                    written++;
                }
            }

            Console.WriteLine(written);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 22236
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = if (n and 1 == 0) {
        { i: Int -> (n shr 1) + ((i + 1) shr 1) * Math.pow(-1.0, i.toDouble()).toInt() }
    } else {
        { i: Int -> (n shr 1) - ((i + 1) shr 1) * Math.pow(-1.0, i.toDouble()).toInt() }
    }
    val b = arrayOfNulls<String>(n)
    readLine()!!.split(' ').forEachIndexed { i, a ->
        b[map(i)] = a
    }
    println(b.joinToString(" "))
}


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

def dijkstra(s,n,cost,l):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True
        dist_v = d[v]
        for j, weight in enumerate(cost[v]):
            alt = dist_v + weight
            r = (dist_v - 1) // l
            if r != ((alt - 1) // l) and dist_v != 0:
                alt = (r + 1) * l + weight         
            d[j] = min(d[j],alt)
    return d

n,m,l = map(int, input().split())
path = [[float("inf") for i in range(n)] for i in range(n)]
ans_list = []
for i in range(m):
  a,b,cost = map(int, input().split())
  a -= 1
  b -= 1
  if cost <= l:
    path[a][b] = cost
    path[b][a] = cost
for s in range(n):
  ans_list.append(dijkstra(s,n,path,l))
q = int(input())

for i in range(q):
  s,t = map(int, input().split())
  ans = ans_list[s-1][t-1]
  if ans == float("inf"):
    ans = -1
  else:
    ans = (ans - 1) // l
  print(ans)


Measured memory_bytes: 71772
#include <stdio.h>
#include <string.h>

int main(void)
{
  int N;
  scanf("%d", &N);
  char words[N][11];
  for(int i = 0; i < N; i++){
    scanf("%s", words[i]);
    if(0 < i && words[i][0] != words[i-1][strlen(words[i-1])-1]){
      printf("No\n");
      return 0;
    }
    for(int j = 0; j < i; j++){
      if(strcmp(words[i], words[j]) == 0){
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair


int main(){
  string s;
  cin >> s;
  bool flag = true;
  flag &= s[0]=='A';
  FOR(i,1,s.size()){
    if(i == 0 || i == 2)continue;
    flag &= ((s[i] >= 'a' && s[i] <= 'z') || s[i]=='C');
  }
  int t = false;
  FOR(i, 2, s.size() - 1){
    if(s[i] == 'C')
      t++;
  }
  flag &= (t==1);

  if(flag)EN(AC);
  EN(WA);

  return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, k, cnt = 0; cin >> n >> k;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];

    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    for(int i = 0; i < k; i++){
        cnt += l[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
while True:
    H,W = map(int, input().split())
    if H == 0 or W == 0:
        break
    for i in range(H):
        if i == 0:
            line = "#"
            for j in range(W-1):
                if j % 2 == 0:
                    line += "."
                else:
                    line += "#"
            print(line)
        elif i % 2 == 1:
            line = "."
            for j in range(W-1):
                if j % 2 == 0:
                    line += "#"
                else:
                    line += "."
            print(line)
        elif i % 2 == 0:
            line = "#"
            for j in range(W-1):
                if j % 2 == 0:
                    line += "."
                else:
                    line += "#"
            print(line)
    print()


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;
int main()
{
    ll t,i,n;
    ll a,b,c;
    ll arr[3];
    for(i=0;i<3;i++) cin>>arr[i];
    sort(arr,arr+3);
    if((arr[0]==arr[1] && arr[2]!=arr[1]) || (arr[1]==arr[2] && arr[0]!=arr[1])) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main() {
  int64_t t,a,k;
  cin >> t >> a >> k;
  if(k<t) cout << t-k << ' ' << a << endl;
  else if(a+t>k) cout << 0 << ' ' << a-(k-t) << endl;
  else cout << 0 << ' ' << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF 1LL<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n,a; cin >> n >> a;
    vl x(n);
    rep(i,n) cin >> x[i];
    ll dp[55][55][2505];
    rep(i,55) rep(j,55) rep(k,2505) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    rep(i,n){
        rep(j,i+1){
            rep(k,2501){
                if(dp[i][j][k]>=0){
                    if(dp[i+1][j][k]!=-1) dp[i+1][j][k] += dp[i][j][k];
                    else dp[i+1][j][k] = dp[i][j][k];
                }
                if(k >= x[i]){
                    if(dp[i][j][k-x[i]]!=-1){
                        if(dp[i][j][k-x[i]]<=0)dp[i+1][j+1][k] = dp[i][j][k-x[i]] + 1;
                        else dp[i+1][j+1][k] = dp[i][j][k-x[i]];
                    }
                }
            }
        }
    }
    ll ans = 0;
    REP(i,1,n+1){
        if(dp[n][i][i*a]==-1) continue;
        ans += dp[n][i][i*a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 59520
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>

using namespace std;
int main(){
  int n,m;
  cin >>n>>m;
  vector<int> x(m);
  for(int i=0;i<m;i++)
    cin >>x[i];

   vector<long long> l(m-1,0);

  if(n>=m) {cout<<0<<endl; return 0;}
  else{
    sort(x.begin(),x.end());
    for(int i=0;i<m-1;i++)
    l[i]=x[i+1]-x[i];

    sort(l.begin(),l.end(),greater<int>());

    long long sum=0;
    for(int i=0;i<n-1;i++)
    sum+=l[i];

    cout<<x[m-1]-x[0]-sum<<endl;
  }
  
}


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

int main(void) {
    int N;
    cin >> N;
    switch(N%10) {
        case 3:
            cout << "bon\n";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon\n";
            break;
        default:
            cout << "hon\n";
            break;
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();

    System.out.println(lcm(a,b));


  }

  public static long lcm (long a, long b) {
    long temp;
	  long c = a;
	  c *= b;
	  while((temp = a%b)!=0) {
		  a = b;
      b = temp;
	  }
	  return (c/b);
  }

}


Measured memory_bytes: 22868
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] bingo = new int [3][3];

		//ビンゴカードの入力
		for(int x=0 ; x<3 ; x++) {
			for(int y=0 ; y<3 ; y++) {
				bingo[x][y] = sc.nextInt();
			}
		}
		//抽選番号の個数の入力と、配列に抽選番号を入力
		int sum = sc.nextInt();
		int num[] = new int[sum];
		for(int i=0 ; i<sum ; i++) {
			num[i] = sc.nextInt();
		}
		//
		for(int i=0 ; i<sum ; i++) {
			for(int x=0 ; x<3 ; x++) {
				for(int y=0 ; y<3 ; y++) {
					if(bingo[x][y]==num[i]) {
						bingo[x][y]=1;
					}
				}
			}
		}
		//ビンゴのパターン
		int pattern1 = bingo[0][0] + bingo[0][1] + bingo[1][2];  //縦1列目
		int pattern2 = bingo[1][0] + bingo[1][1] + bingo[1][2];  //縦2列目
		int pattern3 = bingo[2][0] + bingo[2][1] + bingo[2][2];  //縦3列目
		int pattern4 = bingo[0][0] + bingo[1][1] + bingo[2][2];  //ななめ右下
		int pattern5 = bingo[2][0] + bingo[1][1] + bingo[0][2];  //ななめ左下
		int pattern6 = bingo[0][0] + bingo[1][0] + bingo[2][0];  //横1列目
		int pattern7 = bingo[0][1] + bingo[1][1] + bingo[1][2];  //横2列目
		int pattern8 = bingo[0][2] + bingo[1][2] + bingo[2][2];  //横3列目

		if(pattern1==3 || pattern2==3 || pattern3==3 || pattern4==3 || pattern5==3 || pattern6==3 || pattern7==3 || pattern8==3) {
			System.out.print("Yes");
		}
		else {
			System.out.print("No");
		}
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>

int main(void) {
  auto N = 0;
  auto K = 0;
  std::cin >> N >> K;
  std::vector<int> vec;
  while (N != 0) {
    vec.push_back(N%K);
    N /= K;
  }
  std::cout << vec.size();
  return 0;
}

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

int main(){
    int a, b;
    while(cin >> a >> b, a != 0 || b != 0){
        int max_shop = 0;
        int max = a + b;
        for(int i=1; i<5; i++){
            cin >> a >> b;
            if(max < a + b){
                max = a + b;
                max_shop = i;
            }
        }
        cout << (char)('A' + max_shop) << " " << max << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int n;
  int d;
  cin >> n >> d;
  
  int i = 0;
  long int x;
  long int y;
  long double point;
  long int ans = 0;
  while(i < n){
  	cin >> x >> y;
    point = sqrt((x*x)+(y*y));
    if(point <= d){
      ans ++;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll k, a, b;

    cin >> k >> a >> b;

    ll n = 0;
    ll t = a - 1 + 2;

    ll r = 1 + k;

    ll res = a;

    k -= a - 1;

    res += (k / 2) * (b - a);

    res += (k % 2);

    r = max(res, r);

    cout << r << endl;

    return 0;
}

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

int main() {
  string a ;
  cin >> a ;
  bool kekka = false;
  for (int i = 0; i < 3; i++) {
    char b = a.at(i);
      if(b=='7')
      {kekka=true;}
  }
  
  if(kekka==true)
  {cout << "Yes" << endl;}
else{cout << "No" << endl;}
    
    
    
    
}



Measured memory_bytes: 3620
#include <cstdio>

int main() {
  int n;
  scanf("%d", &n);
  int k = n % 10;
  if(k == 3) {
    puts("bon");
  } else if(k == 0 || k == 1 || k == 6 || k == 8) {
    puts("pon");
  } else {
    puts("hon");
  }
  return 0;
}

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

using namespace std;

const int N=1e6+10;

int gcd(int x,int y)
{
	return y==0?x:gcd(y,x%y);
}

int a[N],n,b[N];
int main()
{
	int g=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		g=gcd(a[i],g);
	}
	if (g!=1)   printf("not coprime");
	else
	{
		int flag=1;
		for (int i=1;i<=n&&flag;i++)
		{
			int temp=(int)sqrt(a[i]);
			for (int j=2;j<=temp;j++)
			{
				if (a[i]%j==0)
				{
					if (b[j])  
					{
						flag=0;
						break;
					}
					b[j]=1;
					while (a[i]%j==0)
					{
						a[i]/=j;
					}
				}
			}
			if (a[i]>1) 
			{
				if (b[a[i]])  
				{
					flag=0;
					break;
				}
				b[a[i]]=1;
			}
		}
		if (flag)   printf("pairwise coprime");
		else   printf("setwise coprime");
	}
	return 0;
}

Measured memory_bytes: 7976
# -*- coding: utf-8 -*-
"""
Set Operation - Set Symmetric Difference
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_9_D&lang=jp

"""
_ = input()
A = set([int(a) for a in input().split()])
_ = input()
B = set([int(b) for b in input().split()])
C = sorted(d for d in (A ^ B))
if C:
    print(*C, sep='\n')



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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;

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

int main() {
    int n;
    cin >> n;
    
    ll ans = 0;
    rep (a, 1, n) rep (b, 1, n) {
        if (a * b >= n)
            break;
        ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in= new FastScanner(System.in);
		PrintWriter out= new PrintWriter(System.out);
		
		
		int n= in.nextInt();
		int k= in.nextInt();
		int cur= 1;
		for (int i = 0; i < n; i++) {
			cur= Math.min(2*cur, cur+k);
		}
		System.out.println(cur);
	}
	static class p{
		int x;
		int y;
		public p(int a, int b) {
			x=a;
			y=b;
		}
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}
/*
4 6
1 1 1
1 3 1
4 2 1
4 3 1
2 4 1
2 3 1
*/

Measured memory_bytes: 20692
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    ll N;
    vector<ll> a;
    vector<ll> b;
    vector<ll> c;

    cin >> N;
    rep(i, 0, N){
        ll tempA, tempB, tempC;
        cin >> tempA >> tempB >> tempC;
        a.push_back(tempA);
        b.push_back(tempB);
        c.push_back(tempC);
    }

    ll ansA[100003];
    ll ansB[100003];
    ll ansC[100003];
    rep(i, 0, 100003){
        ansA[i] = 0;
        ansB[i] = 0;
        ansC[i] = 0;
    }
    ansA[0] = a[0];
    ansB[0] = b[0];
    ansC[0] = c[0];
    rep(idx, 1, N){
        chMax(ansA[idx], max(ansB[idx - 1], ansC[idx -1]) + a[idx]);
        chMax(ansB[idx], max(ansA[idx - 1], ansC[idx -1]) + b[idx]);
        chMax(ansC[idx], max(ansA[idx - 1], ansB[idx -1]) + c[idx]);
    }

    cout << max(ansA[N-1],max(ansB[N-1], ansC[N-1])) << endl;

    return 0;
}


Measured memory_bytes: 5216
def main():
    N = int(input())
    a = list(map(int, input().split()))
    gray = brown = green = cyan = blue = yellow = orange = red = other = 0
    for ai in a:
        if 1 <= ai <= 399 and gray == 0:
            gray = 1
        elif 400 <= ai <= 799 and brown == 0:
            brown = 1
        elif 800 <= ai <= 1199 and green == 0:
            green = 1
        elif 1200 <= ai <= 1599 and cyan == 0:
            cyan = 1
        elif 1600 <= ai <= 1999 and blue == 0:
            blue = 1
        elif 2000 <= ai <= 2399 and yellow == 0:
            yellow = 1
        elif 2400 <= ai <= 2799 and orange == 0:
            orange = 1
        elif 2800 <= ai <= 3199 and red == 0:
            red = 1
        elif 3200 <= ai <= 4800:
            other += 1
    ans_max = gray + brown + green + cyan + blue + yellow + orange + red + other
    if gray + brown + green + cyan + blue + yellow + orange + red == 0:
        ans_min = 1
    else:
        ans_min = gray + brown + green + cyan + blue + yellow + orange + red
    print(str(ans_min) + " " + str(ans_max))


if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, Q, K;
vector<vector<P>> root(100001);  //pair<辺の距離, 行先の頂点>
vector<ll> dist(100001, LLONG_MAX); //distance[i]は始点(start)から頂点iへの最短距離が入る
bitset<100001> used;

void Dijkstra(ll start = K){ //start = 始点
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, start));
    while(!que.empty()){
        ll d, t; //d:startからの距離, t:行先
        tie(d, t) = que.top(); que.pop();
        if(used[t]) continue;   //探索済み
        used[t] = true, dist[t] = d;
        for(auto e : root[t]){
            if(dist[e.second] <= d + e.first) continue;
            que.push(make_pair(d + e.first, e.second));
        }
    }
}

int main(void){
    
    scanf("%d", &N);
    for(int i = 0; i < N - 1; ++i){
        ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
        root[a].push_back(make_pair(c, b)), root[b].push_back(make_pair(c, a));
    }
    
    scanf("%d %d", &Q, &K);
    Dijkstra();
    for(int i = 0; i < Q; ++i){
        int a, b; scanf("%d %d", &a, &b);
        printf("%lld\n", dist[a] + dist[b]);
    }
    
    return 0;
}


Measured memory_bytes: 11120
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(ll n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  int N;
  cin>>N;
  cout<<int(sqrt(N))*int(sqrt(N));
return 0;}


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

int main(int argc, char const* argv[])
{
	string W;
	cin >> W;
	for(int i = 0; i < W.size(); i++){
			if(W[i] >= 'A' && W[i] <= 'Z')W[i] += 32;
	}
	string T;
	cin >> T;
	int count = 0;
	while(T != "END_OF_TEXT"){
			for(int i = 0; i < T.size(); i++){
					if(T[i] >= 'A' && T[i] <= 'Z')T[i] += 32;
			}
			if(T == W)count++;
			cin >> T;
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 3148
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[4], dice[2], dice[1], dice[3] ]
    @bottom = dice[5]
  end

  def print_upper(action)
    action.chars do |str|
      b = @bottom
      u = @top
      case str
      when "N"
        @top   = @side[2]
        @bottom  = @side[0]
        @side[2] = b
        @side[0] = u
      when "E"
        @top   = @side[3]
        @bottom  = @side[1]
        @side[3] = b
        @side[1] = u
      when "S"
        @top   = @side[0]
        @bottom  = @side[2]
        @side[0] = b
        @side[2] = u
      when "W"
        @top   = @side[1]
        @bottom  = @side[3]
        @side[1] = b
        @side[3] = u
      end
    end
    puts @top
  end
end

d = Dice.new(gets.split.map(&:to_i))
d.print_upper(gets.chomp)

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

bool compare(int a,int b){
  return a<b;//ascending
} 

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


    string s;
    cin>>s;
    int p=0;
    int count=0;
    int max=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='R'){
        count++;
        if(count>max){
      max=count;
    }
      }
      else if(s[i]=='S'){
        count=0;
        continue;
        
      }
    }
  cout<<max<<endl;

  return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

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

using namespace std;
const int V = 100005;


int a[100005];
int n;


int main(){
cin >> n;
rep(i,n)cin >> a[i];
rep(i,n){
  if(i == 0){    rep(k,n){
    cout << a[k];
    if(k == n-1){
      break;
    }
    cout<< ' ';
  }
  cout << endl;

 continue;}
  int v = a[i];
  int j = i-1;
  while(j>=0 && a[j] > v){
    a[j+1] = a[j];
    j--;
  }
  a[j+1] = v;
  rep(k,n){
    cout << a[k];
    if(k == n-1){
      break;
    }
    cout<< ' ';
  }
  cout << endl;
}
}



Measured memory_bytes: 3068
#include <stdio.h>

int main(void)
{
    int a, b, c;
    int count = 3;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a == b)
        count--;
    if(b == c)
        count--;
    if(a == c)
        count--;
    if(a == b && b == c && a ==c)
        count = 1;
    
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
//#include <cmath>
#include <cstdlib>

using namespace std;

int main(){

    int n;
    cin >> n;

    if(n == 1){
        cout << "1";
        return 0;
    }

    if(n == 2){
        int a,b;
        cin >> a >> b;
        if(abs(a-b) <= 2){
            cout << "2";
            return 0;
        }else{
            cout << "1";
            return 0;
        }
    }


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

    int ans = 0;
    for(int i=0;i<n-2;i++){
        ans = max(ans,a[i]+a[i+1]+a[i+2]);
    }

    cout << ans;



    return 0;
}

Measured memory_bytes: 640