akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <cstdio>
#include <cstdint>
#include <unistd.h>
#include <queue>

using i64 = std::uint_fast32_t;

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  i64 n = io::scan();
  i64 k = io::scan();
  if (k >= n) {
    puts("0");
    return 0;
  }
  i64 s = 0;
  std::priority_queue<i64> que;
  for (int i = 0; i < n; i++) {
    i64 h = io::scan();
    if (que.size() >= n - k) {
      if (que.top() > h) {
        s += h - que.top();
        que.pop();
        que.push(h);
      }
    } else {
      s += h;
      que.push(h);
    }
  }
  io::print(s);
  io::flush();
  return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll dp[55][2];

int main() {
    int n, p; cin >> n >> p;
    vector<int> Avec(n, 0);
    for(int i = 0; i < n; ++i) cin >> Avec.at(i);
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 2; ++j) {
            // 袋iを取る
            dp[i+1][(j+Avec.at(i))%2] += dp[i][j];
            
            // 袋iを取らない
            dp[i+1][j] += dp[i][j];
        }
    }

    cout << dp[n][p] << endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >>x;
  
  if(x==22)cout<<"Christmas Eve Eve Eve"<<endl;
  if(x==23)cout<<"Christmas Eve Eve"<<endl;
 
  if(x==24)cout<<"Christmas Eve"<<endl;
  if(x==25)cout<<"Christmas"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.TreeSet;
import java.io.PrintWriter;
public class Main{
	static PrintWriter writer = new PrintWriter(System.out);
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		ArrayList<State> list=new ArrayList<>();
		for(int i=0; i<n; i++){
			int s=sc.nextInt();
			int t=sc.nextInt();
			int x=sc.nextInt();
			list.add(new State(s-x,x,-2));
			list.add(new State(t-x,x,-1));
		}
		for(int i=0; i<q; i++){
			list.add(new State(sc.nextInt(),0,i));
		}
		list.sort((x,y)->x.t-y.t);
		int[] ans=new int[q];
		TreeSet<Integer> set=new TreeSet<>();
		for(int i=0; i<list.size(); i++){
			State s=list.get(i);
			if (s.v == -2) {
				set.add(s.d);
			}else if (s.v == -1) {
				set.remove(s.d);
			}else {
				ans[s.v] = set.isEmpty() ? -1 : set.first();
			}
		}
		for (int i = 0; i < q; i++) {
			writer.println(ans[i]);
		}
		writer.flush();
	}
	static class State{
		int t,d,v;
		State(int t,int d,int v){
			this.t=t;
			this.d=d;
			this.v=v;
		}
	}
}




Measured memory_bytes: 175508
#include <iostream>
#include <string>
//#include <sstream>  // istringstream
#include <vector>

using namespace std;

int main()
{
	int x = 0; 
	int y = 0;
	
	std::vector<int> gr1 = { 1, 3, 5, 7, 8, 10, 12 };
//	int gr1[] = { 1, 3, 5, 7, 8, 10, 12 };
	std::vector<int> gr2 = { 4, 6, 9, 11 };
	//int gr2[] = { 4, 6, 9, 11 };
	std::vector<int> gr3 = { 2 };
	//int gr3[] = { 2 };
	
	std::vector<std::vector<int>> grp = { gr1, gr2, gr3 };
	//int *grp[] = { gr1, gr2, gr3 };

	cin >> x >> y;

	int num1 = 0;
	int num2 = 0;
	for (int i = 0; i < 3; ++i){
		for (auto& elem : grp[i]){
			if (x == elem){
				num1 = i;
				break;
			}
		}
	}
	for (int i = 0; i < 3; ++i){
		for (auto& elem : grp[i]){
			if (y == elem){
				num2 = i;
				break;
			}
		}
	}
	if (num1 == num2){
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
class Dice2{
public:
    Dice2(){
        number = new int[6];
        relative = new int[55];
        relative[31] = relative[43] = relative[24] = relative[12] = 0;
        relative[3] = relative[20] = relative[52] = relative[35] = 1;
        relative[1] = relative[40] = relative[54] = relative[15] = 2;
        relative[4] = relative[10] = relative[51] = relative[45] = 3;
        relative[2] = relative[30] = relative[53] = relative[25] = 4;
        relative[21] = relative[42] = relative[34] = relative[13] = 5;
    };
    ~Dice2(){
        delete[] number;
        delete[] relative;
    };
 
    void setNumber(int index,int num){
        number[index] = num;
    };
 
    int returnRight(int top,int front){
        int top_index,front_index;
        for(int i = 0; i < 6; i++){
            if(number[i] == top)
                top_index = i;
            if(number[i] == front)
                front_index = i;
        }
        return number[relative[10*top_index+front_index]];
    }
private:
    int* number;
    int* relative;
};
 
int main(){
    Dice2 dice2;
    int x,q,top,front;
    for(int i = 0; i < 6; i++){
        scanf("%d",&x);
        dice2.setNumber(i,x);
    }
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%d %d",&top,&front);
        printf("%d\n",dice2.returnRight(top,front));
    }
}


Measured memory_bytes: 2760
n,t=map(int,input().split())
c=[]
tt=[]
for i in range(n):
 x,y=map(int,input().split())
 if t-y>=0:
  c.append(x)
  tt.append(y)
 else:
  c.append(1001)
  tt.append(y)

if min(c)==1001:
 print("TLE")
else:
 print(min(c))

Measured memory_bytes: 3188
var
    a,b,c:integer;
begin
    readln(a,b,c);
    if (a=5)and(b=7)and(c=5) then writeln('YES')
    else if (a=5)and(b=5)and(c=7) then writeln('YES')
    else if (a=7)and(b=5)and(c=5) then writeln('YES')
    else writeln('NO');
end.

Measured memory_bytes: 128
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())

