akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct
{
	char city[12];
	int rev;
	int num;
}rest;

int cmp(const void *p,const void *q)//降順
{
	if(strcmp(((rest*)p)->city,((rest*)q)->city)==0)return ((rest*)q)->rev - ((rest*)p)->rev;
	return strcmp(((rest*)p)->city,((rest*)q)->city);
}

int main()
{
	int n,p,i;
	char s[11];
	rest lst[110];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",s);
		scanf("%d",&p);
		strcpy(lst[i].city,s);
		lst[i].rev=p;
		lst[i].num=(i+1);
	}
	qsort(lst,n,sizeof(rest),cmp);
	
	for(i=0;i<n;i++)
	{
		printf("%d\n",lst[i].num);
	}
}


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

int _atoi(string str)
{
	int res = 0;

	for (int i = 0; i < str.length(); i++)
		res = res * 10 + (str[i] - '0');

	return res;
}

bool YYMM(string str)
{
	string q = "";

	for (int i = 2; i <= 3; i++)
		q += str[i];

	int MM = _atoi(q);
	//cout << "YYMM" << " " << q << endl;

	if (MM < 1 || MM > 12)
		return false;

	return true;
}

bool MMYY(string str)
{
	string q = "";

	for (int i = 0; i <= 1; i++)
		q += str[i];

	int MM = _atoi(q);

	if (MM < 1 || MM > 12)
		return false;

	return true;
}

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

	string str;

	cin >> str;

	bool yymm = YYMM(str);
	bool mmyy = MMYY(str);

	if (yymm == true && mmyy == false)
		cout << "YYMM" << endl;
	else if (yymm == false && mmyy == true)
		cout << "MMYY" << endl;
	else if (yymm == true && mmyy == true)
		cout << "AMBIGUOUS" << endl;
	else
		cout << "NA" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

int a[100010] = {}, b[100010] = {}, c[100010] = {};

ll answer[100010] = {};

int main() {

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
/*
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		cout << c[i] << " ";
	}
	cout << endl;
*/
	//bを決め打ちしたときのcの数
	for (int i = 0; i < n; i++) {
		//cout << b[i] << " " << ((n+c) - upper_bound(c, c + n, b[i])) << endl;
		answer[i+1] = (n - (int)(upper_bound(c, c + n, b[i]) - c));
		//cout << answer[i + 1] << endl;
	}

	for (int i = 0; i <= n; i++) {
		answer[i + 1] += answer[i];
	}

	ll result = 0;

	//aを決め打ちしたときのbの位置を求めてそれを減算してやる。
	for (int i = 0; i < n; i++) {
		//cout << answer[n + 1] - answer[upper_bound(b, b + n, a[i]) - b] << endl;
		result += answer[n+1] - answer[upper_bound(b, b + n, a[i]) - b];
	}

	cout << result << endl;

	return 0;
}

/*
3
1 1 1
1 2 2
2 3 3

3
1 2 3
1 2 3
1 2 3

2
1 3
2 2
3 1

*/


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

