akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,m,s;
	int v[1001];
	for(;;){
		scanf("%d%d",&n,&m);
		if(!n)break;
		s=0;
		rep(i,n){
			scanf("%d",v+i);
			s+=v[i];
		}
		sort(v,v+n);
		rep(i,n/m)s-=v[i*m+n%m];
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 1208
lsa=list(map(int,input().split()))
lsb=list(map(int,input().split()))
lsc=list(map(int,input().split()))
n=int(input())
called=[int(input()) for i in range(n)]

lsaa=[lsa[0],lsb[0],lsc[0]]
lsbb=[lsa[1],lsb[1],lsc[1]]
lscc=[lsa[2],lsb[2],lsc[2]]

lsx=[lsa[0],lsb[1],lsc[2]]
lsy=[lsa[2],lsb[1],lsc[0]]

ls=[lsa,lsb,lsc,lsaa,lsbb,lscc,lsx,lsy]

for i in ls:
    flag=False
    for j in i:
        if j in called:
            flag=True
        else:
            flag=False
            break
    if flag:
        break

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

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

int main(){
  int A, B;
  cin >> A >> B;
  int C = A - 1;
  int D = B - 1;

  int array[4] = {A, B, C, D};
  sort(array, array + 4, greater<int>());
  cout<<array[0] + array[1]<<endl;
}

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

int abc102_b(int *a, int length) {
	int min = 1000000001;
	int max = 0;
	for (int i = 0; i < length; i++) {
		if (a[i] < min) {
			min = a[i];
		}
		if (a [i]>max) {
			max = a[i];
		}
	}
	return max - min;
}

void abc_102_b_test() {
	{
	int a[] = { 1,4,6,3 };
	assert(abc102_b(a, 4) == 5);
	}
	{
		int a[] = { 1000000000 ,1 };
		assert(abc102_b(a, 2) == 999999999);
	}
	{
		int a[] = { 1,1,1,1,1 };
		assert(abc102_b(a, 5) == 0);
	}
	{
		int a[] = { 1,1};
		assert(abc102_b(a, 2) == 0);
	}
}


int main()
{
//	abc_102_b_test();
	int n;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	cout << abc102_b(a, n) << endl;

	return 0;
}



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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
char S, T; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> S;
	(ll)S++;

	cout << S << endl;

	return 0;
}


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

// THINK: INT vs LONG LONG?

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

    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << '\n';

    return 0;
}

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

const static int N = 100;

