akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return b;
    }

    return gcd(b, a%b);
}

int gcd(int a, int b, int c)
{
    return gcd(gcd(a,b), c);
}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll acc = 0;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            for(int k=1;k<=n;++k)
            {
                acc += gcd(i,j,k);
            }
        }
    }
    cout << acc << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	int a, b;
	while (cin >> a >> b)
	{
		int x = a, y = b;
		while (a%b != 0)
		{
			int r = a%b;
			a = b;
			b = r;
		}
		cout << b << " " << x / b*y / b*b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

	int n,m;
	cin>>n>>m;
	map<int,vi>ma;
	rep(i,n){
		int a,b;cin>>a>>b;
		ma[a-1].pb(b);
	}
	priority_queue<int>pq;
	int out=0;
	rep(i,m){
		rep(j,ma[i].size())pq.push(ma[i][j]);
		if(!pq.empty()){
			out+=pq.top();
			pq.pop();
		}
	}
	cout<<out<<endl;
}


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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> R(n, 0);
  for (int i=0; i<n; i++) std::cin >> R[i];
  
  int minimum = R[0];
  int diff = R[1] - R[0];
  for (int i=2; i<n; i++) {
    if (R[i-1] < minimum) minimum = R[i-1];
    if (R[i] - minimum > diff) diff = R[i] - minimum;
  }
  
  std::cout << diff << std::endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<vector<ll>> vec;
  rep(i,n){
    ll x, y, h;
    cin >> x >> y >> h;
    vector<ll> r = {x,y,h};
    vec.push_back(r);
  }
  for(ll i = 0; i < 101; i++) {
    for(ll j = 0; j < 101; j++) {
      ll h = -1;
      bool ok = true;
      rep(k,n) {
        if (vec[k][2] == 0) continue;
        ll tmp = vec[k][2] + abs(vec[k][0] - i) + abs(vec[k][1] - j);
        if (h == -1) {
          h = tmp;
        } else if (h > 0) {
          if (h != tmp) {
            ok = false;   
          }
        }
      }
      rep(k,n) {
        if (vec[k][2] == 0) {
          ll tmp = abs(vec[k][0] - i) + abs(vec[k][1] - j);
          if (h > tmp) ok = false;
        }
        
      }
      if (ok) {
        cout << i << " " << j << " " << h;
        return 0;
      }
      h = -1;
    }
  }
  return 0;
}

Measured memory_bytes: 3616
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))


Measured memory_bytes: 19472
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long D, std::vector<long long> c, std::vector<std::vector<long long>> s, std::vector<long long> t) {
  vector<set<ll>> last(26);
  REP(j, 26) {
    last[j].insert(0);
  }
  ll score = 0;
  REP(d, D) {
    ll i = t[d] - 1;
    score += s[d][i];
    last[i].insert(d + 1);
    REP(j, 26) {
      score -= c[j] * (d + 1 - *last[j].rbegin());
    }
    cout << score << endl;
  }
}

int main() {
  long long D;
  scanf("%lld", &D);
  std::vector<long long> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &c[i]);
  }
  std::vector<std::vector<long long>> s(D, std::vector<long long>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%lld", &s[i][j]);
    }
  }
  std::vector<long long> t(D);
  for (int i = 0; i < D; i++) {
    scanf("%lld", &t[i]);
  }
  solve(D, std::move(c), std::move(s), std::move(t));
  return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i<n;i++)