int main(int argc, char *argv[])
{
    int a;
    char str[100];
    int cnt_r;
    int cnt_b;
    int i;

    scanf("%d", &a);
    scanf("%s", str);

    for (i = 0; i < a; i++)
    {
        if (str[i] == 'R')
        {
            cnt_r++;
        }

        else if (str[i] == 'B')
        {
            cnt_b++;
        }
    }

    if (cnt_r > cnt_b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(input())

u = [[0 for i in range(w)] for j in range(h)]
d = [[0 for i in range(w)] for j in range(h)]
l = [[0 for i in range(w)] for j in range(h)]
r = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            u[i][j] = 0
        else:
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            l[i][j] = 0
        else:
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1

for i in range(h-1,-1,-1):
    for j in range(w):
        if s[i][j] == "#":
            d[i][j] = 0
        else:
            if i == h-1:
                d[i][j] = 1
            else:
                d[i][j] = d[i+1][j] + 1

for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            r[i][j] = 0
        else:
            if j == w-1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j+1] + 1

s = [[0 for i in range(w)] for j in range(h)] 
maxs = 0
for i in range(h):
    for j in range(w):
        s[i][j] = u[i][j] + l[i][j] + d[i][j] + r[i][j] - 3
        maxs = max(maxs,s[i][j])
print(maxs)

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

int main(){
  string s;
  cin >> s;
  bool beautiful = true;
  for(int i = 0; i < s.size(); i++){
    int cnt = 0;
    for(int j = 0; j < s.size(); j++){
      if(s.at(i) == s.at(j)) cnt++;
    }
    if(cnt % 2 == 1){
      beautiful = false;
      break;
    }
  }
  if(beautiful) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>

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

    int n;
    std::cin >> n;
    std::vector<double> d(n);
    for(auto& i : d){
        int x;
        std::cin >> x;
        i = x;
    }
    for(auto& i : d){
        int y;
        std::cin >> y;
        i -= y;
        i = std::fabs(i);
    }
    double m1 = 0 , m2 = 0 , m3 = 0 , mInf = 0;
    for(auto& i : d){
        m1 += i;
    }
    for(auto& i : d){
        m2 += i*i;
    }
    m2 = std::sqrt(m2);
    for(auto& i : d){
        m3 += i*i*i;
    }
    m3 = std::pow(m3, 1.0/3.0);
    mInf = *std::max_element(d.begin(), d.end());
    std::cout << std::fixed << std::setprecision(6) << m1 << "\n";
    std::cout << std::fixed << std::setprecision(6) << m2 << "\n";
    std::cout << std::fixed << std::setprecision(6) << m3 << "\n";
    std::cout << std::fixed << std::setprecision(6) << mInf << "\n";
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    
    vector<int> v;
    map<string,int> m;
    map<string,int> :: iterator it;
    
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        

        it=m.find(s);
        if(it!=m.end())
        {
            int count=it->second;
            m.erase(s);
            m.insert(pair<string,int>(s,count+1));
        }
        
        m.insert(pair<string,int>(s,1));
        
        
    }
    int max_idx=0;
    
    for(auto itr=m.begin();itr!=m.end();itr++)
    {
        //cout<<itr->first <<" "<<itr->second<<endl;
        max_idx= max(max_idx,itr->second);
    }
    
    for(auto itr=m.begin();itr!=m.end();itr++)
    {
        if(itr->second==max_idx)
        {
            cout<<itr->first<<endl;
        }
    }
   
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define  clr(v,val)      memset(v,val,sizeof(v))
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
ll setBit1(ll num, ll idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=200000+9,mod=1e9+7;
int a[200000+9],n;
ll P[4][N],ans[4];
int solve(int val,int f,int pos){
   if(val==0){
    return 0;
   }
   ll res;
   if(f==2){
    res=(ans[f]+P[f][pos])%val;
   }
   else{
    res=((ans[f]-P[f][pos])%val+val)%val;
   }

   ll cur=res;
   bitset<20> p(cur);
   int num=p.count();
   int cnt=1;
//cout<<cur<<" "<<num<<endl;
   while(cur!=0){

       cur= cur%num;
       bitset<20> pp(cur);
       num=pp.count();
       cnt++;
   }

   return cnt;


}
int main(){
    GO();
    cin>>n;
    int cnt=0;
    string ss;
    cin>>ss;
    for(int i=0;i<n;i++){
        a[i]=ss[i]-'0';
        if(a[i]==1) cnt++;
    }


    P[1][0]=1;
    for(int i=1;i<N&&cnt-1>0;i++){
        P[1][i]=(P[1][i-1]*2)%(cnt-1);
    }
    P[2][0]=1;
    for(int i=1;i<N;i++){
        P[2][i]=(P[2][i-1]*2)%(cnt+1);
    }

    for(int i=0;i<n&&cnt-1>0;i++){
        int ni=n-1-i;
        if(a[i]==1){
            ans[1]=(ans[1]+P[1][ni])%(cnt-1);
        }
    }
    for(int i=0;i<n;i++){
        int ni=n-1-i;
        if(a[i]==1){
            ans[2]=(ans[2]+P[2][ni])%(cnt+1);
        }
    }


    for(int i=0;i<n;i++){
        if(a[i]==1){
          //  a[i]^=1;
            cout<<solve(cnt-1,1,n-1-i)<<"\n";
          //  a[i]^=1;
        }
        else{
          //  a[i]^=1;
            cout<<solve(cnt+1,2,n-1-i)<<"\n";
        //    a[i]^=1;
        }
    }
}




















































































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


	int p,q,r;
	cin >> p>>q>>r;

	int ans = min({p+q, q+r, r+p});

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt=0;
    if(s[0] != 'A' || s[s.size()-1] == 'C' || s[1] == 'C' || ((int)s[1])<97){
        cout << "WA" << endl;
        return 0;
    }
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C'){cnt++;}
        if(s[i]!='C' && ((int)s[i])<97){
            cout << "WA" << endl;
            return 0;
        }
    }
    if(cnt != 1 || ((int)s[s.size()-1])<97){
        cout << "WA" << endl;
    }
    else cout << "AC" << endl;

    return 0;
}

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