int main() {
  int n, G[N][N];
  int v, m, k;
  
  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) G[i][j] = 0;
  }

  for ( int i = 0; i < n; i++ ) {
    cin >> v >> m;
    v--;
    for ( int j = 0; j < m; j++ ) {
      cin >> k;
      k--;
      G[v][k] = 1;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j< n; j++ ) {
      if ( j ) cout << " ";
      cout << G[i][j];
    }
  cout << endl;
  }

  return 0;    
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void) {

	int x, y500, y5, sum;

	scanf("%d", &x);

	y500 = (int)(x / 500);

	x -= y500 * 500;

	y5 = (int)(x / 5);

	sum = (y500 * 1000) + (y5 * 5);

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n,x,y;cin>>n>>x>>y;
	int z=x+y;
	if(z<=n)z=0;
	else z=z-n;
	cout<<min(x,y)<<" "<<z<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


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

    cout << "Christmas";
    rep(i, 25-n) cout << " Eve";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
	int a[3], b[10] = {0}, okN;
	while(std::cin >> a[0] >>  a[1] >> a[2]) {
		
		for( int i=0; i<10; i++) b[i] = 0;
		
		// Initialize b[i] for the set of card list
		// except card already showed
		for( int i=0; i<3; i++) b[a[i]] = 1;
		
		okN = 0;
		
		// estimated percentage
		for( int i=0; i<10; i++) {
			if(b[i]==1) continue;

			if(a[0]+a[1]+i<=19) okN++;
		}
		
		if(okN>=4) std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int inf = 10000;

int n, ma, mb;
int a[40];
int b[40];
int c[40];
int dp[401][401];

int main(){
  scanf("%d%d%d", &n, &ma, &mb);
  rep(i, n){
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
  }

  rep(i, 401){
    fill_n(dp[i], 401, inf);
  }
  dp[0][0] = 0;
  rep(i, n){
    for(int j = 400; j >= 0; --j){
      for(int k = 400; k >= 0; --k){
        if(j >= a[i] && k >= b[i]){
          dp[j][k] = min(dp[j - a[i]][k - b[i]] + c[i], dp[j][k]);
        }
      }
    }
  }
  
  int ans = inf;
  int k = 1;
  while(ma * k <= 400 && mb * k <= 400){
    ans = min(dp[ma * k][mb * k], ans);
    ++k;
  }
  printf("%d\n", ans != inf ? ans : -1);
  return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)

#define int long long

int n, m;
bool f[10][10];
int dfs(int x, int y, vector<int> v) {
	int ret = 0;
	int s = (n - 1) / 2;
	int nx = x, ny = y + 1;
	if (ny == n) {
		nx++;
		ny = nx;
	}
	if (nx == n) {
		ret = 1;
		for (auto u : v)if (u != 0)ret = 0;
	}
	else if (x == y && x > 0 && v[x - 1] != 0) {
		ret = 0;
	}
	else if (f[x][y]) {
		ret = dfs(nx, ny, v);
	}
	else {
		if (v[x] < s && v[y] > -s) {
			vector<int> w = v;
			w[x]++, w[y]--;
			ret += dfs(nx, ny, w);
		}
		if (v[x] > -s && v[y] < s) {
			vector<int> w = v;
			w[x]--, w[y]++;
			ret += dfs(nx, ny, w);
		}
	}
	//cerr << x << " " << y << " ";
	//for (auto u : v)cerr << " " << u;
	//cerr << "  " << ret << endl;
	return ret;
}

signed main() {
	for (; cin >> n && n;) {
		cin >> m;
		memset(f, 0, sizeof(f));
		vector<int> x(m), y(m);
		rep(i, 0, m) {
			cin >> x[i] >> y[i];
			x[i]--, y[i]--;
		}

		vector<int> v(n);
		rep(i, 0, m) {
			v[x[i]]++;
			v[y[i]]--;
			f[x[i]][y[i]] = true;
			f[y[i]][x[i]] = true;
		}
		rep(i, 0, n)f[i][i] = true;

		int ans = dfs(0, 0, v);
		cout << ans << endl;
	}
	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL solve(LL N, VL xs){
  LL res = 0;
  while(true){
	SORT(xs);
	if(xs.back() < N)
	  break;
	++res;
	REP(i,N-1) xs[i]++;
	xs.back() -= N;
  }
  return res;
}

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

  LL K;
  cin >> K;
  if(!K){
	cout << 2 << endl
		 << "1 1" << endl;
	return 0;
  }

  LL N = 50;
  LL d = K / N;
  LL e = K % N;
  VL ans(N);
  iota(ALL(ans), 0);
  REP(i,N){
	LL t = d + (i < e);
	ans[i] += N * t - (K - t);
  }

  cout << N << endl;
  REP(i,N) cout << (i?" ":"") << ans[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj1131().doIt();
    }
    class aoj1131{
    	int result = 0;
    	int p,q,a,n;
    	void dfs(int split, int pp, int qq, int bai,int bo) {
            if(p * qq == q * pp){
                result++;
                return ;
            }
            if(split == n) return;
            if(p * qq < q * pp)return;
            for(int i = bo; i * bai <= a; i++){
                dfs(split + 1, qq * 1 + pp * i, qq * i, i * bai, i);
            }
        }
         void doIt(){
        	 while(true){
                 p = sc.nextInt();
                 q = sc.nextInt();
                 a = sc.nextInt();
                 n = sc.nextInt();
                 if(p + q + a + n == 0) break;
                 result = 0;
                 dfs(0,0,1,1,1);
                 System.out.println(result);
             }
         }
     }
}

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

#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++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int A, B; cin >> A >> B;
	if (A > 12)cout << B;
	else if (A >= 6)cout << B / 2;
	else cout << 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// dp[i][j][k]: i番目までの薬でタイプAがjグラム、タイプBがkグラムになるような組み合わせの買い方の最小コスト 存在しなければinf
int n, ma, mb, a[44], b[44], c[44], dp[44][444][444];

int main() {
	cin >> n >> ma >> mb;
	repst(i,1,n) cin >> a[i] >> b[i] >> c[i];
	
	rept(i,10*n) rept(j,10*n) dp[0][i][j] = inf;
	dp[0][0][0] = 0;
	repst(i,1,n) {
		rept(j,10*n) {
			rept(k,10*n) {
				dp[i][j][k] = dp[i-1][j][k];
				if (j>=a[i] && k>=b[i]) chmin(dp[i][j][k], dp[i-1][j-a[i]][k-b[i]]+c[i]);
			}
		}
	}
	int ans = inf;
	repst(i,1,10*n) repst(j,1,10*n) if (i*mb==j*ma) chmin(ans, dp[n][i][j]);
	if (ans==inf) ans = -1;
	cout << ans << ln;
}

Measured memory_bytes: 32896
#include<cstdio>
int n,L,a[300100],t[300100],ans,vis[300100],l[300100],r[300100];
int main(){
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&t[i]);
	ans=n;
	for(int i=1;i<=n;i++){
		ans+=t[i]/(2*L);
		t[i]%=2*L;
		if(t[i]==0)ans--,vis[i]=1;
		else{
			l[i]=2*a[i]>=t[i];
			r[i]=2*(L-a[i])>=t[i];
			if(!l[i]&&!r[i])t[i]=0,vis[i]=1;
		}
	}
	int px=1;
	while(px<n&&!(l[px]==1&&r[px]==0))px++;
	int tot=0,top=0;
	for(int i=1;i<px;i++)
		if(!vis[i]){
			if(!l[i]){
				if(top)top--,ans--;
			}
			else top++;
		}
	tot+=top,top=0;
	for(int i=n-1;i>=px;i--)
		if(!vis[i]){
			if(!r[i]){
				if(top)top--,ans--;
			}
			else top++;
		}
	tot+=top;
	ans-=tot/2;	
	if(r[n]==0)ans++;
	printf("%lld\n",1ll*ans*2*L);
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int a,b;
  scanf("%d%d",&a,&b);
  if((a+b)%3==0 || a%3==0 || b%3==0){
    printf("Possible\n");
  }else{
    printf("Impossible\n");
  }
  return 0;
}


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

using namespace std;

int main()
{
	string str ;
	getline(cin,str);
	transform(str.begin(), str.end(), str.begin(), ::toupper);

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 3180
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
vector <tuple<int,int,int>>relation;
int n;
long long ans;
int main(){
    scanf("%d",&n);
    if(n>=30)
        printf("Yes");
    else
        printf("No");
    
}

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

int main() {
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> route(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        route.at(i) = make_pair(a, b);
    }
    sort(route.begin(), route.end());
    for (int i = 0; i < n; i++) {
        int a, b;
        tie(a, b) = route.at(i);
        if (b <= t) {
            cout << a << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 11

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

	int n, m;
	cin >> n >> m;
	ll a[n], sum = 0, cum[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a + n);
	cum[0] = a[0];
	for (int i = 1; i < n; ++i)
	{
		cum[i] = cum[i-1] + a[i];
	}
	ll b, c;
	vector<pair<ll, ll>> bc;
	for (ll i = 0; i < m; ++i)
	{
		cin >> b >> c;
		bc.pb({b, c});
	}
	sort(bc.begin(), bc.end(), [](pair<ll, ll> a, pair<ll, ll> b){
		return a.ss > b.ss;
	});

	ll last = -1, f = 1;
	for(auto e : bc)
	{
		ll k = e.ss;
		ll l = last + 1, r = n - 1;
		while(l < r)
		{
			ll mid = l + r >> 1;
			if(a[mid] < k)
				l = mid + 1;
			else
				r = mid;
		}
		if(a[l] < k)
			l+=1;
		// cout << l << " ";
		if(l - last - 1 > e.ff)
			l = last + e.ff + 1;
		else
			f = 0;
		if(l > last + 1)
		{
			sum = sum - cum[l - 1] + (last >= 0 ? cum[last] : 0) + (l - last - 1) * e.ss; 
			// cout << cum[l - 1] << " ";
		}
		// cout << sum << " " << l << " " << last<<"\n";
		last = l - 1;
		if(!f)
			break;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3956
K = int(input())
#N, K = list(map(int, input().split()))

res = 0

def runrun(keta, flag, before, res) :
  if(flag) :
    if(keta == 0) :
      res += 1
      if(res == K) :
        print("".join(map(str, before)))
        exit()
      return res
    for i in range(before[-1]-1, before[-1]+2) :
      if((i < 0) or (i > 9)) :
        continue
      else :
        res = runrun(keta-1, flag, before+[i], res)
    return res
  else :
    if(keta <= 0) :
      return res

    res = runrun(keta-1, flag, before, res)
    for i in range(1, 10) :
      res = runrun(keta-1, True, before+[i], res)
    return res
      
      
runrun(10, False, [], res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  if(2*k>b-a+1){
    for(int i=a; i<=b; ++i) cout << i << endl;
    return 0;
  }

  for(int i=a; i<=a+k-1; ++i){
    cout << i << endl;
  }
  for(int i=b-k+1; i<=b; ++i){
    cout << i << endl;
  }
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

vector<int>e[100],v;
int n,s[100][100],res;
void F()
{
	int i,j,t,c;
	if(v.size()>1)
	{
		for(c=i=0;i<v.size();++i)
		{
			t=2e9;
			for(j=0;j<v.size();++j)
			{
				if(i==j)continue;
				t=min(t,s[v[i]][v[j]]);
			}
			c+=t;
		}
		res=max(res,c);
	}
	if(v.size())
	{
		for(i=v[v.size()-1]+1;i<n;++i)
		{
			for(j=0;j<v.size();++j)
				if(!std::binary_search(e[i].begin(),e[i].end(),v[j]))
					goto N;
			v.push_back(i);
			F();
			v.pop_back();
			N:;
		}
	}
	else
	{
		for(i=0;i<n-1;++i)
		{
			v.push_back(i);
			F();
			v.pop_back();
		}
	}
}
int main()
{
	int m,a,b,f;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d%d",&a,&b,&f);
		--a,--b;
		e[a].push_back(b);
		e[b].push_back(a);
		s[a][b]=s[b][a]=f;
	}
	for(m=0;m<n;++m)sort(e[m].begin(),e[m].end());
	F();
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	cout << 48 - in() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, M) cin >> B[i];
    rep(i, 0, N - M + 1)
    {
        rep(j, 0, N - M + 1)
        {
            bool ok = true;

            rep(k, 0, M)
            {
                rep(l, 0, M)
                {
                    if (A[i + k][j + l] != B[k][l])
                    {
                        ok = false;
                        break;
                    }
                }
                if (!ok) break;
            }

            if (ok)
            {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
int n,m,o;
while(cin>>n>>m,n!=0&&m!=0){

vector<pair<int, int> > pairs(m);
 for (int i = 0; i < m; i++) {
    pairs[i] = make_pair(0, i);
  }

for(int j=0;j<n;j++){
for(int r=0;r<m;r++){
cin>>o;
if(o==1){
pairs[r].first=pairs[r].first-1;
}
}
}
sort(pairs.begin(), pairs.end());
for(int q=0;q<m-1;q++){
cout<<pairs[q].second+1<<" ";
}
cout<<pairs[m-1].second+1<<endl;
}
	return 0;
}

Measured memory_bytes: 1200
from itertools import combinations
N = list(map(int, input()))
K = int(input())

nlen = len(N)
ans = 0
if K <= nlen:
    cmb = [9] * nlen
    for n in N:
        if n != 0:
            cmb[0] = n - 1
            for x in combinations(cmb, K):
                y = x[0]
                for z in x[1:]:
                    y *= z
                ans += y
            if K == 1:
                ans += 1
                break
            K -= 1
        cmb.pop()
print(ans)

Measured memory_bytes: 3064
S = str(input())

def judge(s):
    if len(s)%2 == 1:
        return 0
    else:
        for i in range(int(len(s)/2)):
            if s[i]!=s[int(len(s)/2)+i]:
                return 0
        return 1

    
x = len(S)
for i in range(1,len(S)):
    S = S[:-1]
    if judge(S)== 1:
        print(x-i)
        break



Measured memory_bytes: 3060
// [[ABC134C] Exception Handling] https://www.luogu.com.cn/problem/AT4843
#include <algorithm>
#include <iostream>
using namespace std;
string s;
int main() {
  cin >> s;

  const int slen = s.length();
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < slen; i++) {
    if (s[i] - '0' != i % 2) {
      ans1++;
    } else {
      ans2++;
    }
  }

  cout << min(ans1, ans2) << endl;

  return 0;
}


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

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

const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        sum += p[i];
    }
    cout << sum - *max_element(p.begin(),p.end())/2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (a, b) = get!(u64, u64);

    println!("{}", a * b + 1 - a - b);
}


Measured memory_bytes: 8572
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 1e5, MaxM = 2e5;
int n, m, all, col[MaxN + 5], cnt[5];
int pre[MaxM + 5], last[MaxN + 5], other[MaxM + 5];
bool flag, vis[MaxN + 5];

void Build(int x, int y)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
}

void Init()
{
	all = -1; memset(last, -1, sizeof(last));
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		Build(u, v); Build(v, u);
	}
}

void Dfs(int x, int fa, int t)
{
	vis[x] = true; col[x] = t;
	int ed = last[x], dr;
	while (ed != -1) {
		dr = other[ed];
		if (dr != fa) {
			if (!vis[dr]) Dfs(dr, x, t ^ 1);
			else if (col[dr] == col[x]) flag = true;
		}
		ed = pre[ed];
	}
}

void Solve()
{
	memset(col, -1, sizeof(col));
	memset(vis, 0, sizeof(vis));
	memset(cnt, 0, sizeof(cnt));
	flag = false;
	Dfs(1, -1, 0);
	for (int i = 1; i <= n; i++) cnt[col[i]]++;
	if (flag) printf("%lld\n", (LL)n * (LL)(n - 1) / 2 - m);
	else printf("%lld\n", (LL)cnt[0] * (LL)cnt[1] - m);
}

int main()
{
	while (~scanf("%d%d", &n, &m)) {
		Init();
		Solve();
	}
	return 0;
}

Measured memory_bytes: 4096
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

    int kosuu = 0;
    int x = 1;
    while(x < b){
        x = x + (a - 1);
        kosuu++;
    }
    cout << kosuu << endl;
}


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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }

const long long INF = 1LL << 60;

bool dp[100100];

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

    vector<int>A(N);
    rep(i,N)cin >> A[i];

    rep(i,N){
        if(A[i]%2 ==0){
            if(A[i]%3 != 0 && A[i]%5 !=0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;

}



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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 200000+100;
ll n;
ll a[SIZE],aa[SIZE];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        aa[i] = a[i];
    }
    sort(aa,aa+n);
    for(int i = 0; i < n; i++){
        if(a[i] == aa[n-1]) cout << aa[n-2] << endl;
        else
        {
            cout << aa[n-1] << endl;
        }
    }
}

Measured memory_bytes: 4736
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

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

    ll a,n,x;
    cin>>a>>n;
    ll sum=0;
    ifr(i,0,n) cin>>x,sum+=x;
    if(sum<a) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long B, long long C){
	int s[3];
	s[0] = A;
	s[1] = B;
	s[2] = C;
	bool OK = false;
	sort(s,s+3);
	if((s[0]==5)&&(s[1]==5)&&(s[2]==7)){
		OK = true;
	}
	if(OK==true){
		cout << YES << endl;
	}else{
		cout << NO << endl;
	}

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

main(){
 int i,j;
 int H,W;

while(1){
 scanf("%d %d",&H,&W);

 if(H==0 && W==0){
 break;}

 for(i=1;i<=H;i++){
  for(j=1;j<=W;j++){

  printf("#");
  }
  printf("\n");
 }
 
 printf("\n");
}

return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n,m,x;cin>>n>>m>>x;
    int before=0,after=0;
    rep(i,m){
        int tmp;cin>>tmp;
        (tmp<x)?before++:after++;
    }
    co(min(before,after));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------
int n;
vector<pair<int,int>> tasks;
//------------------------------------------------
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    tasks.emplace_back(b,a);//（締め切り、所要時間）
  }

  sort(tasks.begin(),tasks.end());
  int sum=0;
  bool isyes=true;
  for(auto v : tasks){
    sum +=v.second;

    if(sum>v.first){
      isyes=false;
      break;
    }
  }
  if(isyes) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 2420
from ctypes import *
import subprocess as sp
from operator import itemgetter
import sys
import os.path

set_code = r"""
#include <set>

std::set<int> s;

void add(int x) {
    s.insert(x);
}

bool find(int x) {
    return s.find(x) != s.end();
}

void remove(int x) {
    s.erase(x);
}

bool empty() {
	return s.empty();
}

int getMin() {
	return *s.begin();
}
"""

class CppSet:
	counter = 0

	def __init__(self):
		lib_name = './hoge{}.so'.format(CppSet.counter)

		code_file_name = "tmp.cpp"
		with open(code_file_name, "w") as f:
			f.write(set_code)

		CppSet.counter += 1
		sp.Popen(['g++', '-fPIC', '-shared', '-std=c++11', '-O2', code_file_name, '-o', lib_name]).communicate()

		lib = CDLL(lib_name)
		self.add = getattr(lib, "_Z3addi")
		self.find = CFUNCTYPE(c_bool, c_int)(
						("_Z4findi", lib),
						((1, "x"), )
					)
		self.remove = getattr(lib, "_Z6removei")
		self.empty = CFUNCTYPE(c_bool)(
						("_Z5emptyv", lib),
						()
					)

		self.getMin = CFUNCTYPE(c_int)(
						("_Z6getMinv", lib),
						()
					)

def main():
	N, Q = map(int, sys.stdin.readline().split())
	tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
	stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]
	stx.sort()
	
	D = [int(sys.stdin.readline()) for _ in range(Q)] 
	ans = [-1]*Q

	idx = 0
	stx_len = len(stx)
	se = CppSet()
	for i, d in enumerate(D):
		while idx < stx_len:
			t, com, x = stx[idx]
			if t > d:
				break
			if com == 1:
				se.add(x)
			else:
				se.remove(x)
			idx += 1
		ans[i] = (-1 if se.empty() else se.getMin())

	print(*ans, sep='\n')

