akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_D = 10;

ll power_(ll a, ll power){
    ll value = 1;
    
    while(power != 0){
        if(power & 1) value = (value * a);
        a = a * a;
        power = power >> 1;
     
    }
    return value;
}

int main(void){
    ll D, G;
    ll p[MAX_D], c[MAX_D];
    ll answer = 1001;
    
    cin >> D >> G;
    ll binD = power_(2, D);
    rep(i, D) cin >> p[i] >> c[i];

    rep(i, binD){
        ll tmp = i;
        ll score = 0;
        ll cnt = 0;
        ll res[1001];
        ll cnt_res[1001];
        ll n_res = 0;
        ll res_cnt = 1001;

        rep(j, D){
            if (tmp % 2 == 1){
                score += p[j] * 100 * (j + 1) + c[j];
                cnt += p[j];
            }else{
                rep(k, p[j] - 1){
                    res[n_res] = 100 * (j + 1) * (k + 1); 
                    cnt_res[n_res] = k + 1;
                    n_res ++;
                } 
            }
            tmp /= 2; 
        }

        rep(k, n_res) res[k] += score;

        if (score >= G) answer = min(answer, cnt);
        else{
            rep(k, n_res){
                if (res[k] >= G) res_cnt = min(cnt_res[k], res_cnt);
            }
            answer = min(answer, cnt + res_cnt);
        }
    }

    cout << answer << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int n;
string s;
 
vector<bool> dfs(vector<bool> &tmp, int cnt){
  if(cnt==n){
    if(tmp[n]==tmp[0]){
      if((tmp[0]  && s[0]=='o' && tmp[1]==tmp[n-1])||
         (tmp[0]  && s[0]=='x' && tmp[1]!=tmp[n-1])||
         (!tmp[0] && s[0]=='x' && tmp[1]==tmp[n-1])||
         (!tmp[0] && s[0]=='o' && tmp[1]!=tmp[n-1])){
        tmp.pop_back();
        return tmp;
      }
    }
    return tmp;
  }
  
  if((tmp[cnt] == true && s[cnt] == 'o')||(tmp[cnt] == false && s[cnt] == 'x')){
    if(cnt!=0){ 
      tmp.emplace_back(tmp[cnt-1]);
      vector<bool> cur = dfs(tmp, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
    } else {
      vector<bool> tmps = tmp; tmps.emplace_back(true);
      vector<bool> cur = dfs(tmps, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
      
      vector<bool> tmpw = tmp; tmpw.emplace_back(false);
      cur = dfs(tmpw, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
    }
  }

  if((tmp[cnt] == true && s[cnt] == 'x')||(tmp[cnt] == false && s[cnt] == 'o')){
    if(cnt!=0){ 
      tmp.emplace_back(!tmp[cnt-1]);
      vector<bool> cur = dfs(tmp, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
    } else {
      vector<bool> tmps = tmp; tmps.emplace_back(true);
      vector<bool> cur = dfs(tmps, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
      
      vector<bool> tmpw = tmp; tmpw.emplace_back(false);
      cur = dfs(tmpw, cnt+1); 
      if(cur.size()==s.size()){ return cur;}
    }
  }
  vector<bool> dame(1,false);
  return dame;
}

int main() {
  cin >> n >> s;
  vector<bool> a;
  a.emplace_back(true);
  a = dfs(a,0);
  if(a.size()==s.size()){
    rep(i,n){
      if(a[i]){cout<<"S";}else{cout<<"W";}
    }
    cout<<endl; return 0;
  }

  vector<bool> b;
  b.emplace_back(false);
  b = dfs(b,0);
  if(b.size()==s.size()){
    rep(i,n){
      if(b[i]){cout<<"S";}else{cout<<"W";}
    }
    cout<<endl; return 0;
  }
  
  cout << -1 << endl;
  return 0;
}  


Measured memory_bytes: 41216
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    map<int, vector<string> > tbl;
    map<string, int> score;
    REP(i, 0, n) {
      string name;
      int len; cin >> name >> len;
      REP(j, 0, len) {
        int t; cin >> t;
        tbl[t].push_back(name);
      }
      score[name] = 0;
    }
    for (auto e: tbl) {
      auto &v = e.second;
      for (auto f: v) {
        score[f] += n - v.size() + 1;
      }
    }
    pair<int, string> mi(1e9, "");
    for (auto e: score) mi = min(mi, make_pair(e.second, e.first));
    cout << mi.first << " " << mi.second << endl;
  }
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int c=0;
	for(int i=0;i<n;++i)
	{
		int x;
		scanf("%d",&x);
		if(x%2)++c;
	}
	if(c%2==0)puts("YES");
	else puts("NO");
}

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

int st[100];
int si=0;

int pop(){
  return st[--si];
}

void push(int num){
  st[si++]=num;
}

int main()
{
  char S[5],top,s;
  int a,b,i,Slen;
  
  while((scanf("%s",S))!=EOF){
    if('0'<=S[0] && S[0]<='9') push(atoi(S));
    else{
      a=pop();
      b=pop();
      if(S[0]=='+') push(b+a);
      else if(S[0]=='-') push(b-a);
      else if(S[0]=='*') push(b*a);
    }
  }
  printf("%d\n",pop());
  
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h1, m1;
  cin >> h1 >> m1;
  int h2, m2;
  cin >> h2 >> m2;
  int k;
  cin >> k;
  m1 += h1*60;
  m2 += h2*60;
  int d = m2 - m1;
  if(d < k) cout << 0 << endl;
  else cout << d - k << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
	long long a,b,m,i,j,k,x,y,mn,p,q,r;
	cin>>a>>b>>m;
	x=10000000000;
	y=10000000000;
	for (i=0;i<a;i++)
	{
		cin>>arr[i];
		x=min(x,arr[i]);
	}
	for (i=0;i<b;i++)
	{
		cin>>arr1[i];
		y=min(y,arr1[i]);
	}	
	mn=x+y;
	x=0;
	for (i=0;i<m;i++)
	{
		cin>>p>>q>>r;
		x=arr[p-1]+arr1[q-1]-r;
		mn=min(mn,x);
	}
	cout<<mn<<endl;
}

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

const int mod = 1e9 + 7;

const int N = 405;

int n;
int a[2][N];
int f[N][N];
int cnt[N][N];
int g[N][N][N];
bool visit[N];
bool have[2][N][N];

void add(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < 2; ++i) {
		for (int j = 1; j <= n; ++j) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < 2; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				have[i][j][k] = have[i][j][k - 1] || (a[i][k] == j);
			} 
		}
	}
	for (int i = 0; i <= n; ++i) {
		memset(visit, 0, sizeof visit);
		int cur = 0;
		for (int j = 1; j <= i; ++j) {
			visit[a[0][j]] = 1, cur++;
		}
		cnt[i][0] = cur;
		for (int j = 1; j <= n; ++j) {
			if (!visit[a[1][j]]) {
				visit[a[1][j]] = 1, cur++;
			}
			cnt[i][j] = cur;
		}
	}
	f[0][0] = 1;
	for (int i = 0; i <= (n / 3); ++i) {
		for (int j = i * 2; j >= 0; --j) {
			add(f[i + 1][j + 2], f[i][j]);
			if (j) add(f[i][j - 1], 1LL * f[i][j] * j % mod);
		}
	}
	g[0][0][0] = 1;
	for (int i = 0; i <= (n / 3); ++i) {
		for (int j = i; j <= n; ++j) {
			for (int k = i; k < n; ++k) {
				if (!g[i][j][k]) continue;
				if (cnt[j][k] > i * 3) continue;
				int tmp = i * 3 - cnt[j][k];
				if (have[0][a[1][k + 1]][j]) {
					add(g[i][j][k + 1], g[i][j][k]);
				}
				else {
					add(g[i][j][k + 1], 1LL * g[i][j][k] * tmp % mod);
				}
			} 
		}
		for (int j = i; j < n; ++j) {
			for (int k = i; k <= n; ++k) {
				if (!g[i][j][k]) continue;
				if (cnt[j][k] > i * 3) continue;
				int tmp = i * 3 - cnt[j][k];
				if (have[1][a[0][j + 1]][k]) {
					add(g[i][j + 1][k], g[i][j][k]); continue;
				}
				else {
					add(g[i][j + 1][k], 1LL * g[i][j][k] * tmp % mod);
				}
			} 
		}
		for (int j = i; j < n; ++j) {
			for (int k = i; k < n; ++k) {
				if (!g[i][j][k]) continue;
				if (cnt[j][k] > i * 3) continue;
				if (!have[0][a[1][k + 1]][j + 1] && !have[1][a[0][j + 1]][k + 1]) {
					add(g[i + 1][j + 1][k + 1], g[i][j][k]);
				}
			}
		}
/*		for (int j = i; j <= n; ++j) {
			for (int k = i; k <= n; ++k) {
				if (g[i][j][k]) {
					cout << g[i][j][k] << ' ' << i << ' ' << j << ' ' << k << '\n';
				}
			}
		}*/
	}
	cout << 1LL * g[n / 3][n][n] * f[n / 3][0] % mod;
}

Measured memory_bytes: 89216
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b

# 貪欲に大きい方だと思うんだけど違うのかな
# 貪欲でない反例 (わからん)


N = a_int()
A = ints()
A.sort()
ans = A.pop()
N -= 2
while N > 1:
    N -= 2
    ans += 2 * A.pop()
if N == 1:
    ans += A.pop()
print(ans)


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

using namespace std;

using ll = long long;

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

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;
    for (int i = 0; i <= a; ++i)
        for (int j = 0; j <= b; ++j)
            for (int k = 0; k <= c; ++k)
                if (500 * i + 100 * j + 50 * k == x)
                    ++cnt;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N[10],i,j,h,max;

  for(i=0;i<10;i++){ scanf("%d",&N[i]); }
  for(i=0;i<10;i++){
    max=i;
    for(j=i;j<10;j++){
      if(N[j]>N[max]){ max=j ;}
    }
    h=N[max];
    N[max]=N[i];
    N[i]=h;
  }
  printf("%d\n%d\n%d\n",N[0],N[1],N[2]);

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

int D[100][100],c[510][510];
int cnt[100][3];
int main()
{
	int N, C;
	cin >> N >> C;
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			cin >> D[i][j];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			cin >> c[i][j];
			cnt[c[i][j]][(i + j) % 3]++;
		}
	}
	int ans = mod;
	for (int s = 1; s <= C; s++) {
		for (int t = 1; t <= C; t++) {
			for (int r = 1; r <= C; r++) {
				if (s == t || s == r || t == r) continue;
				int cost = 0;
				for (int i = 1; i <= C; i++) {
					cost += D[i][s] * cnt[i][0];
					cost += D[i][t] * cnt[i][1];
					cost += D[i][r] * cnt[i][2];
				}
				ans = min(ans, cost);
				//cout << cost << endl;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1280
from heapq import *

X,Y,Z,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

# Heapq的なのでぶっこみPopしてればよい
# そのかわり全パターン最初からぶち込むのはむりなので、popしたindexをもとに候補となる対象をpushする必要がある
# ただし容易に重複投入しうるので、投入済みパターンを覚えておくのかな…。historyに含まれてたらSKIP。
Q = []
his = set()

def pushq(p,q,r):
  if (p,q,r) in his:
    return
  if p >= X or q >= Y or r >= Z:
    return
  his.add((p,q,r))
  heappush(Q, ((-1) * (A[p] + B[q] + C[r]), (p, q, r)))
  return

pushq(0,0,0)
for _ in range(K):
  V = heappop(Q)
  print((-1)*V[0])
  p,q,r = V[1]
  pushq(p+1,q,r)
  pushq(p,q+1,r)
  pushq(p,q,r+1)
  


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

int main() {
  int n,d;
  cin >> n >> d;
  vector<vector<int>> a(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> a.at(i).at(j);
    }
  }
  
  int x =0;
  int s = 0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      s = 0;
      for(int k=0;k<d;k++){
        s += (a.at(i).at(k) - a.at(j).at(k))*(a.at(i).at(k) - a.at(j).at(k));
      }
      
      int h=0;
      while(h<=130){
        if(s == h*h){
          x++;
          break;
        }
        h++;
      }
      
    }
  }
  
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i=1;
	int data;
	
	while(1){
		scanf("%d", &data);
		if(data == 0)
			break;
		else{
			printf("Case %d: %d\n", i, data);
			i = i + 1;
		}
	}
	return 0;

}