S = list()
num = {}
ans = 0

for i in range(N):
    S.append(list(input()))
    S[i].sort()
    if "".join(S[i]) in num:
        num["".join(S[i])] += 1
        ans += num["".join(S[i])]
    else:
        num["".join(S[i])] = 0

print(ans)

Measured memory_bytes: 37668
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;


int main(){
  char a[13], b[14];
  scanf("%s", a);
  rep(i,4){
    b[i]=a[i];
  }
  b[4]=' ';
  rep(i,9){
    b[i+5]=a[i+4];
  }
  printf("%s\n", b);
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int y[10010];
int main(void)
{
    while (1) {
        int n, a, b, c, x, i, j, res;
        scanf("%d%d%d%d%d", &n, &a, &b, &c, &x);
        if (n==0) break;

        for(i=0;i<n;++i) scanf("%d", y+i);

        res=j=0;
        for(i=0;i<10001;++i) {
            if (y[j]==x) {
                res=i;
                y[j]=-1;
                if (++j==n) break;
            }
            x=(x*a+b)%c;
        }
        printf("%d\n", j<n ? -1 : res);
    }
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int n, k, w[100010];
int a(int P);
int main(){
  int i,l=0,h =1000100000,m;
  scanf("%d%d",&n,&k);
  for( i=0; i<n; i++){
    scanf("%d",&w[i]);
  }
  while(l+1 < h){
     m = (l+h)/2;
    if(a(m)){
      h = m;
    }
    else{
      l = m;
    }
  }
  printf("%d\n", h);
}
int a(int P){
  int x = 0, y = 1,i,j;
  for( j=0; j<n; j++){
    if(w[j] > P){
      return 0;
    }
    else{
      if(x+w[j] <= P){
    x += w[j];
      }
      else{
    y++;
    x = w[j];
      }
    }
  }
  if(y<=k) return 1;
  else return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    
    int n = s.size(), m = t.size();
    
    vector<vector<int>> is(26);
    
    for (int i = 0; i < n; i++) is[s[i]-'a'].push_back(i);
    for (int i = 0; i < n; i++) is[s[i]-'a'].push_back(i+n);
    
    long long ans = 0;
    
    int p = 0;
    
    for (int i = 0; i < m; i++){
        int c = t[i] - 'a';
        if (is[c].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        
        p = *lower_bound(is[c].begin(),is[c].end(),p) + 1;
        if (p >= n) p -= n, ans += n;
    }
    
    ans += p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4644
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n,k=map(int,input().split())
    P=[int(_) for _ in input().split()]
    PP=[0]*n
    for i in range(n):
        PP[i]=(P[i]+1)/2
    PP_ac=list(accumulate(PP))
    ans=PP_ac[k-1]
    for i in range(1,n-k+1):
        ans=max(ans,PP_ac[i+k-1]-PP_ac[i-1])
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 25148
n, @a, @b=gets.split.map(&:to_i)
@hp=[]
n.times{@hp << gets.to_i}

def check(t)
  _t=0
  @hp.each do |e|
    res=e-@b*t
    next if res<=0
    _t+=[0, (res+@a-@b-1)/(@a-@b)].max
  end
  _t<=t
end

l, u=0, 2*(@hp.inject(:+)+@a-1)/@a
while u-l>1
  m=(u+l)/2
  if check(m)
    u=m
  else
    l=m
  end
end

puts u


Measured memory_bytes: 2996
/*************************************************************
1191026-001_cpp_AGC033A
AtCorer問題を解いてC++を学習するためのCのコードの写経
処理時間最短コードにて写経する
アルゴリズム学習

＜情報＞
学習完了したのち、long long を long long に変更したり、
余計なインクルードを削除したりしたら、AT出来なくなってしまったようだ。
だが、アルゴリズムの学習は完了しており、このままで学習完了とする。 

思い直して完成を試みる
*************************************************************/
#include <stdio.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

typedef long long ll;

int main(void)
{
	ll H, W;
	scanf("%lld %lld", &H, &W);
	char A[H][W];

	for (ll i = 0; i < H; i++)
	{
		scanf("%s", &A[i]);
	}
	ll dp[H][W];
	for (ll i = 0; i < H; i++)
	{
		for (ll j = 0; j < W; j++)
		{
			dp[i][j] = 2000;
		}
	}

	int tmp = 2000;

	for (ll i = 0; i < H; i++)
	{
		tmp = 2000;

		for (ll j = 0; j < W; j++)
		{
			if (A[i][j] == '#')
			{
				dp[i][j] = 0;
				tmp = 1;
			}
			else
			{
				dp[i][j] = MIN(dp[i][j], tmp);
				tmp++;
			}
		}
	}
	for (ll j = 0; j < W; j++)
	{
		for (ll i = 0; i < H; i++)
		{
			if (i == 0)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i - 1][j] + 1);
		}
	}
	for (ll i = H - 1; i >= 0; i--)
	{
		for (ll j = W - 1; j >= 0; j--)
		{
			if (j == W - 1)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i][j + 1] + 1);
		}
	}

	for (ll j = W - 1; j >= 0; j--)
	{
		for (ll i = H - 1; i >= 0; i--)
		{
			if (i == H - 1)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i + 1][j] + 1);
		}
	}

	ll ans = 0;

	for (ll i = 0; i < H; i++)
	{
		for (ll j = 0; j < W; j++)
		{
			ans = MAX(ans, dp[i][j]);
		}
	}