if __name__ == "__main__":
	main()


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

#define HASH 200003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, dp[26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (k = 0; k < 26; k++) {
				if (dp[k] == 0) continue;
				T[j] = 'a' + k;
				h[0] = (tmp * k + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (p->l == l[i] - j && lex_smaller(&(T[j]), p->s) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 17364
// 
#include <bits/stdc++.h>
using namespace std;
#define ll 		long long int
#define pii 	pair<int,int>
#define vi 		vector<int>
#define mii 	map<int,int>
#define pb 		push_back
#define mp 		make_pair
#define ff 		first
#define ss 		second
#define MOD 	1000000007
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,k;
	cin>>n;
	int a[n][3],i,j;
	for(i=0;i<n;i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];


	int dp[n][3],temp;
	// dp[0]=INT_MIN;
	for(i=0;i<3;i++)
	{
		dp[0][i]=a[0][i];
	}
	
	for(i=1;i<n;i++)
	{
		for(j=0;j<=2;j++)
		{
			int op1,op2,op3;
			op1=(j==0)?INT_MIN:dp[i-1][0];
			op2=(j==1)?INT_MIN:dp[i-1][1];
			op3=(j==2)?INT_MIN:dp[i-1][2];

			dp[i][j]=a[i][j]+max(op1,max(op2,op3));			
		}
	}
	// for(i=0;i<n;i++)
	// {
	// 	for(j=0;j<=2;j++)
	// 		cout<<dp[i][j]<<" ";

	// 	cout<<"\n";
	// }
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> L(m);
  rep(i,m) cin >> L[i];
  sort(L.begin(), L.end());
  vector<int> l(m-1);
  rep(i,m-1) l[i] = L[i+1] - L[i];
  sort(l.begin(), l.end());
  if (m <= n) cout << 0 << endl;
  else{
    int ans = 0;
    rep(i,m-n) ans += l[i];
    cout << ans << endl;  
  }
}
  

Measured memory_bytes: 1024
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    }
    println!("{}",max(a+b,max(a+a-1,b+b-1)))
}