double n, ans;

int main() {
  cin >> n;
  vector<double> v(n);
  rep (i, n) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  ans = v.at(0);
  rep (i, n - 1) {
    ans = (ans + v.at(i + 1)) / 2;
  }
  cout << fixed << ans << endl;
  return 0;
}


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

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  
  if(B-A>2*(K-1)){
  
  for(int i=0;i<K;i++){
    cout<<A+i<<endl;
  }
  for(int i=K-1;i>=0;i--){
    cout<<B-i<<endl;
  }
  }
  else{
    for(int i=A;i<=B;i++){
      cout<<i<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

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

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


struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};


int a[10];
vector<int> v;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    char s;
    string t="";
    REP(i, n){
        cin >> s;
        t += s;
        v.push_back((int)s-'0');
    }
    sort(v.begin(), v.end());
    
    
    vector<string> ans;
    do{
        string str="";
        for(int i=0; i<n; ++i){
            str += (char)v[i] +'0';
        }
        ans.push_back(str);
    }while(next_permutation(v.begin(), v.end()));
           
    for(int i=0; i<ans.size(); ++i){
        if(ans[i]==t){
            if(i>0) {
                for(int j=0; j<ans[i-1].size(); ++j){
                    if(j) cout << " ";
                    cout << ans[i-1][j];
                }
                cout << endl;
            }
            for(int j=0; j<ans[i].size(); ++j){
                    if(j) cout << " ";
                    cout << ans[i][j];
               
            } cout << endl;
            if(i<ans.size()-1){
                
                for(int j=0; j<ans[i+1].size(); ++j){
                    if(j) cout << " ";
                    cout << ans[i+1][j];
                }
                cout << endl;
            }
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 28312
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  while (true) {
    ll n, x;
    cin >> n >> x;
    if (n == 0 and x == 0) return;
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    for (ll j = i+1; j <= n; j++)
    for (ll k = j+1; k <= n; k++) {
      if (i + j + k == x) ans++;
    }
    cout << ans << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
 using namespace  std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// What follows is a magical ordered_set data structure.
// Supports the following functions:
// find_by_order(ll k) - returns k'th smallest element (0-indexed)
// order_of_key(ll k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> 
 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod= 1e17+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
//cd god (mod,0);
 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res *res;
	
	if (b % 2 == 1)
		{
			res = res * a;
		 
 
		}    
	
	return res;
}
 
long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1LL;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;
 
	return res;
}
 
 
//TEMPLATE ENDS HERE!!!! ------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
 
 
 
 
 
 
struct custom
{
	bool operator()(ll a, ll b)
	{
		return a > b;
	}
};


int main()
{
		
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll x[m];
	for(ll i=0; i<m ;i++)
		cin>>x[i];
	sort(x,x+m);
	ll worst = x[m-1]-x[0];
	vector <ll> diff;
	for(ll i=1  ; i<m;i++)
	{
		diff.pb(x[i]-x[i-1]);
	}

	sort(diff.begin(),diff.end(),greater<>());

	for(ll i = 0 ; i< n-1 && i<diff.size(); i++)
	{
		worst  = worst - diff[i];
	}

	cout<<max(worst,(ll)0)<<endl;
	return 0;


}

Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cassert>
#include <numeric>
#include <queue>
#include <unordered_set>

using namespace std;

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

    cout << min(n * a, b) << endl;

    return 0;
}

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

int main() {
  string N;
  int count = 0;
  cin >> N;
  
  if(N.at(0)=='7'){
	count++;
  }else if(N.at(1)=='7'){
	count++;
  }else if(N.at(2)=='7'){
	count++;
  }else{
  	cout << "No" << endl;
  }
  
  if(count > 0){
  	cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	int A[N]; int x = inf,y = 0;
	rep(i,0,N){
		cin>>A[i];
		x = min(x, A[i]);
		y = max(y, A[i]);
	}
	if(x == y){
		if(x == N - 1 || 2 * x <= N) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
	}else if(x + 1 == y){
		int a = 0,b = 0;
		rep(i,0,N){
			if(A[i] == x) a++;
			else b++;
		}
		if(a < y && y <= a + b / 2) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}else cout<<"No"<<endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] S = new string[N];
        for (int i = 0; i < N; i++)
            S[i] = Console.ReadLine();
        Console.WriteLine(S.Distinct().Count()) ;
    }
}