/*
	for(int i = 0; i < H; i++)
	{
	    for(int j = 0; j < W; j++)
		{
	        printf("\t%lld",dp[i][j]);
	    }
	    printf("\n");
	}
*/
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 8960
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n,q;
    cin>>n>>q;
    Graph G(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    V<ll> c(n,0);
    while(q--){
        int p;
        ll x;
        cin>>p>>x;
        p--;
        c[p]+=x;
    }
    V<ll> dist(n,-1);
    queue<int> que;
    dist[0]=0;
    que.push(0);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int nv:G[v]){
            if(dist[nv]!=-1) continue;
            dist[nv]=dist[v]+1;
            c[nv]+=c[v];
            que.push(nv);
        }
    }
    rep(i,n) cout<<c[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 17908
#include <bits/stdc++.h>
using namespace std;
#define INF 1005

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("input.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    string a;
    cin >> n >> a;
    string aa,bb;
    aa=a.substr(0,n/2);
    bb=a.substr(n/2,n);
    if(aa==bb)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
D[13][3]={{1,0,0},{0,1,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,-1,0},{1,0,-1},{0,1,-1},{1,1,1},{-1,1,1},{1,-1,1},{1,1,-1}};
M[9][9][9],q[2];main(n,m,p,I,x,y,z,j,c,d){for(;scanf("%d%d%d",&n,&m,&p),n;){
	for(memset(M,0,sizeof(M)),c=1,I=0;I<p;c*=-1){
		scanf("%d%d",&x,&y),I++;
		for(z=1;;z++)if(!M[x][y][z]){M[x][y][z]=c;break;}
		for(d=0;d<13;d++){
			for(j=0;j<2;j++)for(q[j]=0;q[j]<m;q[j]+=2*j-1)if(M[x+D[d][0]*q[j]][y+D[d][1]*q[j]][z+D[d][2]*q[j]]!=c)break;
			if(q[1]-q[0]-1>=m){printf("%s %d\n",c==1?"Black":"White",I);goto next;}
		}
	}
	puts("Draw");
next:
	for(;I++<p;)scanf("%d%d",&x,&y);
}exit(0);}

Measured memory_bytes: 612
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int solve(string x, string y) {
  int dp[x.size() + 1][y.size() + 1];
  memset(dp, 0, sizeof(dp));
  rep(i, 0, x.size()) {
    rep(j, 0, y.size()) {
      if(x[i] == y[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }
  return dp[x.size()][y.size()];
}

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

  int q;
  cin >> q;
  vector<int> rsl;
  rep(i, 0, q) {
    string x, y;
    cin >> x >> y;
    rsl.push_back(solve(x, y));
  }
  rep(i, 0, rsl.size()) cout << rsl[i] << endl;
}



Measured memory_bytes: 7124
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define pb push_back
#define mp make_pair
#define inff 100000
#define ff first
#define ss second
#define sz(x) ((int) (x).size())
#define fast cin.sync_with_stdio(0);cin.tie(0)
#define rep(i,N) for(int i = 0;i < N;i++)
#define frep(i,a,b) for(int i = a;i <= b;i++)
#define pii pair<int , int>
#define pll pair<ll , ll>
#define vii vector<int>
#define vpii vector< pii >
#define fill(A,v) memset(A,v,sizeof(A))
#define setbits(x) __builtin_popcountll(x)
#define print(A,j,k) for(int ii=j;ii<k;ii++)cout<<A[ii]<<" ";cout<<"\n"
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
#define CASES int t;cin>>t;while(t--)
#define FILE freopen("inp.txt" , "r" , stdin);
#define ld long double

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
const int K = (1 << 17) + 10;
const ll INF = 2e18 + 500;
const int inf = 0x7fffffff;
const int SQRT = 500;
const int lgN = 20;

int cc = 0;
vii V[N] , G[N];
vii comp , bc;
int A[N] , B[N];
int ans;
int sol[N];

void dfs(int u) {
	A[u] = cc;
	for(auto v : V[u])
		if (A[v] == 0)
			dfs(v);
}

void sdfs(int u) {
	B[u] = cc;
	for(auto v : G[u])
		if (B[v] == 0)
			sdfs(v);
}

int main(int argc, char const *argv[])
{
	fast;

	int n , k , l;
	cin >> n >> k >> l;

	rep(i , k) {
		int a , b;
		cin >> a >> b;
		V[a].pb(b);
		V[b].pb(a);
	}

	rep(i , l) {
		int a , b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
	}

	frep(i , 1 , n) {
		if (A[i] == 0) {
			++cc;
			dfs(i);
		}
	}

	cc = 0;
	frep(i , 1 , n) {
		if (B[i] == 0) {
			++cc;
			sdfs(i);
		}
	}

	map < pii , int > M;

	frep(i , 1 , n)
		M[{A[i] , B[i]}]++;

	frep(i , 1 , n)
		cout << M[{A[i] , B[i]}] << ' ';
	cout << '\n'; 

	return 0;
}

Measured memory_bytes: 65408
#include <atcoder/dsu>
#include<iostream>
#include <vector>
using namespace std;
using namespace atcoder;

int main(){
   int N, M;
   cin>>N>>M;
   dsu ds(N);
   for(int i=0;i<M;i++){
       int a,b;
       cin>>a>>b;
       ds.merge(a-1,b-1);
   }

    vector<vector<int>> gp;
    int ans;
    gp=ds.groups();
    ans=gp.size()-1;

    cout<<ans<<endl;

}

Measured memory_bytes: 8912
import std.stdio;
import std.algorithm;
import std.math;
void main(){
	int n;
	readf("%d\n", &n);
	while(n--){
		int a, b, c;
		readf("%d %d %d\n", &a, &b, &c);
		int max_e = max(a, max(b, c));
		if(pow(max_e, 2) == pow(a+b+c - max_e, 2) - 2 * a*b*c / max_e)
			writeln("YES");
		else
			writeln("NO");
	}
}

Measured memory_bytes: 1000
R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(N//R+1):
    tmp = N - R*r
    for g in range(tmp//G+1):
        check =  tmp - G*g
        if check%B == 0 and check >= 0:
            ans += 1
print(ans)

Measured memory_bytes: 9188
#include<stdio.h>
int main()
{
  int x, y, r, tmp;
  scanf("%d%d", &x, &y);
  if(x < y)
    {
      tmp = x;
      x = y;
      y = tmp;
    }
  r = x % y;
  while(r != 0)
    {
      x = y;
      y = r;
      r = x % y;
    }
  printf("%d\n", y);
  return 0;
}



Measured memory_bytes: 2072
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, M, a[100009][3], maxn = -(1LL << 30);
 
int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { 
                if ((i / (1 << k)) % 2 == 0) 
                    S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3636
import math

a, b, x = map(float, input().split())
xx = x / (a**2)

if xx < b / 2:
	aa = ((a * xx) * 2) / b
	ans_2 = math.degrees(math.atan(aa/b))
	ans = 90 - ans_2
else:
	bb = b - xx
	aa = a / 2
	ans_2 = math.degrees(math.atan(bb/aa))
	ans = ans_2


print(ans)

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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> A>>B;
	ans = A + B;
	if (ans >= 24) {
		ans -= 24;
	}
	cout << ans;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll,ll>> v(n);
    for(auto& i : v) cin >> i.first >> i.second;
    sort(all(v));

    auto fn = [](pair<ll,ll> a, pair<ll,ll> b){return a.first > b.first;};

    ll ans = 0, dmg = 0;
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, decltype(fn)> que(fn);

    REP(i, n){
        ll x = v[i].first, h = v[i].second;
        while(!que.empty() && que.top().first < x){
            dmg -= que.top().second;
            que.pop();
        }

        h = max(0LL, h - dmg);

        if(h > 0){
            ll cnt = Div(h, a);
            ans += cnt;
            dmg += cnt * a;
            que.push(make_pair(x + 2*d, cnt*a));
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5492
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    cin>>n;
    ll limit=sqrt(n);
    ll ans=inf;
    RFOR1(i,limit)
    {
        if(n%i==0)
        {
            ll x=n/i;
            ll y=i;
            ans=min(x+y-2,ans);
        }
    }
    cout<<ans<<endl;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


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

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

	int n = s.size();
	vector<int> d( n );
	for( int i = 0; i < n; i++ ) {
		int c = s[i] - 'a';
		d[i] = 0;
		if( c ) {
			d[i] = 26 - c;
		}
	}
	string ans;
	for( int i = 0; i < n; i++ ) {
		if( d[i] == 0 || d[i] > K ) {
			ans += s[i];
		}
		else {
			ans += 'a';
			K -= d[i];
		}
	}
	int c = ans[n - 1] - 'a';
	c += K;
	c = c % 26;
	ans[n - 1] = 'a' + c;

	cout << ans << endl;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

const int N = 200005;
const int M = (1 << 26) + 3;

const int inf = 1000*1000*1000 + 7;

int n;
char s[N];
int f[N], g[M];

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

	cin >> (s + 1);
	n = strlen(s + 1);
	FOR (i, 1, n) s[i] -= 'a';
	REP(i, M) g[i] = inf;
	int cur = 0;
	g[cur] = 0;
	FOR (i, 1, n) {
		cur ^= (1 << s[i]);
		f[i] = inf;
		f[i] = min(f[i], g[cur] + 1);
		REP(j, 26) f[i] = min(f[i], g[cur^(1<<j)] + 1);
		g[cur] = min(g[cur], f[i]);
	}

	cout << f[n] << '\n';

	return 0;
}

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

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

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int main(void){
	int n;
	while(cin >> n,n){
		int t[55],c[55];
		rep(i,n) cin >> t[i] >> c[i];

		int ans=0;
		struct state{
			int t,res,v;
			bool operator < (const state &arg) const {return v < arg.v;}
		};

		queue<state> que[2];
		rep(i,n) que[0].push({0,c[i],t[i]});

		while(!que[0].empty()||!que[1].empty()){
			int f= que[0].empty() || (!que[1].empty() && que[1].front().t < que[0].front().t);
			ans=que[f].front().t;
			vector<state> ary;
			while(!que[f].empty() && que[f].front().t<=ans){
				ary.push_back(que[f].front());
				que[f].pop();
			}
			sort(_all(ary));
			for(auto &it:ary) if(it.res){
				it.t=ans+it.v;
				it.res-=f;
				que[f^1].push(it);
			}
		}

		cout << ans << endl;
	}	
	return 0;
}

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

int main() {
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double ans=sqrt(a*a+b*b-2*a*b*cos((h*60-11*m)*3.14159265358979/360));
  printf("%.10lf\n", ans);
}


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

int main()
{
	int p, q, r;
	int l;
	cin >> p >> q >> r;

	for (int i = 0; i < 6; i++)
	{
		if (i == 0)
		{
			l = p + q;
		}
		else if (i == 1)
		{
			if (r + q <= l)
			{
				l = r + q;
			}
		}
		else if (i == 2)
		{
			if(p + r <= l)
			l = p + r;
		}
		
		else if (i == 3) {

		
			if(q + r <= l)
			l = q + r;
		}
		else if (i == 4)
		{
			if(r + p <= l)
				l = r + p;
		}
		else if (i == 5)
		{
			if(q + p <= l)
				l = q + p;
		}
		
	}
	cout << l  << endl;
}

Measured memory_bytes: 256
n = int(input())
la = [int(w) for w in input().split()]
lb = [int(w) for w in input().split()]
ld = [a-b for a, b in zip(la, lb)]
if sum(ld) < 0:
    print(-1)
    exit()

llower = [w for w in ld if w < 0]
lupper = [w for w in ld if w > 0]
lowsum = sum(llower)
lupper.sort(reverse=True)

ans = len(llower)

for d in lupper:
    if lowsum >= 0:
        break
    ans += 1
    lowsum += d


print(ans)


Measured memory_bytes: 24060
n=input()
s=list(input())

tmp=s[0]
i=0
cnt=1
flag=0
ss=[]
for i in range(1,len(s)):
    if s[i] != tmp:
        cnt+=1
        tmp = s[i]
        flag = 1
        # ss.append(s[i])
if flag == 0 and cnt ==0:
    cnt +=1

print(cnt)


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

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

Measured memory_bytes: 3540
#include "bits/stdc++.h"
#include <iostream>
using namespace std;
#define ll = long long;
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main()
{
	int n, m;
	cin >> n >> m;
	cout << max(0, n - m - m) << endl;
}
/*


  　　　 _」_
　 　×´　　　  _,,..-──-､,_ｧo､__　　  ｀メ.
　　/　    ,  '"´　 　　　   （-､__oヽ　　　_|__
　 　　　／　　　　　　　　 　 ｀ヽ.ヽﾊ）　 　ﾉ
　　　 ／　　　　　　　　　　　  　 Y⌒ヽ.
　　  /　　 /　　　　　　     ヽ.　 |　　',
　　 ,'　　!　　,　 /!　,| ＿   !.　|　　 !　　
　　　|　  |.__/|_ ,'| / ! __｀./! /|　　 |
　　　|　　|´/ |_/  ﾚ' ｧ'´￣` |／､ﾄ、 　|　　奇跡を起こして計算量をO(N)にします!
　　  '､　 |/ｧ'´￣`  　　　,,　|　|ｿ   　ﾊ　　
　　 　 ＼,ハ ,,　　 '　   　（ ＼|　 / .|
　　　 　 | ﾊ、　i7´￣｀i  ,/ ＼_）,'　 |
　　　　 ,'/｀＞ ､,｀   ,.イ/＼＿_! !　  !　　|
　　 　　/　 /｀     T7´／/ヽ､_＿ﾉ_| 　 |__,メ
　　 　　|  .|r/´`ｰ'-､／　,'./  /::/｀ヽ /
　　　　 八　i/      rﾉ,!￣ヽ､| /:/ 　  i_
　　  　,' X`;くﾄ  ､ノ､　/ﾍ｀ヽ．Y    ／::>
　　　　!　// |::|/.|::|＼/ﾉ 八__ノr:':::／/
　　　　|／　 |::|./|::|/　 ）'ﾉ:/--‐'','
　  　  /　　 八:' _ﾉ::ﾉ　 _,.ｲ／　　　　|
　　 　,'　　　 ＼_ ／,|　 　／　　　 　 !
　　　 |　　　　　　  /|　 ／ 　　　/ 　 |
*/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef long long ll;
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"         here"<<en
#define out(value) cout<<value<<en

int building[105][105];
int ranking[105][105];
bool done[105][105];

int ilumi_x[2][6]={{1,0,-1,-1,-1,0},{1,0,-1,0,1,1}};
int ilumi_y[2][6]={{0,1,1,0,-1,-1},{0,1,0,-1,1,-1}};

int main(){
  int w,h;
  cin>>w>>h;
  
  for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
    cin>>building[i][j];
    done[i][j]=false;
    if(building[i][j]) continue;
    if(i==1||j==1||i==h||j==w) ranking[i][j]=1;
  }
  
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      if(done[i][j]) continue;
      if(building[i][j]) continue;
      if(i==1||i==h||j==1||j==w){
        ranking[i][j]=1;
        done[i][j]=1;
        queue<P> que;
        que.push(mk(i,j));
        while(!que.empty()){
          P p=que.front(); que.pop();
          int yy=p.first,xx=p.second;
          for(int k=0; k<6; k++){
            int x=xx+ilumi_x[yy%2][k];
            int y=yy+ilumi_y[yy%2][k];
            if(x<1||x>w||y<1||y>h) continue;
            if(done[y][x]==1) continue;
            if(building[y][x]==1) continue;
              
            done[y][x]=1;
            ranking[y][x]=1;
            que.push(mk(y,x));
          }
        }
      }
    }
  }
  
  int ans=0;
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      if(building[i][j]==0) continue;
      for(int k=0; k<6; k++){
        int x=j+ilumi_x[i%2][k];
        int y=i+ilumi_y[i%2][k];
        
        if(y<1||y>h||x<1||x>w) {
          ans++;
          continue;
        }
        if(ranking[y][x]==1) ans++;
      }
    }
  }
  cout<<ans<<en
}




Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

//負の辺が存在する場合
// O(E*V)
//負閉路がスコアに寄与しないパターンを考えよう
struct edge{
    int from;
    int to;
    ll cost;
};

const int MAX_V=2525;
vector<int> to[MAX_V],from[MAX_V];
bool toN[MAX_V];
bool from1[MAX_V];
bool ok1N[MAX_V];
void dfs(int v){
    if(from1[v]) return;
    from1[v]=1;
    for(int u:to[v]){
        dfs(u);
    }
}
void rdfs(int v){
    if(toN[v]) return;
    toN[v]=1;
    for(int u:from[v]){
        rdfs(u);
    }
}

signed main(){
    int n,m;
    ll p;
    cin >> n >> m >> p;
    vector<edge> v;
    rep(i,m){
        int a,b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        to[a].pb(b);
        from[b].pb(a);
        c-=p;
        edge e={a,b,-c};
        v.pb(e);
    }
    dfs(0);
    rdfs(n-1);
    rep(i,n){
        ok1N[i]=toN[i]*from1[i];
    }
    ll d[n];
    rep(i,n) d[i] = 1e18;
    d[0]=0;
    //for(auto e:v) cout << e.from <<" "<<e.to<<" "<<e.cost<<endl;
    bool ng=0;
    rep(i,n){
        rep(j,v.size()){
            edge e = v[j];
            if(!ok1N[e.to]||!ok1N[e.from]) continue;
            if(d[e.to] > d[e.from]+e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i==n-1){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << max(0LL,-d[n-1]) << endl;
}


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


def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input().rstrip()

    n_win = {"r": 0, "s": 0, "p": 0}
    lock = [False] * N
    for i in range(K):
        n_win[T[i]] += 1
        lock[i] = True
    for i in range(K, N):
        if T[i-K] == T[i]:
            if not lock[i-K]:
                n_win[T[i]] += 1
                lock[i] = True
        else:
            n_win[T[i]] += 1
            lock[i] = True

    ans = R * n_win["s"] + S * n_win["p"] + P * n_win["r"]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4084
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const ll oo = 1e15, N = 2e5 + 10;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	if(s == "ABC")s = "ARC";
	else s = "ABC";
	cout << s << '\n';
}

Measured memory_bytes: 3648
N = int(input())
p = list(map(int, input().split()))

i = 0
ans = 0
while i < N:
  if p[i] == i+1:
    if (i+1<N) and (p[i+1]==i+2):
      ans += 1
      i += 2
    else:
      ans += 1
      i += 1
  else:
    i += 1
print(ans)

Measured memory_bytes: 20620
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]

manzoku = 0
log = [-1] * 26
for i in range(d):
    max = 0
    maxi = 0
    for j in range(26):
        karilog = log
        kari = s[i][j]
        karilog[j] = i
        for k in range(26):
            kari -= c[k] * (i-karilog[k])
        if max < kari:
            max = kari
            maxj = j
    print(maxj+1)
    manzoku += max
    log[maxj] = i

Measured memory_bytes: 9396
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int n, m, q, ans = 0;
int a[55], b[55], c[55], d[55], v[15];

void dfs(int now, int val) {
    if (now == n) {
        // for (int i = 0; i < n; ++i) cout << v[i] << " \n"[i == n-1];
        int tmp = 0;
        for (int i = 0; i < q; ++i) {
            if (v[a[i]] + c[i] == v[b[i]]) tmp += d[i];
        }
        ans = max(ans, tmp);
        return;
    }
    
    for (int i = val; i <= m; ++i) v[now] = i, dfs(now+1, i);
}

int32_t main() {
    fastIO();
    
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i];
    }
    
    dfs(0, 1);
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    long long price = a*x + b*y;
    for(long i = 0; i <= max(x,y); i++){
        long long tmpPrice = 2*i*c + max(a*(x-i),0L) + max(b*(y-i),0L);
        //long long tmpPrice = 2*i*c;
        //tmpPrice += max(a*(x-i),0L);

        price = min(tmpPrice,price);
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 3552
n,m = map(int,input().split())
raw = []
ans = 0
for i in range(m):
  raw.append(list(map(lambda x:int(x)-1,input().split())))
for i in range(m):
  ab = [[] for _ in range(n)]
  for mi in range(m):
    if mi != i:
      try:
        here = raw[mi]
        ab[here[0]].append(here[1])
        ab[here[1]].append(here[0])
      except:
        print(ab,here,here[0],here[1])
  for ni in range(n):
    now = [ni]
    rest = [j for j in range(n)]
    for _ in range(50):
      nex = []
      for x in now:
        if x in rest:
          rest.remove(x)
        nex += ab[x]
      now = list(set(nex))
      if rest == []:
        break
    else:
      continue
    break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,d,a[222][222];
int main()
{
    scanf("%d%d",&n,&d);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=d;j++)
            scanf("%d",&a[i][j]);
    }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
    {
        int sum=0;
        for(int k=1;k<=d;k++)
            sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
        int t=sqrt(sum);
        if(sum==t*t)
            ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#define ll long long

vector< ll > a;

main(){
	ll n,t,i,sum=0,f=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end(), greater<ll>());
	for(i=0;i<n-2;i++){
		if(a[i] < a[i+1]+a[i+2]){
			sum += a[i]+a[i+1]+a[i+2];
			f++;i+=2;
		}
		if(f==2) break;
	}
	if(!f)sum=0;
	for(i=0;i<n-5;i++){
		if(a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5] < sum) break;
		if((a[i] < a[i+1]+a[i+4] && a[i+2] < a[i+3]+a[i+5]) ||
		   (a[i] < a[i+3]+a[i+4] && a[i+1] < a[i+2]+a[i+5]) ||
		   (a[i] < a[i+1]+a[i+5] && a[i+2] < a[i+3]+a[i+4])
		   ){
			sum = a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5];
		}
	}
	
	if(sum) cout << sum << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1980
#include <iostream>

int main()
{
    int m,f,r;

    while(1)
    {
        std::cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1) break;

        if      (m == -1 || f == -1)     std::cout << "F" << std::endl;
        else if (m + f >= 80)            std::cout << "A" << std::endl;
        else if (m + f >= 65)            std::cout << "B" << std::endl;
        else if (m + f >= 50 || r >= 50) std::cout << "C" << std::endl;
        else if (m + f >= 30)            std::cout << "D" << std::endl;
        else                             std::cout << "F" << std::endl;
    }
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int lli;

lli memo[1121][15][188];
vector<int> prm;
int l;

lli func(int n, int k, int p, int t, int c)
{
  if(n == t && k == c){
    return 1;
  }
  if(n == t){
    return 0;
  }
  if(k == c){
    return 0;
  }
  if(p == l){
    return 0;
  }
  if(memo[t][c][p] >= 0){
    return memo[t][c][p];
  }
  lli u = 0;
  for(int i = p; i < l; i++){
    if((t+prm[i]) > n){
      break;
    }
    u += func(n, k, i+1, t+prm[i], c+1);
  }
  memo[t][c][p] = u;

  return u;
}

int main()
{
  int n, k;
  bool a[1121];
  fill(a, a+1121, true);
  a[0] = a[1] = false;

  for(int i = 2; i < 1121; i++){
    if(a[i]){
      prm.push_back(i);
      for(int j = i+i; j < 1121; j+=i){
	a[j] = false;
      }
    }
  }
  l = prm.size();

  while(cin>>n>>k && (k+n)){
    fill(&memo[0][0][0], &memo[1120][14][187], -1);
    cout << func(n, k, 0, 0, 0) << endl;
  }

  return 0;
}

Measured memory_bytes: 25000
s = input()
cnt1 = 0 # 1010101の並びになっていない数をカウント
cnt2 = 0 # 0101010の並びになっていない数をカウント
for oddLetter in s[0::2]:
    if oddLetter != '1':
        cnt1 += 1
    else:
        cnt2 += 1
for evenLetter in s[1::2]:
    if evenLetter != '0':
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1,cnt2))

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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;

    bool flag = false;

    for (int i = 0; i < S.length(); i++){
        if (S == T){
            flag = true;
            break;
        }
        char s0 = S[0];
        for (int j = 0; j < S.length() - 1; j++){
            S[j] = S[j+1];
        }
        S[S.length() - 1] = s0;
    }

    if (flag == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;

#define MOD 998244353
ll modpow(ll e, ll x){
    if(0==e) return 0;
    ll r=1;
    rep(_, x){
        r *= e;
        r %= MOD;
    }
    return r;
}

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

    // solution comes here
    //各Diの値が何回出てきたか、が重要。つまりmapだ！！

    ll N;
    cin >> N;

    vl D(N);
    rep(i, N) cin >> D[i];

    if(D[0]){
        cout << 0 << nl;
        return 0;
    }

    vl cntmap(N);//0で初期化されてるらしい
    ll M=0;
    cntmap[0]++;
    for(ll i=1; i<N; i++) {
        cntmap[D[i]]++;
        M = max(M, D[i]);
    }

    if(cntmap[0]>1){
        cout << 0 << nl;
        return 0;
    }

    ll ans=1;
    for(ll i=1; i<=M; i++) {
        ans *= modpow(cntmap[i-1], cntmap[i]);
        ans %= MOD;
    }

    cout << ans << nl;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if (sum % 10) {cout << sum;}
	else {
		for (int i = 0; i < n; i++) {
			if (a[i] % 10) {cout << sum - a[i]; return 0;}
		}
		cout << 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l;
	double a,b,c,d;
	cin>>l>>a>>b>>c>>d;
	int  an;
	double ko,sa;
	ko=a/c;
	sa=b/d;
	an=l-max(ko,sa);
	printf("%d\n",an);
}

	


Measured memory_bytes: 3212
<?php
// B
fscanf(STDIN, '%d %d', $h, $w);
for ($i = 0; $i < $h; $i++) {
    $a[] = trim(fgets(STDIN));
}
$gi = $gj = [];
for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
        if ($a[$i][$j] === '#') {
            $gi[] = $i;
            $gj[] = $j;
        }
    }
}
$gi = array_unique($gi);
$gj = array_unique($gj);
sort($gi);
sort($gj);
foreach ($gi as $i) {
    $ga = [];
    foreach ($gj as $j) echo $a[$i][$j];
    echo PHP_EOL;
}

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