Measured memory_bytes: 2040
import sys

h,w = map(int,input().split())
C = [input() for _ in range(h)]

dd = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if C[i][j] == '#':
            b = []
            for di,dj in dd:
                if 0<=i+di<h and 0<=j+dj<w:
                    b.append(C[i+di][j+dj] == '.')
            if all(b):
                print('No')
                sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll dp[100010];
int main(){
	fast;
	ll n;
	cin>>n;
	ll a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	dp[1]=0;
	dp[2]=fabs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+fabs(a[i]-a[i-1]),dp[i-2]+fabs(a[i]-a[i-2]));
	}
	cout<<dp[n]<<endl;
	return 0;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, K, R, S, P, ANS = 0;
	string T;
	cin >> N >> K >> R >> S >> P >> T;
	vector<string> V(K);
	for (int i = 0; i < N; i++) {
		V[i % K] += T[i];
	}
	for (int i = 0; i < K; i++) {
		vector<vector<long long> > DP(V[i].size() + 1, vector<long long>(3, 0));
		for (int j = 0; j < V[i].size(); j++) {
			if (V[i][j] == 'r') {
				DP[j + 1][0] = max(DP[j + 1][0], max(DP[j][1], DP[j][2]));
				DP[j + 1][1] = max(DP[j + 1][1], max(DP[j][2], DP[j][0]));
				DP[j + 1][2] = max(DP[j + 1][2], max(DP[j][0], DP[j][1]) + P);
			}
			if (V[i][j] == 's') {
				DP[j + 1][0] = max(DP[j + 1][0], max(DP[j][1], DP[j][2]) + R);
				DP[j + 1][1] = max(DP[j + 1][1], max(DP[j][2], DP[j][0]));
				DP[j + 1][2] = max(DP[j + 1][2], max(DP[j][0], DP[j][1]));
			}
			if (V[i][j] == 'p') {
				DP[j + 1][0] = max(DP[j + 1][0], max(DP[j][1], DP[j][2]));
				DP[j + 1][1] = max(DP[j + 1][1], max(DP[j][2], DP[j][0]) + S);
				DP[j + 1][2] = max(DP[j + 1][2], max(DP[j][0], DP[j][1]));
			}
		}
		ANS += max({ DP[V[i].size()][0], DP[V[i].size()][1], DP[V[i].size()][2] });
	}
	cout << ANS << endl;
}

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