Measured memory_bytes: 48132
from collections import deque
def start_search(G):
    start=[]
    for i in range(H):
        for j in range(W):
            if G[i][j]=='#':
                start.append((i,j))
    return start
def bfs(G,visited,start):
    queue=deque(start)
    cnt=0
    for p,q in start:
        visited[p][q]=0
    while queue:
        tmp=len(queue)
        for _ in range(tmp):
            (y,x)=queue.popleft()
            for j,k in ([1,0],[0,1],[-1,0],[0,-1]):
                tmp_y,tmp_x = y+j,x+k
                if 0<=tmp_y<=H-1 and 0<=tmp_x<=W-1 and visited[tmp_y][tmp_x]==-1:
                    visited[tmp_y][tmp_x]=visited[y][x]+1
                    queue.append([tmp_y,tmp_x])
        cnt+=1
    return cnt-1
if __name__=="__main__":
    H,W = map(int,input().split())
    G=[input() for _ in range(H)]
    start=start_search(G)
    visited=[[-1]*W for _ in range(H)]
    print(bfs(G,visited,start))


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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int l = 0;
  int r = n - 1;
  while (l < r) {
    while (l < n && s[l] != 'W') {
      l++;
    }
    while (r >= 0 && s[r] != 'R') {
      r--;
    }
    if (l < r) {
      ans++;
      l++;
      r--;
    } else {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(b - a == c - b)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	char str1[105]; // 100 karakter
	char str2[105]; // 100 karakter
	scanf("%s %s", &str1, &str2); // jessica (str1), priscilla (str2)
	printf("%s%s\n", str2, str1);
	return 0;
}

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

const int N = 1e6+1;

ll dp[N], dp2[N];

int main() {

    dp[0] = dp2[0] = 0;
    for (int i=1; i<N; ++i) {
        dp[i] = dp2[i] = i;
        for (int j=1; ; ++j) {
            int p=j*(j+1)*(j+2)/6;
            if (p > i) break;
            dp[i] = min(dp[i], dp[i-p]+1);
            if (p%2) {
                dp2[i] = min(dp2[i], dp2[i-p]+1);
            }
        }
    }

    int n;
    while (cin >> n and n) {
        cout << dp[n] << " " << dp2[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 18656
# -*- coding:utf-8 -*-
s = [""]*3
s[0] = input()
s[1] = input()
s[2] = input()

turn = 0

while s[turn] != "":
    next = s[turn][0]
    s[turn] = s[turn][1::]
    if next == "a" :
        turn = 0
    elif next == "b":
        turn = 1
    else:
        turn = 2

if turn == 0:
    print("A")
elif turn == 1:
    print("B")
else:
    print("C")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++) cin>>h[i];
	int dp[n];
	for(int i=0;i<n;i++)
	{
		dp[i]=MOD;
	}
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		if(i+1<n) dp[i+1] = std::min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
	//	cout<<"dp["<<i+1<<"]="<<dp[i+1]<<"\n";
		if(i+2<n) dp[i+2] = std::min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	//	cout<<"dp["<<i+2<<"]="<<dp[i+2]<<"\n";
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int arr[M];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> arr[i];
	sort(arr, arr+n);
	vector<pair<int, int> > v;
	for(int i = 0; i < n;) {
		int j = i+1;
		while(j < n && arr[j] == arr[i] ) j++;
		v.push_back(make_pair(arr[i], j - i) );
		i = j;
	}
	bool ans = false;
	int len = v.size();
	if(len == 1 && v[0].first == 0) ans = true;
	else if(len == 2 && n % 3 == 0 && v[0].first == 0 && v[0].second*2 == v[1].second) ans = true;
	else if(len == 3 && n % 3 == 0 && (v[0].first ^ v[1].first) ==  v[2].first && v[0].second == v[1].second && v[1].second == v[2].second) ans = true;
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
int N,a,b,c,d;
string x;
int main() {
	cin>>N;
	for(int i=1;i<=N;i++) {
		cin>>x;
		if(x=="AC") {
			a++;
		} else if(x=="WA") {
			b++;
		} else if(x=="TLE") {
			c++;
		} else if(x=="RE") {
			d++;
		}
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
}


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

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int l, r, sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;


struct Dinic
{
  const int INF = 1 << 30;

  struct edge
  {
    int to, cap, rev;
  };

  vector< vector< edge > > graph;
  vector< int > min_cost, iter;

  Dinic(int n)
  {
    graph.resize(n);
  }

  void add_edge(int from, int to, int cap)
  {
    graph[from].push_back((edge) {to, cap, (int) graph[to].size()});
    graph[to].push_back((edge) {from, 0, (int) graph[from].size() - 1});
  }

  bool bfs(int s, int t)
  {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int p = que.front();
      que.pop();
      for(int i = 0; i < graph[p].size(); i++) {
        const edge &e = graph[p][i];
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return (min_cost[t] != -1);
  }

  int dfs(int idx, const int t, int flow)
  {
    if(idx == t) return (flow);
    for(int &i = iter[idx]; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        int d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return (d);
        }
      }
    }
    return (0);
  }

  int max_flow(int s, int t)
  {
    int flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      int f = 0;
      while((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
    return (flow);
  }
};


void solve()
{
  int V, E;
  cin >> V >> E;
  Dinic graph(V);
  for(int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    graph.add_edge(a, b, c);
  }
  cout << graph.max_flow(0, V - 1) << endl;
}

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

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;

// 深さ優先探索
int dfs(string &S) {
    ll ret = 0;
    vector<char> lis = {'3', '5', '7'};
    if ((int)S.size() > 0) {  // 最初はSは空なので注意
        if (stoll(S) > N) {   // Nを超えてたら探索しない
            return ret;
        } else {  // N 以下で 3,5,7 がそれぞれ1回以上登場するか？
            bool ok = true;
            for (auto c : lis) {
                if (S.find(c) == string::npos) ok = false;
            }
            if (ok) ret++;
        }
    }

    for (auto c : lis) {  // 3つに分岐する
        S.push_back(c);
        ret += dfs(S);
        S.pop_back();
    }
    return ret;
}
int main() {
    cin >> N;
    string S = "";
    cout << dfs(S) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007
#define tp tuple<ll,ll,ll>

int main() {
	int N, A;
	cin >> N;
	map<ll, ll> M;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (M.count(A))M[A]++;
		else M.insert({ A,1 });
	}
	vector<int> S;
	for (auto x : M) {
		S.push_back(x.second);
	}
	
	int ss = S.size();
	sort(all(S));
	vector<int> T = S;
	for (int i = 1;i < ss;i++) {
		T[i] += T[i - 1];
	}
	int ok, ng, mid, xs, ot, ans;
	cout << N << endl;
	for (int i = 2;i <= N;i++) {
		ok = 0, ng = N + 1;
		if (ss < i) {
			cout << 0 << endl;
			continue;
		}
		while (ok + 1 != ng) {
			mid = (ok + ng) / 2;
			auto it = lower_bound(all(S), mid);
			xs = it - S.begin();
			if (xs == 0) {
				ans = ss;//最大幅
			}
			else {
				ot = ss - xs;
				//cout << ss << " " << xs << " ";
				ans = T[xs - 1] / mid + ot;
			}
			//cout << i << " " << mid << " " << ans << endl;
			if (ans >= i) {
				ok = mid;
			}
			else {
				ng = mid;
			}
		}
		cout << ok << endl;
	}
}

Measured memory_bytes: 21232
#include <stdio.h>

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

Measured memory_bytes: 1584
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
const int MX = 410000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}
	
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	int h, w, a, b; cin >> h >> w >> a >> b;
	ll ans = 0;
	for(int i = h - a, j = b + 1; i > 0 && j <= w; i--, j++){
		ans += C(i + j - 2, i - 1) * C(h + w - i - j, h - i) % mod;
	}
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 9856
//If you are reading this then you are at wrong place.
#include<bits/stdc++.h>
#define mod 1000000007
#define lli long long int
using namespace std;
bool prime [1000001];
void debug(lli a){cout<<a<<endl;}
lli sieve(lli a){memset(prime,true,sizeof(prime));lli p,i;for(p=2;p*p<=a;p++){if(prime[p]==true){for(i=p*2;i<=a;i+=p)prime[i]=false;}}return 0;}
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli find_max(lli __a,lli __b){return __a^((__a^__b) & -(__a<__b));}
lli add(lli __a,lli __b,lli MOD){lli x = (__a+__b)%MOD; return x; }
lli mul(lli a,lli b,lli MOD){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b,lli MOD){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b,lli MOD){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}
int main()
{
	//ifstream cin("testcase.txt");
	//ofstream cout("output.txt");	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);	
	cout.precision(20);
	lli t,i,j;
	//cin>>t;
	//memset(dp, -1, sizeof dp);
	t=1;
	lli counter1=0;
	while(t--)
	{
		counter1++;
		string a,b,c;
		cin>>a>>b>>c;
		if(b[0]==a[a.size()-1] && b[b.size()-1]==c[0])
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
				
		//cout<<"Case #"<<counter1<<" ";
		//cout<<endl;	
	}	
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <queue>

using namespace std;

int main(){
    string command;

    priority_queue<int> queue;

    while(true){
        cin >> command;
        if(command == "end")
            break;
        else if(command == "insert"){
            int argument;
            cin >> argument;
            queue.push(argument);
        }else if(command == "extract"){
            cout << queue.top() << endl;
            queue.pop();
        }
    }

    return 0;
}

Measured memory_bytes: 7040
import collections


def main():
    N = int(input())
    table = [''.join(sorted(list(input()))) for _ in range(N)]
    sort_table = set(table)
    cnt_table = collections.Counter(table)
    ans = 0
    for i in sort_table:
        num_of_i = cnt_table[i]
        if num_of_i <= 1:
            continue
        x = (num_of_i * (num_of_i - 1)) // 2
        ans += x

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30356
n,m=map(int,input().split())
fall=[0]*(n+1)
for i in range(m):
    fall[int(input())]=1
dp=[0]*100010
dp[0]=1
for now in range(n):
    for next in range(now+1,min(n,now+2)+1):
        if fall[next]==0:
            dp[next]+=dp[now]
            dp[next]%=1000000007
print(dp[n])

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i, 0, n) cin >> a.at(i);
  
  int cnt = 0;
  bool flag = 1;
  while (flag) {
    flag = 0;
    for(int j = n-1; j >= 1; j--) {
      if (a.at(j) < a.at(j-1)) {
        swap(a.at(j), a.at(j-1));
        cnt++;
        flag = 1;
      }
    }
  }
  
  rep(i, 0, n-1)
    cout << a.at(i) << " ";
  cout << a.at(n-1) << "\n";
  cout << cnt << "\n";

}



Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        if(a >= b && a >= c){
            System.out.println(a*10 + b + c);
        }else if(b >= a && b >= c){
            System.out.println(a + b*10 + c);
        }else{
            System.out.println(a + b + c*10);
        }
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int n, a, C[100005];
int main(){
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> a;
    C[a]++;
    C[a+1]++;
    C[a-1]++;
  }
  int ans = 0;
  for(int i=0; i<100005; ++i) ans = max(ans, C[i]);
  cout << ans << endl;
}

Measured memory_bytes: 3960
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

    val Array(h, w) = readLine().split(" ").map(_.toInt)
    val S = (0 until h).map { _ =>
      readLine().toCharArray
    }. toArray

    val iv = Array(0,0,-1,1)
    val jv = Array(1,-1,0,0)

    val res = (0 until h) forall { i =>
      (0 until w) forall { j =>
        if (S(i)(j) == '#') {
          (0 until 4) exists { v =>
            val ni = i + iv(v)
            val nj = j + jv(v)
            if (ni >= 0 && ni < h && nj >= 0 && nj < w) {
              if (S(ni)(nj) == '#') true
              else false
            } else false
          }
        } else true
      }
    }
    if (res) println("Yes")
    else println("No")
  }

}