#define fod(i,n) for(i=n-1;i>=0;i--)
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld k, n;
    cin >> k;
    cin >> n;
    lld m, i;
    lld A[n];
    m =2 * n;
    lld D[m];
    foi(i,n){
    	cin >> A[i];
    }
    lld j = 0;
    for(i = 1; i < n; i+=1){
    	D[j]= A[i] - A[i-1];
    	j++;
    }
    	D[j]= k-A[n-1]+A[0];
    	j++;
    for(i = 1; i < n; i+=1){
    	D[j]= A[i] - A[i-1];
    	j++;
    }
    	D[j]= k-A[n-1]+A[0];
    	j++;
    lld d = 0;
    lld min =MAX;
    for(i = 0; i<n-1; i+=1){
    	d+= D[i];
    }
    if (d < min){
    	min  = d;
   	}
    for(i = 1; i < n; i+=1){
    	d = d-D[i-1];
    	d+= D[i+n-2];
    	if (d < min){
    		min  = d;
    	}
    }
    cout <<min<<"\n";
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
     
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d\n", calcRectangleArea(a, b), calcRectangleAround(a, b));
        
    }
     
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
    
    public int calcRectangleArea(int height, int width){
        return height * width;
    }
    
    public int calcRectangleAround(int height, int width){
        return (height + width) * 2;
    }
}

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

int main(void){
  int n,l; cin >> n >> l;
  int sum = 0;
  int eat = 1000;
  int check;
  for(int i = 1; i <= n; i++){
    sum += l + i -1;
    if(eat > abs(l + i - 1)){
      check = i;
      eat = abs(l + i - 1);
    }
  }
  cout << sum - (l+check-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) > "Yes" : "No" ) << endl


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

template <class T = int> T in() { T x; cin >> x; return (x); }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int k = in(), cnt = 0;

	FOR(i,1,k) {
		if (i % 2 == 0) {
			FOR(j,1,k) {
				if (j % 2 == 1) {
					cnt++;
				}
			}
		}
	}

	cout << cnt << endl;

	return;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
int main() {
	double a,b,h,m;
	double a_kaku,b_kaku,c_kaku;
	double ans;
	cin >>a>>b>>h>>m;
	b_kaku=6*m;
	a_kaku=30*h+0.5*m;
	c_kaku=abs(a_kaku-b_kaku);
//	cout <<"akaku="<<a_kaku<<endl;
//	cout <<"bkaku="<<b_kaku<<endl;
//	cout <<"ckaku="<<c_kaku<<endl;
	ans=sqrt(a*a+b*b-2*a*b*cos(M_PI*c_kaku/180));
	cout << fixed<<setprecision(20);
	cout <<ans<<endl;
	return 0;
}


Measured memory_bytes: 4256
import math
n = int(input())
r = list(map(int,input().split()))

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > 1000000000000000000:
        break

if x > 1000000000000000000:
    x = -1

if 0 in r:
    x = 0

print(math.floor(x))

Measured memory_bytes: 22476
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                    f_idx = j

                elif j == len(s) - 1:
                    if max_c < j - f_idx:
                        max_c = j - f_idx

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k,ans=0;

    cin>>n>>k;
/// TLE
//    for(int i=0;i<n;i++)
//    {
//
//        ans=min(n,abs(n-k));
//        n=ans;
//    }
//
    //     cout<<ans;

    if(n%k==0)
    {
        cout<<0;
    }
    else
    {
        n%=k;
        cout<<min(n,k-n);
    }



  return 0;
}


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


int main(){
int N, M;
cin >> N >>M;
vector<string> mo(N);

for(int i = 0;i<N;i++)cin >> mo.at(i);
  sort(mo.begin(), mo.end());
for(int i = 0;i<N;i++) cout<<mo.at(i); cout <<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;

bool check(long long int n){
  string s = to_string(n);
  int a = 0;
  int b = 0;
  int c = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '3'){
      a++;
    }
    else if(s[i] == '5'){
      b++;
    }
    else if(s[i] == '7'){
      c++;
    }
  }
  return (min(a,min(b,c)) == 0 ? false: true);
}

int dfs(long long int a,long long int n){
  if(a > n){
    return 0;
  }
  int ret = 0;
  if(check(a) == true){
    ret++;
  };
  //cout << a << "," << ret << endl;

  return ret + dfs(a*10 + 7, n) + dfs(a*10 + 5, n) + dfs(a*10 + 3, n);
}

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  
  cout << dfs(0, n) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main()
{
    int a , b , c;
    cin >> a >> b >> c;
    if (1<=a && a<=100 && 1<=b && b<=100 && 1<=c && c<=100 )
    {
    if (a!=b && a!=c && b!=c)
        cout << 3;
    else if (a==b && a!=c && b!=c)
        cout << 2;
    else if (a!=b && a==c && b!=c)
        cout << 2;
    else if (a!=b && a!=c && b==c)
        cout << 2;
    else if (a==b && a==c && b==c)
        cout << 1;
    }
    return 0;
}

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