// NOTE TO SELF // try to simplyfy the problem

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

#define ll long long int

//const int mod=1000000007;

using namespace std;


//const ll INF= 1e18L+5 ;

ll dp[100005][3];

int main()
{

    ll n;
    cin>>n;
    
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    
    ll flag=1;
    
    ll k=n;
    
    while(k--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        
        dp[flag][0]= a+ max({dp[flag-1][1],dp[flag-1][2]});
        dp[flag][1]= b+ max({dp[flag-1][0],dp[flag-1][2]});
        dp[flag][2]= c + max({dp[flag-1][1],dp[flag-1][0]});
        
        flag++;
        
        
    }
    
    ll ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 5916
N = int(input())
L = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    for j in range(i):
        for k in range(j):
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i] and L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and L[j] + L[k] > L[i]:
                ans += 1
print(ans)


Measured memory_bytes: 9188
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
for(i=1;i<=n;i++){
    key=A[i];
    j=i-1;
    while(j>=0&&A[j]>key){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=key;
  trace(A, n);
 }
  return 0;
}

Measured memory_bytes: 608
a = input()
r, c = a.split(' ')
r, c = int(r), int(c)

col_sum = [0 for i in range(c)]
for i in range(r):
    b = input()
    list = b.split(' ')
    
    row_sum = 0
    sum_str = ''
    for j in range(c):
        row_sum += int(list[j])
        sum_str = sum_str + list[j] + ' '
        col_sum[j] += int(list[j])
    sum_str = sum_str + str(row_sum)
    print(sum_str)
    