Measured memory_bytes: 25520
import sys
from bisect import bisect_left
def main():
    sys.setrecursionlimit(202020)
    N = int(input())
    A = [0] + list(map(int, input().split()))
    G = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        G[u].append(v)
        G[v].append(u)
    L = [A[1]]
    Ans = [0] * (N+1)
    def dfs(v):
        Ans[v] = len(L)
        for u in G[v]:
            G[u].remove(v)
            Au = A[u]
            if Au > L[-1]:
                L.append(Au)
                dfs(u)
                del L[-1]
            else:
                idx = bisect_left(L, Au)
                old = L[idx]
                L[idx] = Au
                dfs(u)
                L[idx] = old
    dfs(1)
    print("\n".join(map(str, Ans[1:])))

main()


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

signed main() {
	int N;
	cin>>N;
	std::vector<int> v(N);
  std::vector<int> ans(4);
	int k;
  cin>>k;
  v[0]=k;
  for(int i=1;i<N;i++){
    cin>>k;
    v[i]=v[i-1]+k;
  }
  int h,l,a,b,c;
  int m=10000000000;
  for(int b=1;b<N-1;b++){
    h=b;
    l=0;
    while(h-l>1){
      a=(h+l)/2;
      if(v[a]>v[b]/2)h=a;
      else l=a;
    }
    if(abs(v[b]-2*v[h])<abs(v[b]-2*v[l]))l=h;
    ans[0]=v[b]-v[l];
    ans[1]=v[l];
    h=N-1;
    l=b;
    while(h-l>1){
      c=(h+l)/2;
      if((v[c]-v[b])*2>v[N-1]-v[b])h=c;
      else l=c;
    }
    if(abs(v[N-1]-v[b]-(v[h]-v[b])*2)<abs(v[N-1]-v[b]-(v[l]-v[b])*2))l=h;
    ans[2]=v[N-1]-v[l];
    ans[3]=v[l]-v[b];
    sort(ans.begin(),ans.end());
    m=min(m,ans[3]-ans[0]);
  }
  cout<<m<<endl;
}