using namespace std;

int main()
{
	int n,m,c;
	scanf("%d%d%d",&n,&m,&c);
	
	int b[101];
	
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int dou=0;
		for(int j=1;j<=m;j++)
		{
			int x;
			scanf("%d",&x);
			dou+=x*b[j];
		}
		if(dou+c>0) ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
 } 

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

int main(void){
    ll t[2], a[2], b[2];
    cin >> t[0] >> t[1];
    cin >> a[0] >> a[1];
    cin >> b[0] >> b[1];
    ll am = t[0]*a[0];
    ll bm = t[0]*b[0];
    ll ah = t[0]*a[0] + t[1]*a[1];
    ll bh = t[0]*b[0] + t[1]*b[1];
    if (ah == bh) {
        cout << "infinity" << endl;
        return 0;
    }
    if ((am-bm > 0) ^ (ah-bh > 0)) {
        ll dm = abs(am-bm);
        ll dh = abs(ah-bh);
        ll res = (dm/dh)*2+1;
        if (dm % dh == 0) res--;
        cout << res << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int i;
    int A, B, K, flag=0;

    scanf("%d",&K);
    scanf("%d %d",&A, &B);

    for(i=A; i<=B; i++) {
        if(i%K == 0) {
            flag = 1;
            break;
        } 
    }

    if(flag == 1) {
        printf("OK\n");
    } else {
        printf("NG\n");
    }

    return 0;
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s;
	cin >> s;
	int n = s.length();  
  
    // To store the number of replacement operations  
    int cc = 0; 
  
    for(int i=0;i<n/2;i++) 
    { 

        if(s[i]== s[n-i-1])  continue; 

        cc+= 1; 

        if(s[i]<s[n-i-1])  
            s[n-i-1]= s[i] ; 
        else
            s[i]= s[n-i-1] ; 
    }
    cout << cc << "\n";
	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 rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


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

    vector<vector<int>> pos(10);

    rep(i,N){
        rep(j,10){
            if(S[i] -'0' == j) pos[j].push_back(i);
        }
    }

    int ans = 0;
    rep(d1,10)rep(d2,10)rep(d3,10){
        if(pos[d1].empty()) continue;
        int p1 = pos[d1][0];

        auto it2 = upper_bound(pos[d2].begin(), pos[d2].end(), p1);
        if(it2 == pos[d2].end()) continue;
        int p2 = *it2;

        auto it3 = upper_bound(pos[d3].begin(), pos[d3].end(), p2);
        if(it3 == pos[d3].end()) continue;

        //cout << d1 << " " << d2 << " " << d3 << endl;
        //cout << p1 << " " << p2 << " " << *it3 << endl;
        
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 5005
using namespace std;
typedef long long LL;
int n,a[maxn];
LL A,B;
LL f[maxn][maxn];
int main()  {
    scanf("%d%lld%lld",&n,&A,&B);
    for (int i=1;i<=n;++i)
        scanf("%d",a+i);
    memset(f,0x3f,sizeof(f));
    f[0][0]=0;
    for (int i=1;i<=n;++i)  {
        for (int j=i-1,c=0;~j;--j)
            if (a[j]<a[i])
                // cout<<i<<" <- "<<j<<endl,
                f[i][i]=min(f[i][i],f[j][j]+(i-j-1-c)*B+c*A);
            else    ++c;
        for (int j=0;j<i;++j)
            f[i][j]=f[i-1][j]+B;
        // for (int j=0;j<=i;++j)
        //     printf("f[%d][%d]=%lld\n",i,j,f[i][j]);
    }
    LL ans=1LL<<62;
    for (int i=1;i<=n;++i)
        ans=min(ans,f[n][i]);
    printf("%lld\n",ans);
    return 0;
}

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

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

	int m, n;
	cin >> m >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		m -= x;
	}
	cout << max(m, (int)-1);
}


Measured memory_bytes: 3612
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
z=0

for i in range(N):
    if A[i] > B[i]+z:
        ans+=B[i]+z
        z=0
    else:
        ans+=A[i]
        z=B[i]-A[i]+min(z,A[i])

print(ans+min(z,A[N]))

Measured memory_bytes: 19116
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

void add(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}

void sub(int &a, int b) {
  if ((a -= b) < 0) a += MOD;
}

int mul(int a, int b) {
  return (int) ((a * 1LL * b) % MOD);
}

int mpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int minv(int x) {
  return mpow(x, MOD - 2);
}

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    int cur = 1;
    map<int, int> last;
    int prev = -1;
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      if (prev != x) {
        add(cur, last[x]);
        last[x] = cur;
        prev = x;
      }
    }
    printf("%d\n", cur);
  }

  return 0;
}


Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll N,C;
vector<ll> x,v;
ll solve(){
    ll res = 0;
    cin >> N >> C;
    x.resize(N); v.resize(N);
    for(int i = 0; i < N;i++) cin >> x[i] >> v[i];
    
    vector<ll> cusum(N+1,0);
    vector<ll> rcusum(N+1,0);
    for(int i = 0; i <N;i++){
        cusum[i+1] = cusum[i] + v[i];
    }
    for(int i = 0; i < N;i++){
        cusum[i+1] -= x[i];
        res = max(res,cusum[i+1]);
    }
 //   cout << cusum << endl;
    
    reverse(x.begin(),x.end()); reverse(v.begin(),v.end());
    for(int i = 0; i < N;i++){
        rcusum[i+1] = rcusum[i] + v[i];
    }
    for(int i = 0; i < N;i++){
        rcusum[i+1] -= (C-x[i]);
        res = max(res,rcusum[i+1]);
    }
   // cout << rcusum << endl;
    
    vector<ll> check(N+1,0);
    for(int i = 1; i <= N;i++){
        check[i] = max(rcusum[i],check[i-1]);

    }
 //   cout << check << endl;
    reverse(x.begin(),x.end());
//    cout << res << endl;
    for(int i = 1; i < N; i++){
     //   cout << cusum[i] << " " << x[i-1] << " " << check[N-i] << endl;
     //   cout << cusum[i]-x[i-1]+check[N-i] << endl;
        res = max(res,cusum[i]-x[i-1]+check[N-i]);
    }
    
    check.assign(N+1,0);
    for(int i = 1; i <= N;i++){
        check[i] = max(cusum[i],check[i-1]);
    }
    reverse(x.begin(),x.end());
    for(int i = 1; i < N;i++){
        res = max(res,rcusum[i]-(C-x[i-1])+check[N-i]);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ld p = acos(-1) ;
	ll r ; cin >> r ;
	cout << fixed << setprecision(20) ;
	cout << 2.0*r*p << endl ;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;

}


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



int main(){
    
    ll N,a[5];
    cin>>N;
    rep(i,0,5)cin>>a[i];
    sort(a,a+5);
    if(N<=a[0])cout<<5<<endl;
    else cout<<(ll)ceil(N/(double)a[0])+4<<endl;
}






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

using namespace std;


void solve()
{
	int H, W;
	cin >> H >> W;
	vector< vector<char> > field(H, vector<char>(W));
	vector< vector<int> > dp(H, vector<int>(W));
	int maxWidth = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cin >> field[i][j];
			if (field[i][j] == '0')
			{
				dp[i][j] = 1;
				maxWidth = 1;
			}
			else
			{
				dp[i][j] = 0;
			}
		}
	}
	for (int i = 1; i < H; ++i)
	{
		for (int j = 1; j < W; ++j)
		{
			if (field[i][j] == '1')
			{
				dp[i][j] = 0;
			}
			else
			{
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	}
	cout << maxWidth * maxWidth << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 10772
#include<iostream>
using namespace std;
long long mod = 1e9+7;

int main(){
	int n,a,b;
  	cin>>n;
  	int sum[n],diff[n];
  	for(int i=0;i<n;++i){
    	cin>>a>>b;
      	sum[i] = a+b;
      	diff[i] = a-b;
    }
  	int mini1 = mod,mini2 = mod,maxi1 = -mod,maxi2 = -mod;
  	for(int i=0;i<n;++i){
    	if(mini1>sum[i])mini1 = sum[i];
      	if(maxi1<sum[i])maxi1 = sum[i];
      	if(mini2>diff[i])mini2 = diff[i];
      	if(maxi2<diff[i])maxi2 = diff[i];
    }
  
  	if(maxi1-mini1 > maxi2-mini2)cout<<maxi1-mini1;
  	else cout<<maxi2-mini2;
   
    return 0;
}


Measured memory_bytes: 5160
n = int(input())
s = input()

def check_rank(s):
    count = 0
    rank = [0] * len(s)
    for i, c in enumerate(s):
        if c == ")":
            count -= 1
        if c == "(":
            count += 1
        rank[i] = count
    return rank

r = check_rank(s)

if min(r) < 0:
    s = abs(min(r)) * "(" + s
    r = check_rank(s)

if r[-1] > 0:
    s = s + ")" * r[-1]
    r = check_rank(s)

print(s)

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

template<class H>
void CIN(H& h){cin>>h;}
template<class H, class... T>
void CIN(H &h, T&... t){cin>>h;CIN(t...);}
int main(){
  vector<int> x(5);
  for(int i=0; i<5;i++)cin>>x[i];
  for(int i=0; i<5; i++){
    if(x[i]==0){
      cout<<i+1<<endl;
      return 0;
    }
  }

}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
const int maxn=1010;
char str1[maxn],str2[maxn];
int main(){
//	fgets(str1,1010,stdin);
//	fgets(str2,1010,stdin);
	scanf("%s %s",str1,str2);
	int n1=strlen(str1);
	int n2=strlen(str2);
	if(n1!=n2){
		printf("No\n");
		return 0;
	}
	int sum=0;
	while(sum<n1){
		char ch=str1[0];
		for(int i=1;i<n1;i++){
			str1[i-1]=str1[i];
		}
		str1[n1-1]=ch;
		if(strcmp(str1,str2)==0){
			printf("Yes\n");
			return 0;
		}
		sum++;
	}
	printf("No\n");
	return 0;
}
//	for(int i=0;i<n;i++) str1[n+i]=str1[i];
//	for(int i=0;i<n;i++){
//		int ok=0;
//		for(int j=0;j<n;j++){
//			if(str2[j]==str1[j+i]&&j==n-1){
//				ok=1;
//				break;
//			}
//			
//		}
//		if(ok){
//			printf("Yes\n");
//			return 0;
//			}
//	}
//	printf("No\n");
//	return 0;
//}


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

typedef pair<double, int> P;

struct edge{
  int to;
  double cost;
};

struct cir{
  double x, y, r;
};

double xs, ys, xt, yt;
int n;
cir D[1010];
double cost[1010][1010];
bool used[1010];
vector<edge> G[1010];
double d[1010];

const double INF = 1e18 + 9;
const double EPS = 1e-8;

/*
void dijkstra()
{
  priority_queue<P> q;
  fill(d, d + n + 2, INF);
  d[0] = 0.0;
  q.push(P(0.0, 0));

  while (!q.empty()){
    P p = q.top(); q.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        q.push(P(d[e.to], e.to));
      }
    }
  }
}
*/
void dijkstra()
{
  fill(d, d + n + 2, INF);
  fill(used, used + n + 2, false);
  d[0] = 0.0;

  while (true){
    int v = -1;
    for (int u = 0; u <= n + 1; u++){
      if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }

    if (v == -1) break;
    used[v] = true;
    for (int u = 0; u <= n + 1; u++){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

int main()
{
  double a, b;
  cin >> D[0].x >> D[0].y >> a >> b;
  cin >> n;
  D[0].r = D[n + 1].r = 0.0;
  for (int i = 1; i <= n; i++){
    cin >> D[i].x >> D[i].y >> D[i].r;
  }
  D[n + 1].x = a; D[n + 1].y = b;

  for (int i = 0; i <= n + 1; i++){
    for (int j = 0; j <= n + 1; j++){
      if (i == j) continue;
      //edge e;
      //e.to = j;
      //e.cost = 
      cost[i][j] = sqrt(pow(D[i].x - D[j].x, 2) + pow(D[i].y - D[j].y, 2)) - D[i].r - D[j].r;
      //if (e.cost < 0.0) e.cost = 0.0;
      if (cost[i][j] < 0.0) cost[i][j] = 0.0;
      //G[i].push_back(e);
    }
  }

  dijkstra();

  printf("%.10lf\n", d[n + 1]);
}




Measured memory_bytes: 8320
N, *H = map(int, open(0).read().split())

maxMoveCount = 0
currentMoveCount = 0
previous = 0
for i in H:
    if previous >= i:
        currentMoveCount += 1
    else:
        if maxMoveCount < currentMoveCount:
            maxMoveCount = currentMoveCount
        currentMoveCount = 0
    previous = i

if maxMoveCount < currentMoveCount:
    maxMoveCount = currentMoveCount

print(maxMoveCount)

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

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

    int ar[n];
    
    bool ans = true;
 
    for(int i=0;i<n;i++){
        cin>>ar[i];

    }

    for(int i=0;i<n;i++){

        if(ar[i] % 2 ==0){
            
            if(ar[i]%3!=0 and ar[i]%5!=0){
            	ans = false;
            	break;
            }
        }
    }

    if(ans){
    	cout<<"APPROVED"<<endl;
    }else{
    	cout<<"DENIED"<<endl;
    }

	return 0;
}

Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    print(eval(iss()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 3e3+23;
const int maxn = 2e5+35;
const int mod = 998244353;
LL dp[maxm][maxm];
int n,s,a[maxm];
LL qpow(LL a,LL x,LL mod){
    LL res = 1;
    while(x){
        if(x&1) res = res * a % mod;
        a = a*a%mod;
        x >>= 1;
    }
    return res;
}
inline LL inv(LL a,LL mod){
    return qpow(a,mod-2,mod);
}
int main(){
    cin >> n >> s;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    dp[0][0] = qpow(2,n,mod);
    LL inv2 = inv(2,mod);
    for(int i = 1;i <= n; ++i){
        for(int j = 0;j <= s; ++j){
            dp[i][j] = dp[i-1][j];
            if(j-a[i]>=0) dp[i][j] = (dp[i][j]+dp[i-1][j-a[i]]*inv2)%mod;
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

Measured memory_bytes: 74496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <vector <ll>> v(n+1, vector <ll>(m+1, 0));
  rep(i, n) {
    rep(j, m) {
      cin >> v.at(i).at(j);
      v.at(i).at(m) += v.at(i).at(j);
      v.at(n).at(j) += v.at(i).at(j);
      v.at(n).at(m) += v.at(i).at(j);
    }
  }
  rep(i, n+1) {
    rep(j, m+1) {
      if (j) {
        cout << ' ' << v.at(i).at(j);
      } else {
        cout << v.at(i).at(j);
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3220
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//221
	string a;
	cin>>a;
	a[3]='8';
	cout<<a;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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


#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f

using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
ll n;
cin>>n;
ll ans =n+n*n+n*n*n;
cout<<ans<<endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
int main(){cin>>n>>m;m=2*m+1;cout<<(n+m-1)/m<<endl;}

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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int a=0,b=0;
  for(int i=0;i<N;i++){
    char c;
    cin >> c;
    if(c=='a'){
      if(a+b<A+B){
        a++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else if(c=='b'){
      if(a+b<A+B && b<B){
        b++;
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}




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

using namespace std;

int getDays(int y, int m, int d)
{
  int cnt = 0;
  for(int i = 1; i <= y; i++){
    for(int j = 1; j <= 10; j++){
      for(int k = 1; k <= 20; k++){
	if(i % 3 != 0 && j % 2 == 0 && k == 20) continue;
	cnt++;
	if(i == y && j == m && k == d) return cnt;
      }
    }
  }
}

int main()
{
  int clbday = getDays(1000, 1, 1);
  
  int n;
  cin >> n;
  while(n--){
    int Y, M, D;
    cin >> Y >> M >> D;
    cout << clbday - getDays(Y, M, D) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const s = args[0][0]
	console.log(`${s.slice(0, 4)} ${s.slice(4, 12)}`)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
module mod_union_find
  implicit none
  type union_find
    integer :: n = 0
    integer, allocatable :: par(:), rnk(:), cnt(:)
  contains
    procedure :: find => find
    procedure :: same => same
    procedure :: unite => unite
    procedure :: size => size_of
  end type
  interface union_find
    module procedure :: newuf
  end interface
contains
  type(union_find) function newuf(n) result(res)
    integer, intent(in) :: n
    integer :: i
    res%n = n
    allocate(res%par(n), res%rnk(n), res%cnt(n))
    res%par = [(i, i = 1, n)]
    res%rnk = 0
    res%cnt = 1
  end
  recursive integer function find(this, i) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    if (this%par(i) /= i) this%par(i) = find(this, this%par(i))
    res = this%par(i)
  end
  logical function same(this, i, j) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = find(this, i) == find(this, j)
  end
  subroutine unite(this, i, j)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    integer :: x, y
    x = find(this, i)
    y = find(this, j)
    if (x == y) return
    if (this%rnk(x) < this%rnk(y)) then
      this%par(x) = y
      this%cnt(y) = this%cnt(y) + this%cnt(x)
    else
      this%par(y) = x
      this%cnt(x) = this%cnt(x) + this%cnt(y)
      if (this%rnk(x) == this%rnk(y)) this%rnk(x) = this%rnk(x) + 1
    end if
  end
  integer function size_of(this, i) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    res = this%cnt(find(this, i))
  end
end module mod_union_find
program connect_cities
  use mod_union_find
  implicit none
  integer :: n, m, a, b, u(100000) = 0, i
  type(union_find) :: uf
  read(*,*) n, m
  uf = union_find(n)
  do i = 1, m
    read(*,*) a, b
    call uf%unite(a, b)
  end do
  do i = 1, n
    u(uf%find(i)) = 1
  end do
  write(*,'(i0)') sum(u(1:n)) - 1
end program connect_cities

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  if (K - A <= 0) {
      cout << K << endl;
      return 0;
  } else {
      if (K - (A + B) <= 0) {
          cout << A << endl;
          return 0;
      } else {
          cout << A - (K - (A + B)) << endl;
          return 0;
      }
  }
  
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
const int64_t ZER=0LL;

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N) cin>>P.at(i);
  rep(i,N) P.at(i)--;
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);
  
  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> S,T;
    int64_t k=i,sum=0;
    while(seen.at(k)){
      seen.at(k)=false;
      S.push_back(C.at(k));
      sum+=C.at(k);
      k=P.at(k);
    }
    int64_t t=S.size(),r=K/t,q=K%t,MAX=-1*INF,NMAX,MAX2=-1*INF;
    rep(i,t){
      T.push_back(S.at(i));
      if(i>0) T.at(i)+=T.at(i-1);
      if(T.at(i)>MAX){
        MAX=T.at(i);
        NMAX=i+1;
      }
    }
      if(q<NMAX){
        rep(i,q) MAX2=max(MAX2,T.at(i));
        
        if(sum<0) ans=max(ans,MAX);
        else{
          auto temp=max(MAX+sum*(r-1),MAX2+sum*r);
          ans=max(ans,temp);
        }
      }
      else{
        if(sum<0) ans=max(ans,MAX);
        else ans=max(ans,MAX+sum*r);
      }
  }
  cout<<ans;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
 
using namespace std;
 
int main() {
	ll A, B, K;
	cin >> A >> B >> K;
 
	if (K <= A) {
		cout << A - K << " " << B << endl;
 
	}
	else if (K <= A+B) {
		cout << 0 << " " << B-(K-A) << endl;
 
	}
	else {
 
 
		cout << 0 << " " << 0 << endl;
	}
 
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i, j, r,c;
    while(scanf("%d%d",&r,&c)){
            if(r==0 && c==0)
            break;


    for(i=1; i<=r; i++)
    {
        for(j=1; j<=c; j++)
        {
            printf("#");
        }

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

    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;//2,3,,5,7を確認
    cin >> N;
    if(N==1)cout << "Yes" << endl;
    else if(N%2==0&&N/2<=9)cout << "Yes" << endl;
    else if(N%3==0&&N/3<=9)cout << "Yes" << endl;
    else if(N%4==0&&N/4<=9)cout << "Yes" << endl;
    else if(N%5==0&&N/5<=9)cout << "Yes" << endl;
    else if(N%6==0&&N/6<=9)cout << "Yes" << endl;
    else if(N%7==0&&N/7<=9)cout << "Yes" << endl;
    else if(N%8==0&&N/8<=9)cout << "Yes" << endl;
    else if(N%9==0&&N/9<=9)cout << "Yes" << endl;
    else  cout << "No" << endl;
    return 0;
}

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

#define ll long long
#define mod 1000000007
#define debug1(x) cerr<<#x<<" : "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("input.txt", "rt" , stdin);
//    freopen("output.out", "wt",stdout);


int main() {
    IOS;
    ll n,m;
    cin>>n>>m;
    ll a[n],sum=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];sum+=a[i];
    }
    ll x =sum/(4*m),k=0;
    if (sum % (4 * m) != 0) x++;

    for(ll i=0;i<n;i++){

        if(a[i]<x);else k++;

    }
    if(k<m)cout<<"No";else cout<<"Yes";
    return 0 ;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A[100000], N;
int main(){
  int i, j, res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    res++;
    while(i < N-1 && A[i]==A[i+1]){
      i++;
    }
    if(i==N-1){
      break;
    }
    if(A[i] < A[i+1]){
      while(i < N-1 && A[i] <= A[i+1]){
        i++;
      }
    }
    else{
      while(i < N-1 && A[i] >= A[i+1]){
        i++;
      }
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170413-1 [beta]

// --- original code ---
// int N, A[100000];
// {
//   int i, j, res = 0;
//   rd(N,A(N));
//   rep(i,N){
//     res++;
//     while(i < N-1 && A[i]==A[i+1]) i++;
//     if(i==N-1) break;
//     if(A[i] < A[i+1]){
//       while(i < N-1 && A[i] <= A[i+1]) i++;
//     } else {
//       while(i < N-1 && A[i] >= A[i+1]) i++;
//     }
//   }
//   wt(res);
// }


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x : a) {
        cin >> x;
    }

    vector<pair<int, int>> b(n);
    for (int i = 0; i < n; ++i) {
        b[i] = {a[i], i};
    }
    sort(b.begin(), b.end());

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 != b[i].second % 2) {
            cnt++;
        }
    }

    cout << cnt / 2 << endl;
}

Measured memory_bytes: 1408
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
int n;
int dp[maxn][2];
int cnt[maxn];
int a[maxn];
int main()
{
	geti(n);
	for (int i=1; i<=n; i++) geti(a[i]);
	dp[0][0] = 1;
	int it = 1;
	for (int i=1; i<=n; i++)
	{
		dp[i][0] = dp[i-1][0];
		while (a[it]!=a[i])
		{
			dp[i][0] = (dp[i][0]+dp[it][1])%mod;
			it++;
		}
		if (i>1&&a[i-1]!=a[i]) dp[i][1] = cnt[a[i]];
		if (i<n&&a[i+1]!=a[i]) cnt[a[i]] = (cnt[a[i]]+dp[i][0])%mod;
	}
	int ans = dp[n][0];
	while (it<=n) ans = (ans+dp[it++][1])%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3456