sum = 0
sum_str = ''
for i in range(c):
    sum += col_sum[i]
    sum_str = sum_str + str(col_sum[i]) + ' '
sum_str = sum_str + str(sum)
print(sum_str)



Measured memory_bytes: 5620
#include <bits/stdc++.h> 
using namespace std; 
  
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l,r,d,count=0;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++){
		if(i%d==0){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+10;
map<int,int>mark;

int a[N];
int32_t main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int p=1;
    if(a[1]==1)
    {
        cout<<1<<endl;
        return 0;
    }
    int ind;
    int k1=k;
    vector<int>vp;
    mark[1]=1;
    vp.pb(1);
    for(int i=1;i<=n;i++)
    {

        p=a[p];
        k1--;
        if(k1==0)
        {
            cout<<p<<endl;
            return 0;
        }
        if(mark[p]==1)
        {
            ind=p;
            break;
        }
        mark[p]=1;
        vp.pb(p);
        
    }
    vector<int>ans;
    for(int i=0;i<vp.size();i++)
    {
        if(vp[i]==p)
        {
            for(int j=i;j<vp.size();j++)
            {
                ans.pb(vp[j]);
            }
            break;
        }
        k--;
    }
    int z=k%ans.size();
    cout<<ans[z]<<endl;
}

Measured memory_bytes: 16560
extern crate proconio;
use proconio::{fastout, input, marker::Usize1};

use std::cmp;
use std::collections;

struct State<T>(u64, T);

impl<T> cmp::PartialEq for State<T> {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl<T> cmp::Eq for State<T> {}

impl<T> cmp::PartialOrd for State<T> {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T> cmp::Ord for State<T> {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        s: u32,
        es: [(Usize1, Usize1, usize, u64); m],
        vs: [(u32, u64); n],
    }
    let lim = es.iter().map(|&(_, _, a, _)| a).max().unwrap() * (n - 1) + 1;
    let s = cmp::min(s, (lim - 1) as u32) as usize;
    let vs = vs.into_iter()
        .map(|(c, d)| (cmp::min(c, (lim - 1) as u32) as usize, d))
        .collect::<Vec<_>>();
    let mut heap = collections::BinaryHeap::new();
    let mut g = vec![Vec::new(); n];
    for (u, v, a, b) in es {
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }

    let mut dist = vec![std::u64::MAX; n * lim];
    dist[0 * lim + s] = 0;
    heap.push(State(0, (0, s)));
    while let Some(State(t, (v, k))) = heap.pop() {
        let i = v * lim + k;
        if dist[i] < t {
            continue;
        }
        {
            let &(c, d) = &vs[v];
            if k + c < lim {
                let j = v * lim + k + c;
                if t + d < dist[j] {
                    dist[j] = t + d;
                    heap.push(State(dist[j], (v, k + c)));
                }
            }
        }
        for &(u, a, b) in &g[v] {
            if k >= a {
                let j = u * lim + k - a;
                if t + b < dist[j] {
                    dist[j] = t + b;
                    heap.push(State(dist[j], (u, k - a)));
                }
            }
        }
    }
    for t in 1..n {
        println!(
            "{}",
            dist[t * lim..t * lim + lim].iter().copied().min().unwrap()
        );
    }
}


Measured memory_bytes: 4744
#include<iostream>
using namespace std;
int main(){
  int a[3],b[3],c[3][3],flag=1;
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      scanf("%d",&c[i][j]);
  a[0]=0;
  b[0]=c[0][0];
  b[1]=c[0][1];
  b[2]=c[0][2];
  a[1]=c[1][0]-b[0];
  a[2]=c[2][0]-b[0];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
      if(c[i][j]!=a[i]+b[j])
        flag=0;
    }
  if(flag)
   cout<<"Yes"<<endl;
  else
   cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if((a+b)%2==0){
            System.out.println((a+b)/2);
        }else{
            System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void) {

  int w, h, x, y, r;
  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
  if(x-r >= 0 && y+r <= h && x+r <= w && y-r >= 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

 return 0;
}

Measured memory_bytes: 584
li2 = [input() for i in range(3)]
a = []
for i in range(3):
    a.append([int(x.strip()) for x in li2[i].split()])
bingo = [[0, 0, 0] for i in range(3)]

n = int(input())
b = [int(input()) for i in range(n)]


def atari(z):
    for x in range(3):
        for y in range(3):
            if a[x][y] == z:
                bingo[x][y] = 1


for i in range(n):
    atari(b[i])

ans = 0


def check(z1, z2, z3):
    if z1 == 1 and z2 == 1 and z3 == 1:
        global ans
        ans = 1




for i in range(3):
    check(bingo[i][0], bingo[i][1], bingo[i][2])
    check(bingo[0][i], bingo[1][i], bingo[2][i])

check(bingo[0][0], bingo[1][1], bingo[2][2])
check(bingo[2][0], bingo[1][1], bingo[0][2])


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


Measured memory_bytes: 38256
i = gets.to_i
tt = hh = 0

i.times { |j|
  t, h = gets.chomp.split
  if t < h
    hh += 3
  elsif t > h
    tt += 3
  else
    tt += 1
    hh += 1
  end
}

puts "#{tt} #{hh}"

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


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

    long long N = 50;
    cout << N << endl;

    long long num_div = K/N;
    REP(i, N){
        if(i < K%N) cout << (N-1) + (N+1)*(num_div+1) - K;
        else cout << (N-1) + (N+1)*num_div - K;
        if(i != N-1) cout << " ";
        else cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 31.03.2018 18:09:23       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.length();
  if (n < 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (s.find(c) == string::npos) {
        cout << s << c << '\n';
        return 0;
      }
    }
  } else {
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] < s[i + 1]) {
        char best = s[i + 1];
        for (int j = i + 1; j < n; j++) {
          if (s[j] > s[i]) {
            best = min(best, s[j]);
          }
        }
        s[i] = best;
        s = s.substr(0, i + 1);
        cout << s << '\n';
        return 0;
      }
    }
    cout << -1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
n,y=map(int,input().split())
f=0
for i in range(n+1):
  if f==1:
    break
  else:
    for j in range(n-i+1):
      if i*10000+j*5000+(n-i-j)*1000==y and n-i-j>=0:
        f=1
        print(i,j,n-i-j)
        break
if f==0:
  print(-1,-1,-1)

Measured memory_bytes: 3060
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
	static void Main()
	{
		var line = Console.ReadLine();
        string[] str = line.Split(' ');
        int num0 = int.Parse(str[0]);
        int num1 = int.Parse(str[1]);
        int result = (num0 - 1) * (num1 - 1);
        Console.WriteLine(result.ToString());
    }
}