Measured memory_bytes: 1792
import math._
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val X = in.nextInt

  val is = (-200 to 200).map(l => l.toLong*l*l*l*l).toArray

  val (a, b) = (for {
    a <- is
    b <- is
    if (a - b == X)
  } yield (a, b)).head

  def rt5(l: Long): Long = (pow(abs(l), 0.2) + 0.1).toLong * l.sign

  println(s"${rt5(a)} ${rt5(b)}")
}

Measured memory_bytes: 57420
import java.util.*;
 
public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int people = sc.nextInt();
      	int firstPoint = sc.nextInt();
      	int correct = sc.nextInt();
      	int[] point = new int[people];
      	Arrays.fill(point, firstPoint-correct);
      	int correctPerson = 0;
      	for(int i = 0; i < correct; i++){
        	correctPerson = sc.nextInt();
          	point[correctPerson-1] += 1;
        }
      	for(int j = 0; j < people; j++){
        	if(point[j] > 0){
            	System.out.println("Yes");
            }else if(point[j] <= 0){
            	System.out.println("No");
            }
        }     	
	}
}

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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> ans(n - 1,0);
    REP(i, n - 1)
    {
        FOR(j, i + 1, n)
        {
            ans[min(j-i-1,abs(i-x)+abs(j-y))]++;
        }
    }
    REP(i,n-1)
    cout<<ans[i]<<endl;
}