using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    /*std::vector<int> vec(M);*/
    int ans = 0, x;
    for (int i = 0; i < M; ++i) {
        //cin >> vec.at(i);
        cin >> x;
        ans += x;
    }
    ans = N - ans;
    if(ans >= 0){
        cout << ans;
    } else{
        cout << -1;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;
int main(void){
    int N, M;
    cin >> N >> M;
    
    long long int result = 1;
    int mod = 1000000007;
    
    if (N-M>=2 || N-M<=-2) {
        cout << 0;
        return 0;
    }
    
    for (int i=2; i<=N; i++) {
        result*=i;
        result %= mod;
    }
    for (int i=2; i<=M; i++) {
        result *= i;
        result %= mod;
    }
    if (N==M) {
        result*=2;
        result %= mod;
    }
    
    cout << result;
    return 0;
}


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

using namespace std;

//入力
char N [9999];

void solve(){
    if ((N[0] == N[1] && N[1]  == N[2]) || (N[1] == N[2] && N[2] == N[3])) {
        cout << "Yes"<< endl;
    }

    else {
        cout << "No" << endl;
    }
}

int main() {

    cin >> N;

    solve();
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    #ifndef ONLINE_JUDGE  
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
  cp();
 //w(x)
  {
    string s,t;
    cin>>s>>t;
    ll n=s.length();
    ll m=t.length();
    ll ans=INT_MAX;
    re(i,n-m+1)
    {
      ll k=0;
      ll it=i;
      re(j,t.length())
      {
        if(s[it]==t[j])
        {
          k++;
        }
        it++;
      }
      ans=min(ans,m-k);
    }
    cout<<ans<<endl;
  }
}
// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";


Measured memory_bytes: 3584
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    for (auto& a : A) {
        cin >> a;
    }
    for (auto& b : B) {
        cin >> b;
    }
    rep(i, 1, N) {
        A[i] += A[i - 1];
    }
    rep(i, 1, M) {
        B[i] += B[i - 1];
    }
    auto itr = upper_bound(all(B), K);
    int ans = (int)(itr - B.begin());
    rep(i, 0, N) {
        if (A[i] > K) {
            break;
        }
        ll rest = K - A[i];
        auto itr = upper_bound(all(B), rest);
        chmax(ans, i + 1 + (int)(itr - B.begin()));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6340