Measured memory_bytes: 11220
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,k,i,ans=0;
    cin>>n>>k;

    for(i=0;i<n;i++)
    {
    	ll x;
    	cin>>x;
    	if(x>=k) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")


def solve(N: int, K: int):
    print(int(bool(N % K)))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4320
from collections import deque

h, w = map(int, input().split())
s = [list(map(str, input().rstrip())) for _ in range(h)]

dp = [[10001] * w for _ in range(h)]

if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

moves = [[1, 0], [0, 1]]

for y in range(h):
    for x in range(w):
        for m in moves:
            ny, nx = y + m[0], x + m[1]
            if ny >= h or nx >= w:
                continue
            add = 0
            # .から#に突入する時だけカウントが増える
            if s[y][x] == "." and s[ny][nx] == "#":
                add = 1
            dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add)

print(dp[-1][-1])

Measured memory_bytes: 42352
n, k = map(int, input().split())
A = []
for i in range(k):
    d = int(input())
    A.extend(list(map(int, input().split())))

N = []    
for i in range(1, n+1):
    N.append(i)
# print(A,N)
print(len(set(A)^set(N)))

Measured memory_bytes: 9184
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    string s;cin >> s;
    vector<string> chk;chk = {"hi","hihi","hihihi","hihihihi","hihihihihi"};
    REP(i,5){
        if(s == chk[i]){
            cout << "Yes" << '\n';
            return 0;
        }
    }
    cout << "No" << '\n';
    return 0;
}
/*
 * ちょっと待って！
 * そのコード本当に提出して大丈夫？
 * たくさんのコーナーケースがあるよ！
 * 君の注意力は大したことないよ！
 * WAを出すと君は冷静さを失うよ！
 * */


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