Measured memory_bytes: 3620
n = int(input())
ls_p = [[int(i) for i in input().split()] for j in range(n)] 

dist = 0

for i in range(n):
    for j  in range(n):
        dist += ((ls_p[i][0] - ls_p[j][0])**2 + (ls_p[i][1] - ls_p[j][1])**2)**(1/2)

print(dist/n)

Measured memory_bytes: 3064
#include <iostream>
using ll = long long;
using namespace std;

int main() {
    char a;
    int ans = 700;
    for (int i = 0; i < 3; ++i) {
        cin >> a;
        if (a == 'o') ans += 100;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl


int main(){
	li n;
	
	while(cin>>n){
		li res=0;
		
		rep(i,10)rep(j,10)rep(k,10)rep(l,10){
			if(i+j+k+l==n)res++;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c;
    cin>>n;
    vector<vector<int>>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        v[i].push_back(a);   
        v[i].push_back(b);
        v[i].push_back(c);
    }
    vector<vector<int>>dp(n,vector<int>(3));
    //dp[0].push_back(v[0][0]);
    //dp[0].push_back(v[0][1]);
    //dp[0].push_back(v[0][2]);
   dp[0][0]=v[0][0];
   dp[0][1]=v[0][1];
   dp[0][2]=v[0][2];
    for(int i=1;i<n;i++)
        {
            for(int j=0;j<3;j++)
                dp[i][j]=v[i][j]+max((dp[i-1][(j+1)%3]),(dp[i-1][(j+2)%3]));
        }
    /*for(int i=0;i<dp.size();i++)
        {for(int j=0;j<dp[i].size();j++)    
            cout<<dp[i][j]<<" ";
        cout<<"\n";    
        }*/
    cout<<*max_element(dp[n-1].begin(),dp[n-1].end())<<"\n";
    return 0;
}

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, m;
    int scount = 0;
    int smax = 0;
    int tcount = 0;
    
    cin >> n;
    vector<string> s(n);
    
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    
    cin >> m;
    vector<string> t(m);
    
    for (int i = 0; i < m; i++) {
        cin >> t.at(i);
    }

    for (int i = 0; i < n; i++) {
        scount = count(s.begin(), s.end(), s.at(i));
        tcount = count(t.begin(), t.end(), s.at(i));

        if (smax < scount - tcount) {
            smax = scount - tcount;
        }
    }
    cout << smax << endl;
    
}

Measured memory_bytes: 3616
from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split());b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0;d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1
a(-1)


Measured memory_bytes: 36636
#include <stdio.h>

int main(){
  
  int i,j,v,N,c;
  
  scanf("%d",&N);

  int A[N];
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

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

    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    
    A[j+1] = v;
    
    for(c=0;c<N;c++){
      printf("%d",A[c]);
      if(c<N-1){
	printf(" ");
      }
      else{
	printf("\n");
      }
    }
  }
    return 0;
}

  
 



