akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int height=ty-sy,width=tx-sx;
 REP(i,height)cout<<"U";
 REP(i,width)cout<<"R";
 REP(i,height)cout<<"D";
 REP(i,width)cout<<"L";
 cout<<"L";
 REP(i,height+1)cout<<"U";
 REP(i,width+1)cout<<"R";
 cout<<"DR";
 REP(i,height+1)cout<<"D";
 REP(i,width+1)cout<<"L";
 cout<<"U";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

int main(){
  int n,a,b,t[1009],ans;
  cin>>n>>a>>b>>ans;
  rep(i,0,n)cin>>t[i];
  sort(t,t+n);
  reverse(t,t+n);
  int cal=ans,price=a;
  ans=ans/a;
  for(int i=0;i<n;i++){
    cal+=t[i];price+=b;
    ans=max(ans,cal/price);
  }
  cout<<ans<<endl;
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int M=1e5+5;
const int INF=1e9;
const int MOD=1e9+5;

int n;
int tot[M][5],pnts[M][5];

int dp(int a,int b){
  if (a == 1) return pnts[1][b];
  if (tot[a][b] != -1) return tot[a][b];
  tot[a][b] = max(dp(a-1,(b+1)%3) + pnts[a][b] , dp(a-1,(b+2)%3) + pnts[a][b]);
  return tot[a][b];
}

int main(){

	fastio;
  cin >> n;
  fp (i,1,n+1){
      tot[i][0] = -1;
      tot[i][1] = -1;
      tot[i][2] = -1;
  }
  fp(i,1,n+1) cin >> pnts[i][0] >> pnts[i][1] >> pnts[i][2];
  cout << max(dp(n,0) , max(dp(n,1) , dp(n,2))) << "\n";

	return 0;
}


Measured memory_bytes: 13684
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;


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

ll lcm(int x, int y){
	return x/gcd(x,y)*y;
}
void Main()
{
  	int A,B;
  	cin >> A >> B;
  	cout << lcm(A,B) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n;
  cin >> n;
  unordered_set<int>st;
  for (int i = 0; i < n; i++){
    int x;
    cin >> x;
    st.insert(x);
  }
  if (st.size() == n){
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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; }

void Main(){
    int n; cin >> n;
    VI ans(n, 0);
    VI av(n-1); REP(i, n-1) cin >> av[i];
    REP(i, n-1) ans[av[i]-1]++;
    REP(i, n) cout << ans[i] << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 4744
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)
map<int, int> cnt;

void prime_factorize(int n) {
    vector<pair<int, int> > res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    for (auto v : res) cnt[v.first] += v.second;
}

int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) prime_factorize(i);
    int over_2 = 0;
    int over_4 = 0;
    int over_14 = 0;
    int over_24 = 0;
    int over_74 = 0;
    int ans = 0;
    for (auto v : cnt) {
        if (v.second >= 2) over_2++;
        if (v.second >= 4) over_4++;
        if (v.second >= 14) over_14++;
        if (v.second >= 24) over_24++;
        if (v.second >= 74) over_74++;
    }
    ans += over_4 * (over_4 - 1) / 2 * (over_2 - 2);
    ans += over_14 * (over_4 - 1); 
    ans += over_24 * (over_2 - 1); 
    ans += over_74;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>


using namespace std;
typedef long long int ll;


int main() {
    string ans = "-1 -1 -1";
    ll N, Y;
    cin >> N >> Y;
    
    for(size_t i = 0; i <= N; i++)
    {
        for (size_t j = 0; j+i <= N; j++)
        {
            ll r = Y - i*10000 - j*5000;
            ll l = N - i - j;
            if (r/1000 == l && l >= 0)
            {
                cout << i << " " << j << " " << l << endl;
                return 0;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n,k,count=0;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    rep(i,n) {
        if(h[i]>=k)
        count++;
    }
    cout<<count<<endl;
}

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

int main(){
	int n;
	int even[2]={19,20}; //偶数月の日数
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		long ans=0;
		int y, m, d;
		scanf(" %d %d %d", &y, &m, &d); 
		
		int e=0;
		if(y%3==0) e=1;
		
		if(m%2==0)	ans+=19+e-d+1;	
		else ans+=20-d+1;
		++m;		
		
		while(m<11){
			if(m%2==0)	ans+=19+e;	
			else ans+=20;
			++m;	
		}
		
		for(int j=y+1; j<1000; ++j){
			if(j%3==0) ans+=200;
			else ans+=195;	
		}
		
		printf("%ld\n", ans);
	}	
	
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int N, A;
	cin >> N >> A;

	string ret;
	if((N%500) <= A)
		ret = "Yes";
	else
		ret = "No";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define H 251
#define N 2000000001
typedef struct{
  int key;
  int p;
  int dep;
  int l;
  int r;
}Tree;
 
Tree T[H];
 
int main(){
  int h,i;
 
  scanf("%d",&h);
 
  for(i=1;i<=h;i++) T[i].p=T[i].l=T[i].r=N;
  
  for(i=1;i<=h;i++) scanf("%d",&T[i].key);
 
   
 for(i=1;i<=h;i++){
   if(i!=1)T[i].p = T[i/2].key; 
   if(2*i<=h) T[i].l=T[2*i].key;  
   if(2*i+1<=h) T[i].r=T[2*i+1].key;
  }
 
  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,T[i].key);  
    if(i!=1) printf("parent key = %d, ",T[i].p); 
    if(T[i].l!=N) printf("left key = %d, ",T[i].l);
    if(T[i].r!=N) printf("right key = %d, ",T[i].r);  
    printf("\n");
  } 
  return 0;
}
 
  

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

int main()
{
	using namespace std;
	int N_num = 0;
	cin >> N_num;

	vector<int> data(N_num);

	for (int i = N_num - 1; i >= 0; i--)
	{
		cin >> data[i];
	}
	for (int i = 0; i < N_num; i++)
	{
		cout << data[i];
		if (i != N_num - 1)
			cout << ' ';
	}
cout<<'\n';
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>

int main(void){
  int h, w, H, W;
  for(;;){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0)
      break;
    for(h = 0; h < H; h++){
      for(w = 0; w < W; w++){
	if(h == 0 || h == (H - 1)){
	  printf("#");
	}else if(w == 0 || w == (W - 1)){
	  printf("#");
	}else
	  printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]= map(int,input().split())

maxi=max(A)
DP=[0]*(H+maxi)
DP[0]=0

for i in range(1,H+maxi):
  mini=float("inf")
  for j in range(N):
    if i-A[j]>=0:
      mini=min(mini, DP[i-A[j]]+B[j])
  DP[i]=mini
  
mini2=float("inf")
for k in range(H,H+maxi):
  mini2=min(mini2,DP[k])

print(mini2)

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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n;
int a[N];

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    forn(i, 1, n * 3)
        cin >> a[i];
    sort(a + 1, a + 1 + 3 * n);
    int p = n * 3 - 1;
    ll ans = 0;
    forn(i, 1, n) {
        ans += a[p];
        p -= 2;
    }
    cout << ans << "\n";

    return 0;
}


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


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

    ll money = 1000;
    ll max_money = 1000;
    ll stock = 0;
    rep(i,N) {
        money += stock * A.at(i);
        stock = 0;
        max_money = max(max_money, money);
        if (i == N - 1) break;
        if (A.at(i) < A.at(i+1)) {
            stock = money / A.at(i);
            money -= stock * A.at(i);
        }
    }
    cout << max_money << endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N, M; cin >> N >> M;
  string S; cin >> S;

  vector<int> ans;
  int now = N;
  while (now > 0) {
    bool isok = false;
    for (int i = min(M, now); i > 0; i--) {
      if (S[now-i] == '0') {
        isok = true;
        now -= i;
        ans.push_back(i);
        break;
      }
    }

    if (!isok) {
      cout << -1 << endl;
      return 0;
    }
  }

  for (int i = ans.size()-1; i > 0; i--) {
    cout << ans[i] << " ";
  }
  cout << ans[0] << endl;

  return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main(){
    long long N,s[5]={};
    std::string name;
    std::cin>>N;
    for(int i=0;i<N;++i){
        std::cin>>name;
        char a=name[0];
        switch(a){
            case 'M':
                s[0]++;
                break;
            case 'A':
                s[1]++;
                break;
            case 'R':
                s[2]++;
                break;
            case 'C':
                s[3]++;
                break;
            case 'H':
                s[4]++;
                break;
        }
    }
    long long ans=0;
    for(int i=0;i<5;++i){
        for(int j=i+1;j<5;++j){
            for(int k=j+1;k<5;++k){
                ans+=s[i]*s[j]*s[k];
            }
        }
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int d,w;
    while(true){
        cin>>d>>w;
        if(d==0||w==0)break;
        int ike[d][w];
        rep(i,d){ rep(j,w){ cin>>ike[i][j]; }}
        int ans=0;
        for(int iw=3;iw<=w;iw++){
            for(int id=3;id<=d;id++){
                for(int x=0;x<=w-iw;x++){
                    for(int y=0;y<=d-id;y++){
                        int water=0;
                        int masu=0;
                        int sotom=INF;int nakam=0;

                        for(int i=x;i<x+iw;i++){
                            for(int j=y;j<y+id;j++){
                                if(i==x||i==x+iw-1){
                                    sotom=min(sotom,ike[j][i]);
                                }else if(j==y||j==y+id-1){
                                    sotom=min(sotom,ike[j][i]);
                                }else{
                                    water+=ike[j][i];
                                    masu++;
                                    nakam=max(nakam,ike[j][i]);
                                }
                            }
                        }
                        if(nakam<sotom){
                            int res=masu*sotom-water;
                            ans=max(res,ans);
                        }
                    }
                }
            }
        }

        cout<<ans<<endl;






    }



    return 0;
}



Measured memory_bytes: 3076
n = int(input())
list_a = list((map(int, input().split())))
sum = 0
for number in list_a:
    sum += number
    ave = sum/n
if ave - int(ave) <= int(ave) + 1 - ave:
    ave = int(ave)
else:
    ave = int(ave) + 1
ans = 0
for number in list_a:
    ans += (number - ave)**2

print(int(ans))


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    
    int a[3];
    int N;
    int i,j,k,tmp;
    
    cin>>N;
    for(k=0;k<N;k++){
        cin>>a[0]>>a[1]>>a[2];
        for(i=0;i<2;i++){
            for(j=i+1;j<3;j++){
                if(a[j]>a[i]){
                    tmp=a[i];
                    a[i]=a[j];
                    a[j]=tmp;
                }
            }
            
            
        }
        
        if(pow(a[0],2)==pow(a[1],2)+pow(a[2],2)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    
    }

}

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

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    ll cnt = 0;
    ll mx = 0;
    rep(i,s.size()){
        if(s[i] == 'I') cnt++;
        else cnt--;
        mx = max(mx,cnt);
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc118/tasks/abc118_d
=begin
20 4
3 7 8 4
777773

101 9
9 8 7 6 5 4 3 2 1
71111111111111111111111111111111111111111111111111

15 3
5 4 6
654
=end
N, _M = gets.split.map(&:to_i)
valid_nums = gets.split
MATCH_NUM = {
  '1' => 2,
  '2' => 5,
  '3' => 5,
  '4' => 4,
  '5' => 5,
  '6' => 6,
  '7' => 3,
  '8' => 7,
  '9' => 6
}.freeze

dp = ['']

1.step(N) do |i|
  valid_nums.each do |str|
    next if i < MATCH_NUM[str] || !dp[i - MATCH_NUM[str]]
    if (dp[i - MATCH_NUM[str]] + str).size == dp[i]&.size.to_i
      dp[i] = dp[i - MATCH_NUM[str]] + str > dp[i] ? dp[i - MATCH_NUM[str]] + str : dp[i]
    elsif (dp[i - MATCH_NUM[str]] + str).size > dp[i]&.size.to_i
      dp[i] = dp[i - MATCH_NUM[str]] + str
    end
  end
end

p dp[N].to_i


Measured memory_bytes: 104316
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return input().rstrip()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    st = LSR(n)
    x = S()
    ans = 0
    te = 0
    for s, t in st:
        if te:
            ans += int(t)
        if s == x:
            te = 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a.at(i);
        --a.at(i);
    }
    vector<ll> sum(n+1,0);
    for(i = 1;i <= n;++i){
        sum.at(i) = a.at(i-1);
    }
    rep(i,n){
        sum.at(i+1) += sum.at(i);
        sum.at(i+1) %= k;
    }
    map<ll, vector<ll>> spare;
    for(i = 0;i <= n;++i){
        spare[sum.at(i)].push_back(i);
    }
    ll ans = 0;
    for(auto x:spare){
        auto y = x.second;
        ll m = y.size();
        for(i = 0;i < m;++i){
            ll now = y.at(i);
            ll ind = lower_bound(all(y), now + k) - y.begin() - 1;
            ans += ind - i;
        }
    }
    cout << ans << endl;

    return 0;
}

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

long long n, W;
long long w[110], v[110];
long long dp[110][110000];

int main(){
    cin >> n >> W;
    for(int i=1; i<=n; i++) cin >> w[i] >> v[i];

    for(int i=1; i<=n; i++){
        for(int j=0; j<=W; j++){
            dp[i][j] = dp[i-1][j];
            if(j-w[i]>=0){
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


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

int main() {
	vector<int> a = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
	int x , y;
	cin >> x >> y;

	cout << (a.at(x) == a.at(y) ? "Yes" : "No") << endl;

	return 0;
}

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

int task_C (std::vector<unsigned int>& sequence)
{
	// variables for this function
	register unsigned int maxval_1st;
	register unsigned int maxval_2nd;
	register unsigned int maxval_answer;

	// STEP.01
	// initialize the variables to store the maximum values of given sequence
	maxval_1st = 0U;
	maxval_2nd = 0U;

	// STEP.02
	// search the maximum values of given sequence
	for (register auto itr = sequence.begin(); itr != sequence.end(); itr++)
	{
		if (maxval_1st < *itr)
		{
			maxval_2nd = maxval_1st;
			maxval_1st = *itr;
		}
		else if (maxval_2nd < *itr)
		{ maxval_2nd = *itr; }
		else
		{ continue; }
	}

	// STEP.02
	// output the answer of this task
	for (register auto itr = sequence.begin(); itr != sequence.end(); itr++)
	{
		if (*itr != maxval_1st) { maxval_answer = maxval_1st; }
		else                    { maxval_answer = maxval_2nd; }

		std::cout << maxval_answer << std::endl;
	}

	// STEP.END
	return EXIT_SUCCESS;
}

int main (void)
{
	// variables for main process
	register unsigned int buffer_input;
	static   unsigned int N;

	// instances for this function
	std::vector<unsigned int> A;

	// STEP.01
	// read out the given data
	// (the length of the given sequence)
	std::cin >> N;

	// STEP.02
	// read out the given data
	// (the values of the given sequence)
	for (register size_t itr = 0; itr < N; itr++)
	{
		std::cin >> buffer_input;
		A.push_back(buffer_input);
	}

	// STEP.03
	// calculate & output the answer of this task
	task_C (A);

	// STEP.END
	return EXIT_SUCCESS;
}

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

using namespace std;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M;
	cin >> N >> M;

	int count = 0;
	int a = 1, b = a + N / 2 - 2;
	while(1){
		if(M <= count || b <= a) break;
		cout << a << " " << b << endl;
		a++; b--;
		count++;
	}

	a = N / 2;
	b = N;
	if((b & 1) == 0) b--;
	while(1){
		if(M <= count) break;
		cout << a << " " << b << endl;
		a++; b--;
		count++;
	}

	return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define F first
#define S second
#define MP make_pair
#define LL long long
#define MOD 1000000007


int main()  {
//    freopen("in.txt", "r", stdin);
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    FOR(i, 0, (int)s.size() - 1)   {
        if(s[i] == '0')    {
            a++;
        }
        else    {
            b++;
        }
    }
    cout << min(a, b) * 2 << "\n";
    return 0;
}
/**
*/


Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        a: usize,
        s:chars,
    }

    let ss: String = s.into_iter().collect();

    if a >= 3200 {
        println!("{}", ss);
    } else {
        println!("red");
    }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(long long N, long long K){

    lli d = N-2;

    if((d+1)*d/2 < K){
        cout<<-1<<endl;
        return;
    }

    vector<pair<lli,lli>> ans;

    lli cnt=0;
    REP(i,0,N-1){
        ans.push_back({i,N-1});
        REP(j,i+1,N-1){
            if(cnt<K){
                cnt++;
                continue;
            }
            ans.push_back({i,j});
        }
    }

    cout<<ans.size()<<endl;
    REP(i,0,ans.size()){
        cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    func(N, K);
    return 0;
}


Measured memory_bytes: 3812
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
    	long n = sc.nextLong();
      	long a = sc.nextLong();
      	long b = sc.nextLong();

      	long period = n / (a + b);
      	long remainder = n % (a + b);

      	long ans = remainder > a ? period * a + a : period * a + remainder;

      	System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;

/*
累積和s[0] s[1] s[2]... s[n-1]
の中から、
・mで割った余りが等しいもの同士をxC2する
・余りが0であるものの個数を足す
m=3について、
1 4 6 2 2
は、
1 5 11 13 15
3で割った余りは
0 1 1 2 2
だから、
1+1+1=3

*/

void solve(){
    ll n,m;
    cin >> n >> m;
    ll a[n+10];
    rep(i,n){
        cin >> a[i];
    }
    
    ll ans = 0;
    //累積和計算
    ll sum[n+10];
    sum[0]=a[0];
    for(ll i=1; i<n; i++){
        sum[i] = sum[i-1]+a[i];
    }
    rep(i,n){
        sum[i] = sum[i]%m;
    }
    sort(sum,sum+n);

    ll count1=0;
    rep(i,n){
        if(sum[i]==0) count1++;
        else break;
    }
    ans += count1;
    ll pointer = 0;
    ll count = 1;
    while(pointer<n){
        if(sum[pointer]==sum[pointer+1]){
            pointer++;
            count++;
        }
        else{
            ans += count*(count-1)/2;
            count=1;
            pointer++;
        }
    }
    cout << ans << endl;


}

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


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl p(n);
    rep(i,n)cin>>p[i];
    ll cnt=0;
    rep(i,n){
        if(i+1!=p[i])cnt++;
    }
    YES(cnt==2||cnt==0);
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include <queue>
#define LL long long
using namespace std;
LL n,m,ans,tt,x[1001],y[1001],z[1001];
int main(){
  scanf("%lld %lld",&n,&m);
  for(LL i=1;i<=n;i++){
  	scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
  }
  for(LL i=-1;i<=1;i+=2){
  	 for(LL j=-1;j<=1;j+=2){
  	 	for(LL k=-1;k<=1;k+=2){
  	 	   priority_queue <LL> hh;
			  for(LL l=1;l<=n;l++){
  	 	   	  hh.push(i*x[l]+j*y[l]+k*z[l]);
		   }
		   tt=0;
		   for(LL l=1;l<=m;l++){
		   	  tt+=hh.top();
		   	  hh.pop();
		   }
		   if(tt>ans)
		     ans=tt;
	    }
     }
  }
  printf("%lld",ans);
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//--//--//--//--//--//--//--//--//--//--//--//

int main(){

	//input//
	int d, t, s;
	cin >> d >> t >> s;

	if(s*t >= d){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	long n;
	cin >> n;
	long A[2000000];
	long sfrag = 0, efrag = -1;

	string S;
	long s;

	for (int k = 0; k < n; k++)
	{
		cin >> S;
		if (S == "insert")
		{
			cin >> s;
			efrag++;
			A[efrag] = s;
		}
		else if (S == "delete")
		{
			cin >> s;
			int x = efrag;
			while (x >= 0)
			{
				if (A[x] == s)
				{
					A[x] = -1;
					break;
				}
				x--;
			}
		}
		else if (S == "deleteLast")
		{
			while (A[sfrag] == -1) sfrag++;
			sfrag++;
		}
		else if (S == "deleteFirst")
		{
			while (A[efrag] == -1) efrag--;
			efrag--;
		}
	}

	long c = 0;
	for (long i = efrag; i >= sfrag; i--)
	{
		if (A[i] != -1)
		{
			if (c != 0) cout << " ";
			cout << A[i];
			c++;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 11032
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;

int main()
{
    //system("chcp 65001");

    string S;
    string T;
    int ans = 0;
    cin >> S >> T;

    for(int i = 0;i <= 2;i++)
    {
        if(S[i] == T[i])
        {
            ans++;
        }
    }
    //cout << S << endl;
    //cout << T;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, a[100000], i, p = 1;

	scanf("%d", &n);
	for (i = 0;i < n;i++) {
		scanf("%d", &a[i]);
	}

	for(i = 1;i < n;i++){
		p = a[p-1];
		if (p == 2) {
			printf("%d\n", i);
			break;
		}
	}

	if (p != 2) {
		printf("-1\n");
	}

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){

   int n,i,max=0,sum=0;
   int l[10];

   scanf("%d",&n);

   for(i=0;i<n;i++){
     scanf("%d",&l[i]);
     if(l[i]>=max) max=l[i];
   }

   for(i=0;i<n;i++){
      sum=sum+l[i];
   }

   if((sum-max)>max){
    printf("Yes\n");
   }else{
    printf("No\n");
   }   
 
   return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100005];
    int n,k,min1,min2;
    cin>>n>>k;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a,a+n);
    int ans=0x3f3f3f3f;

    for(int i=0; i<n-k+1; i++)
    {
         min1=min(abs(a[i])+a[i+k-1]-a[i] , abs(a[i+k-1])+a[i+k-1]-a[i]);
         ans=min(ans,min1);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    cout << 24 - m + 24 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int cnt = 0;
        int[][] x = new int[N][D];
        for(int i = 0; i<N; i++) {
        	for(int j = 0; j<D; j++) {
            	x[i][j] = sc.nextInt();        		
        	}
        }

        double d = 0;
        for(int i=0; i<N; i++) {
        	for(int j = i + 1; j<N; j++) {
        		d = 0;
        		for(int k = 0; k<D; k++) {
            		d= d + Math.pow(x[i][k] - x[j][k], 2); 
        		}
    			d = Math.pow(d, 1.0/2);
    			if(d==Math.floor(d)) {
    				cnt++;
    			}
        	}
        }
        
        
        
        System.out.println(cnt);
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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;
};

// Dinic法
// 最大流を求める。最短の増加パスを探して、そこにフローを流していくことを繰り返す。そのような経路がなくなったら残余パスでもう一度それを繰り返す。それでも、流せなくなったら終了する。
// 計算量 O(E * V^2)
// ただしほとんどの場合、実際の計算量より高速に動作する。

static const int INF = (1<<30);

class Dinic {
  struct Edge {
    int to, cap, rev;
  };

  public:
    int V;
    vector<vector<Edge>> G;
    vector<int> level; // sからの距離
    vector<bool> used;
  Dinic(int V): V(V), G(V), used(V) {}

  void addEdge(int from, int to, int cap) {
    G[from].pb((Edge){ to, cap, (int) G[to].size() });
    G[to].pb((Edge) { from, 0, (int) G[from].size()-1 });
  }
  // sからの到達するのにかかる最短のステップ数をbfsで調べる
  void bfs(int s) {
    level.assign(V, -1); // level 初期化
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto &e: G[v]) {
        // level[e.to] == -1つまり未"発見"
        // 距離が増加する向きの辺のみからなるグラフを作成
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  int dfs(int v, int t, int f) {
    if (v == t) return f;

    used[v] = true;
    rep (i, 0, G[v].size()) {
      Edge &e = G[v][i];
      // 容量ありでかつ辺の先はより遠い
      if (e.cap > 0 && level[v] < level[e.to] && !used[e.to]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }

    return 0;
  }

  int max_flow(int s, int t) {
    int ret = 0, f;
    while (bfs(s), level[t] >= 0)  {
      used.assign(V, false);
      while ((f = dfs(s, t, INF)) > 0) {
        ret += f;
      }
    }
    return ret;
  }
};

int main() {
  int V, E;
  cin >> V >> E;
  int u, v, c;
  Dinic d(V);
  rep(i, 0, E) {
    cin >> u >> v >> c;
    d.addEdge(u, v, c);
  }
  int ans = d.max_flow(0, V - 1);
  cout << ans << endl;
};





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

using namespace std;
typedef long long ll;

const int N = 200'010;
vector<int> g[N];
bool vis[N];

int dfs(int v, int p = -1) {
    int cnt = 1;
    vis[v] = 1;
    for (auto to : g[v]) {
        if (to == p || vis[to]) continue;
        cnt += dfs(to, v);
    }
    return cnt;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int a, b;
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) ans = max(ans, dfs(i));
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 27384
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
int dp[100000][3]={0};

int bottomup2(int a[100000][3],int n)
{
	int best=0;
	for(int i=0;i<3;i++)
	{
		dp[0][i]=a[0][i];
		best=max(best,dp[0][i]);
	}

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)    //current row
		{
			for(int k=0;k<3;k++)     //will iterate on above 
			{
				if(j==k)
					continue;
				dp[i][j]=max(dp[i][j],a[i][j]+dp[i-1][k]);
				best=max(best,dp[i][j]);
			}
		}
	}
	return best;
}

int main()
{
	ios_base::sync_with_stdio(0);            //fast input and output
	cin.tie(NULL);
	cout.tie(NULL);
	int n,a[100000][3];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	cout<<bottomup2(a,n)<<endl;

    
    return 0;
}

Measured memory_bytes: 5956
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ex[4]={1,-1,1,-1};
int ey[4]={1,1,-1,-1};
int fx[4]={2,0,-2,0};
int fy[4]={0,2,0,-2};

int mp[20][20]={};

signed main(){
  int x,y,s;
  char z;
  while(cin>>x>>z>>y>>z>>s){
    if(s==1){
      mp[y][x]+=1;
      rep(i,4){
        if(y+dy[i]>=0&&x+dx[i]>=0){
          mp[y+dy[i]][x+dx[i]]+=1;
        }
      }
    }
    else if(s==2){
      mp[y][x]+=1;
      rep(i,4){
        if(y+dy[i]>=0&&x+dx[i]>=0){
          mp[y+dy[i]][x+dx[i]]+=1;
        }
        if(y+ey[i]>=0&&x+ex[i]>=0){
          mp[y+ey[i]][x+ex[i]]+=1;
        }
      }
    }
    else if(s==3){
      mp[y][x]+=1;
      rep(i,4){
        if(y+dy[i]>=0&&x+dx[i]>=0){
          mp[y+dy[i]][x+dx[i]]+=1;
        }
        if(y+ey[i]>=0&&x+ex[i]>=0){
          mp[y+ey[i]][x+ex[i]]+=1;
        }
        if(y+fy[i]>=0&&x+fx[i]>=0){
          mp[y+fy[i]][x+fx[i]]+=1;
        }
      }
    }
  }
  int ans1=0,ans2=0;
  rep(i,10){
    rep(j,10){
      if(mp[i][j]==0)ans1++;
      if(ans2<mp[i][j])ans2=mp[i][j];
    }
  }
  cout<<ans1<<endl;
  cout<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 3004
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *left;
    Node *right;
};

Node *root, *NIL;

Node* newNode(int key) {
    Node *node = new Node();
    node->key = key;
    node->left = NIL;
    node->right = NIL;
    return node;
}

void insert(int key) {
    Node *x = root, *y = NIL;
    while (x != NIL) {
        y = x;
        if (key < x->key)
            x = x->left;
        else
            x = x->right;
    }
    Node *z = newNode(key);
    if (y == NIL)
        root = z;
    else if (key < y->key)
        y->left = z;
    else
        y->right = z;
}

bool find(int key) {
    Node *x = root;
    while (x != NIL) {
        if (key == x->key)
            return true;
        else if (key < x->key)
            x = x->left;
        else
            x = x->right;
    }
    return false;
}

void inorder(Node *t) {
    if (t == NIL)
        return;
    inorder(t->left);
    cout << " " << t->key;
    inorder(t->right);
}

void preorder(Node *t) {
    if (t == NIL)
        return;
    cout << " " << t->key;
    preorder(t->left);
    preorder(t->right);
}

int main() {
    int n, v;
    string s;
    root = NIL;
    cin >> n;
    while (n--) {
        cin >> s;
        if (s == "insert") {
            cin >> v;
            insert(v);
        }
        if (s == "find") {
            cin >> v;
            if (find(v))
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
        if (s == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 15664