int main()
{
	int N;
	vector<int>W;
	int w;
	cin >> N;
	int total = 0;
	for (int t = 0; t < N; t++) {
		cin >> w;
		W.push_back(w);
		total += w;
	}
	int totalf, totalb,sabun=1000000000,inst;
	for (int T = 1; T < N; T++) {
		totalf = 0;
		for (int th = 0; th < T;th++) {
			totalf += W[th];
		}
		totalb = total - totalf;
		inst = abs(totalf - totalb);

		if (inst < sabun) {
			sabun = inst;
		}
	}
	cout << sabun;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t

inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}


void solve()
{
	lli n;
	cin>>n;
	lli a[n],ans=-1,ctr=0;
	stack<lli> st;
	//st.push(INT_MIN);
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)
	{
		if(st.empty())
		{
			st.push(a[i]);
			ctr=0;
			continue;
		}
		if(a[i]>st.top())
		{
			ans=max(ans,ctr);
			while(!st.empty())
			{
				//cout<<st.top()<<" ";
				st.pop();
			}
			/*cout<<"\n";*/
			st.push(a[i]);
			ctr=0;
			continue;
		}
		else
		{
			st.push(a[i]);
			ctr++;
		}
	}
	if(!st.empty())ans=max(ans,(lli)st.size()-1);
				/*while(!st.empty())
			{
				cout<<st.top()<<" ";
				st.pop();
			}
			cout<<"\n";*/
	
	cout<<ans;
}

int main()
{
	fast();
	lli t=1,n,m;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;

    string str1, str2;
    for (int i = 0; S.size() > 2; i++)
    {
        S.pop_back();
        if (S.size() % 2 != 0) continue;
        str1 = S.substr(0, (S.size() / 2));
        str2 = S.substr((S.size() / 2), (S.size() / 2));
        if (str1 == str2) break;
    }
    
    cout << S.size() << endl;

    return 0;
}

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