Measured memory_bytes: 2140
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli n;
    cin>>n;
    ldb a[n];
    ldb ans=0;
    forz(i,n)
    {
        cin>>a[i];
        ans+=(1/a[i]);
    }
    cout<<deci(10)<<1/ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int main ()
{
	int n;
	int a[200009];
	scanf("%d",&n);
	int x = -1;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		x = max(x,a[i]);
	}
	int s = 0;
	int k = 0;
	int p;
	for (int i = 1; i <= n; i++)
	{
		p = min(abs(x-a[i]),a[i]);
		if (p > k) {
			s = a[i];
			k = p;}
	}
		printf("%d %d",x,s);
}

Measured memory_bytes: 640
N = int(input())
L=[3,5,7]
answer = 0
for d in range(3,11):
    for x in range(pow(3,d)):
        value = 0
        prod = 1
        for dd in range(1,d+1):
            digit = L[x%pow(3,dd)//pow(3,dd-1)]
            prod *= digit
            value += digit*pow(10,dd-1)
        if value <= N and prod%3 == 0 and prod%5 == 0 and prod%7 == 0:
            answer += 1
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int h,w,cost[11][11],dp[11],inq[11];
void spfa()
{
	dp[1]=0;
	queue<int> q;
	q.push(1);
	memset(inq,0,sizeof(inq));
	while(!q.empty())
	{
		int now=q.front();q.pop();inq[now]=0;
		for(int i=0;i<=9;i++)if(dp[i]>dp[now]+cost[i][now])
		{
			dp[i]=dp[now]+cost[i][now];
			if(!inq[i])q.push(i);
			inq[i]=1;
		}
	}
}
int main()
{
	cin>>h>>w;
	for(int i=0;i<=9;i++)for(int j=0;j<=9;j++)cin>>cost[i][j];
	memset(dp,0x3f,sizeof(dp));
	spfa();
	int ans=0;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			int x;cin>>x;
			if(x!=-1)ans+=dp[x];
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
struct edge{
  int  to;
  int cost;
  edge(int t,int w) : to(t),cost(w){}
};
int main(){
  long long int i,n,m,a,b,ans[100010],x,k=0,check=0,black=0,white=0;
  stack<int> s;
  scanf("%lld %lld\n",&n,&m);
  vector<vector<edge>> g(n+10);
  for(i=0;i<m;i++){
    scanf("%lld %lld\n",&a,&b);
    g[a].push_back(edge(b,1));
    g[b].push_back(edge(a,1));
  }
  for(i=1;i<=n;i++){
    ans[i]=0;
  }
  s.push(1),ans[1]=-1;
  while(!s.empty()){
    x=s.top();
    s.pop();
    for(i=0;i<g[x].size();i++){
      if(ans[g[x][i].to]==0){
        ans[g[x][i].to]=-ans[x];
        s.push(g[x][i].to);
      }
      else if(ans[g[x][i].to]==ans[x]){
        check=1;
        break;
      }
    }
    if(check==1){
      break;
    }
  }
  if(check==1){
    printf("%lld\n",n*(n-1)/2-m);
  }
  else{
    for(i=1;i<=n;i++){
      if(ans[i]==1){
        black++;
      }
      else{
        white++;
      }
    }
    printf("%lld\n",black*white-m);
  }
  return 0;
}

Measured memory_bytes: 7168