Measured memory_bytes: 2136
parseInt(x) = parse(Int,x)

function main()
  S = readline()
  j = 1
  for i = 1:3
    if S[i] == S[i+1]
      j = 0
    end
  end
  if j== 1
    println("Good")
  else
    println("Bad")
  end
end

main()


Measured memory_bytes: 165836
#include <stdio.h>

int main(void) {
	int M;
	int A[50] = {0};
	int i;
	int a, b;
	int n;

	scanf("%d %d", &n, &M);


	for (i = 0; i < M; i++) {
		scanf("%d %d", &a, &b);
		A[a - 1]++;
		A[b - 1]++;
	}
	
	for (i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define fi first
#define se second

ll oe_solve(std::vector<ll> &a, bool minus){
	ll ans = 0, sum = 0;
	if(minus){
		sum = -1;
		if(a[0]>=0) ans += a[0]+1;
		else sum = a[0];
	}else{
		sum = 1;
		if(a[0]<=0) ans -= a[0]-1;
		else sum = a[0];
	}
	REP(i, 1, a.size()){
		if(sum>0){
			sum += a[i];
			if(sum>=0){
				ans += sum+1;
				sum = -1;
			}
		}else{
			sum +=a[i];
			if(sum<=0){
				ans -= sum-1;
				sum = 1;
			}
		}
	}
	return ans;
}


int main(){
	int n;
	scanf("%d", &n);
	std::vector<ll> a(n, 0);
	REP(i, 0, n) scanf("%ld", &a[i]);
	printf("%ld\n", std::min(oe_solve(a, true), oe_solve(a, false)));
	return 0;
}



Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
void chmin(int &a, int b) {if(a > b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int n;
    cin >> n;
    vi a(n);
    a[0] = 0;
    rep(i,1,n){cin >> a[i];}
    map<int,int> mp;
    repn(i,1,n){
        mp[i] = 0;
    }
    rep(i,1,n){
        mp[a[i]]++;
    }
    repn(i,1,n){
        cout << mp[i] << endl;
    }
    

}

Measured memory_bytes: 13556
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k, s, t, a[60], sz, tc, dsz;
long long comb[51][51], acc[51], occ[18][2], ans;
vector<int> vec, tmp[10], dat;

int my_popcount(long long x)
{
	int cnt = 0;
	long long cur = 1LL;
	for (int i = 0; i < 63; i++) {
		if (x & cur) cnt++;
		cur = cur << 1;
	}
	return cnt;
}

void fun(int pos, int sign, long long candi)
{
	if (pos == 18) {
		long long u = (acc[my_popcount(candi)]) * sign;
		ans += u;
		//tmp[tc].pb(u);

	}
	else {
		fun(pos + 1, sign, candi);
		fun(pos + 1, -sign, candi & (occ[pos][0]));
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k >> s >> t;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if ((s & t) != s) {
		cout << 0 << "\n";
		return 0;
	}
	for (int i = 0; i < n; i++) {
		if (((a[i] & s) == s) && ((a[i] | t) == t)) {
			vec.pb(a[i]);
		}
	}
	sz = vec.size();
	for (int i = 0; i <= sz; i++) {
		comb[i][0] = 1;
	}
	for (int i = 1; i <= sz; i++) {
		for (int j = 1; j <= i; j++) {
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
		}
	}
	for (int i = 0; i <= sz; i++) {
		for (int j = 1; j <= min(k - 1, i); j++) {
			acc[i] += comb[i][j];
		}
	}
	
	for (int i = 0; i < sz; i++) {
		dat.clear();
		for (int j = i + 1; j < sz; j++) {
			dat.pb((vec[i] ^ vec[j]) | s | (~t));
		}
		dsz = dat.size();
		memset(occ, 0, sizeof(occ));
		for (int r = 0; r < dsz; r++) {
			for (int j = 0; j < 18; j++) {
				occ[j][(dat[r] >> j) & 1] += 1LL << r;
			}
		}
		if (s == t && vec[i] == t) ans++;
		tc = i;
		fun(0, 1, (1LL << dsz) - 1);
	}
	cout << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string.h>
#include<string>
#include<functional>
#include<set>
using namespace std;

#define INF 1<<21
#define DIV 1000000007
#define MAX 250000

int table[51][51];
int W, H;

void dfs(int x, int y) {
  table[y][x] = 0;

  for (int dx = -1; dx <= 1; dx++) {
	for (int dy = -1; dy <= 1; dy++) {
	  int nx = x + dx, ny = y + dy;
	  if (0 <= nx&&nx < W && 0 <= ny&&ny < H&&table[ny][nx] == 1)dfs(nx, ny);
	}
  }
  return;
}

int main(){
  while (cin >> W >> H, W || H) {
	int ans = 0;
	memset(table, 0, sizeof(table));
	int t;
	for (int y = 0; y < H; y++) {
	  for (int x = 0; x < W; x++) {
		cin >> table[y][x];
	  }
	}

	for (int y = 0; y < H; y++) {
	  for (int x = 0; x < W; x++) {
		if (table[y][x] == 1) {
		  dfs(x, y);
		  ans++;
		}
	  }
	}
	cout << ans << endl;
  }

}

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

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    int ans = 0;

    ans = a - b;
    ans = c - ans;

    if(ans < 0)
    {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll maxn = 2e5;
const ll ZERO = 0;
const ll SADAT = 7.84e-17;
const ll INF = 1e9;
const ll mod = 1e9+7;

#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);

int n ;
string s;

int main(){
    migmig
    cin >> n;
    cin >> s;
    ll ans = 0;
    for (int i= 0 ; i < n ; i ++){
        if (i and s[i]!=s[i-1] ){
            ans++;
        }
    }
    cout << ans+1;

    return(0);
}



//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 512
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (intercalate)

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  let
    x1 = (`div` 2) . sum . zipWith (*) (cycle [1, -1]) $ as :: Int
    xs = init . scanl subtract x1 $ as :: [Int]
  putStrLn . intercalate " " . map (show . (2 *)) $ xs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 15880