int main(){
  int N , K;
  cin >> N >> K;
  int hate[K];
  for (int i = 0 ; i < K ; i++){
    cin >> hate[i];
  }

  for(int i = N; ; i++){
    string payString = to_string(i);
    bool payable = true;
    for(int j = 0; j<payString.size();j++){
      for(int k=0 ; k < K ; k++){
        if(payString[j] - '0'== hate[k]){
          payable = false;
        }
      }
    }
    if(payable){
      cout  << i << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
'''
#最高480msぐらい
from collections import deque
letter = deque(input())
Q= int(input())
reversed = False
for i in range(Q):
    query = input().split()
    if len(query)==1:
        reversed = not bool(reversed)
    else:
        if int(query[1])==1: #まえに追加
            if reversed == False:
                letter.appendleft(query[2])
            else:
                letter.append(query[2])
        else:
            if reversed == False:
                letter.append(query[2])
            else:
                letter.appendleft(query[2])
if reversed==True:
    letter.reverse()

output = ''.join(letter)
print(output)
'''

from collections import deque
true_letter = input()
Q= int(input())
letter = deque(['*'])
reversed = False
for i in range(Q):
    query = input().split()
    if len(query)==1:
        reversed = not bool(reversed)
    else:
        if int(query[1])==1: #まえに追加
            if reversed == False:
                letter.appendleft(query[2])
            else:
                letter.append(query[2])
        else:
            if reversed == False:
                letter.append(query[2])
            else:
                letter.appendleft(query[2])
if reversed==True:
    letter.reverse()
    true_letter = true_letter[::-1]

output = ''.join(letter)
output = output.replace('*',true_letter)
print(output)


Measured memory_bytes: 6900
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (x == 500*i + 100*j + 50*k):
                count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (abs (a - c) <= d)
	{
		cout << "Yes\n";
	}
	else if (abs(a-b) <= d && abs(b-c) <= d)
	{
		cout << "Yes\n";
	}
	else 
		cout << "No\n";
	return (0);
}


Measured memory_bytes: 256
n = int(input())
 
s = [str(input()) for i in range(n)]
 
from collections import Counter
c = Counter(s)

max_num = max(c.values())

result = [i[0] for i in c.items() if i[1]==max_num]
result.sort()
 
for i in range(len(result)):
    print(result[i])

Measured memory_bytes: 35476
#include<bits/stdc++.h>
using namespace std;
long long a[100005][3],dp[100005][3];
int main()
{
	long long i,j,n;
	cin>>n;
	for(i=1;i<=n;++i)
	 cin>>a[i][0]>>a[i][1]>>a[i][2];
	for(i=1;i<=n;++i)
	{
		dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

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

void solve(long long N, std::vector<long long> P, std::vector<long long> Q) {
  int cnt_p = 0;
  int cnt_q = 0;
  do {
    cnt_p++;
  } while (next_permutation(P.begin(), P.end()));

  do {
    cnt_q++;
  } while (next_permutation(Q.begin(), Q.end()));

  cout << abs(cnt_p - cnt_q) << endl;
};

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


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String words = sc.next();
    int ans = 0;
    words = words.replace("a","");
    if(words.length() == 2){
      words = words.replace("b","");
      if(words.length() == 1){
        words = words.replace("c","");
        if(words.length() == 0){
          ans = 1;
        }
      }
    }
    if(ans == 1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    REP(i,s.size()){
        if((i+1)%2==0){
            if(!(s[i]=='L' || s[i]=='U' || s[i]=='D')){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(!(s[i]=='R' || s[i]=='U' || s[i]=='D')){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int n=0,i,m;
	char s[101];

	scanf("%s",s);
	m=strlen(s);
	for(i=0;i<m/2;i++)
		if(s[i]!=s[m-1-i])
			n++;
	printf("%d",n);
	return 0;
}

Measured memory_bytes: 128
import math
from decimal import Decimal

a,b,h,m=map(int, input().split())


d = 30*(h+m/60)-6*m
e = 360-d
f = min(d,e)
y = math.cos(math.radians(f))


x = float(a**2+b**2-2*a*b*y)
p = Decimal(x)
z = p**Decimal(0.5)

print("{0:.20f}".format(z))

Measured memory_bytes: 10348
import functools
n, a, b = map(int, input().split())
mod = 10**9+7

def f(n: int, a: int) -> int:
    n = functools.reduce(lambda x, y: x*y%mod, range(n, n-a, -1))
    d = functools.reduce(lambda x, y: x*y%mod, range(1, a+1))
    return n*pow(d, mod - 2, mod)%mod

ans = pow(2,n,mod) - f(n, a) - f(n, b) - 1
ans %= mod
print(ans)


Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            long i = long.Parse(ReadLine());
            while (!Is_Prime(i))
            {
                i++;
            }
            WriteLine(i);
        }

        /// <summary>
        /// 素数判定を行う関数
        /// 計算量はO(√n)
        /// </summary>
        /// <param name="n">対象変数</param>
        /// <returns></returns>
        static bool Is_Prime(long n)
        {
            if (n == 2)
            {
                return true;
            }
            if (n < 2 || n % 2 == 0)
            {
                return false;
            }
            int i = 3;
            while (i <= Math.Sqrt(n))
            {
                if (n % i == 0)
                {
                    return false;
                }
                i += 2;
            }
            return true;
        }
    }
}


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

int64_t GetLukas(int64_t N, vector<int64_t> &tmp)
{
    if (N == 0)
        return 2;
    else if (N == 1)
        return 1;

    if (tmp.at(N) != -1)
        return tmp.at(N);

    return tmp.at(N) = GetLukas(N - 1, tmp) + GetLukas(N - 2, tmp);
}

int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t> tmp(N + 1, -1);
    cout << GetLukas(N, tmp) << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
	auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.map!(to!int).array;
  int y;
  if (a.sum > 0) {
    y = ((a.sum.to!double / n) + 0.5).to!int;
  } else {
    y = ((a.sum.to!double / n) - 0.5).to!int;
  }
  
  int sum;
  foreach (e; a) {
    sum += (e - y)^^2;
  }
  sum.writeln;
}


Measured memory_bytes: 256
import Data.List

primeFactors :: Integer -> [Integer]
primeFactors n = factors n (head primes) (tail primes)
    where factors n p ps
              | n < 2 = []
              | n < p^2 = [n]
              | mod n p == 0 = [p] ++ factors (div n p) p ps
              | otherwise = let (q:qs) = ps in factors n q qs
primes = 2 : filter (\n-> head (primeFactors n) == n) [3, 5..]

main = do
  a:b:_ <- map read . words <$> getLine :: IO [Integer]
  putStrLn $ show $ (1 +) $ length $ nub $ primeFactors $ gcd a b


Measured memory_bytes: 5116
#include<iostream>
#include<algorithm>
#include<vector>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;

int main(){
	ios::sync_with_stdio(false);
cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	priority_queue<long long>v;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		v.push(a);
	}
	
	for(int i=0;i<M;i++){
		
		long long data=v.top();
		//cout<<data<<endl;
		v.pop();
		data=data/2;
		v.push(data);
		
	}
	long long ans=0;
	for(int j=0;j<N;j++){
		ans+=v.top();
		v.pop();
	}
	cout<<ans<<endl;
	


	
}
	


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}


 
int main(){
    string s;
    cin >> s;

    int count = 0;

    for(int i =0; i < s.size()-1; ++i){
        if(s[i] != s[i+1]){
            count++;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 512
R, G, B, N = map(int, input().split())
ans = 0
Rmax=N//R
Gmax=N//G
for i in range(Rmax+1):
    for j in range(Gmax+1):
        total=i*R+j*G
        if N-total<0:
            break
        elif (N-total)%B==0:
            ans+=1
    if j==0:
        break
print(ans)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> X(n, vector<int>(d));
    rep(i, n) {
        rep(j, d) cin >> X[i][j];
    }
    int ans = 0;
    rep(i, n) rep(j, i) {
        int dist = 0;
        rep(k, d) dist += (int)pow(X[i][k] - X[j][k], 2);
        rep(r, 1000) if (dist == r * r) ans++;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3656
#coding: utf-8
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for z in range(X+1, Y+1):
    xflag, yflag = True, True
    for j in range(len(x)):
        if x[j] >= z:
            xflag = False
            break
    for k in range(len(y)):
        if y[k] < z:
            yflag = False
            break
    if xflag == True and yflag == True:
        print("No War")
        exit()
print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll> 
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
	//cin >> T;
	ll t=0;
	while(t++<T){
		ll n,x,t;
		cin>>n>>x>>t;
		ll ans=0;
		ans=(n/x)*t;
		if(n%x)ans+=t;
		cout<<ans<<endl;
		
	}
return 0;
}


Measured memory_bytes: 3652