akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define d lld
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define MOD 1000000007
#define de(x) if(x!=0 && MODE==x)
#define MODE 1

using namespace std;

int N;
char s[3007] = {};
int dp[3007][3007] = {};
int pre[3007][3007] = {};

int sum(int idx, int l, int r) {
    return ( ( pre[idx][r] - pre[idx][l-1] ) % MOD + MOD ) % MOD;
}

main() {
    int i,j;

    scanf("%d", &N);
    scanf("%s", s+1);
    dp[1][1] = 1;
    pre[1][1] = 1;
    for (i=2; i <= N; i++) {
        if (s[i-1] == '<') {
            for (j=2; j <= i; j++) {
                dp[i][j] += sum( i-1, 1, j-1);
                dp[i][j] %= MOD;
            }
        } else if (s[i-1] == '>') {
            for (j=1; j < i; j++) {
                dp[i][j] += sum( i-1, j, i-1);
                dp[i][j] %= MOD;
            }
        }

        for (j=1; j<=i; j++) {
            pre[i][j] = pre[i][j-1] + dp[i][j];
            pre[i][j] %= MOD;
        }
    }

    int ans = sum( N, 1, N);
    printf("%d\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


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

using namespace std;
int a[30];

int main(){

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

    int cnt = 0;
    for (int l = 0; l < m; ++l) {
        if(a[l] == n) cnt++;
    }
    cout << cnt;
    return 0;
}

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

class cPoke
{
public:
	char m_cSuit;
	int m_nVal;
};

bool compare(const cPoke& card1, const cPoke& card2)
{
	return card1.m_nVal < card2.m_nVal;
}

void Bubble(cPoke pokeIn[], int nNum)
{
	for (int i = 0; i < nNum - 1; ++i)
	{
		for (int j = nNum - 1; j >= i + 1; --j)
		{
			if (pokeIn[j].m_nVal < pokeIn[j - 1].m_nVal)
			{
				swap(pokeIn[j], pokeIn[j - 1]);
			}
		}
	}
}

void Selection(cPoke pokeSelect[], int nNum)
{
	int nMin = 0;
	for (int i = 0; i < nNum - 1; ++i)
	{
		nMin = i;
		for (int j = i + 1; j < nNum; ++j)
		{
			if (pokeSelect[j].m_nVal < pokeSelect[nMin].m_nVal)
			{
				nMin = j;
			}
		}
		swap(pokeSelect[i], pokeSelect[nMin]);
	}
}

void Output(cPoke pokeIn[], int nNum, cPoke pokeStable[])
{
	bool bStable = true;
	for (int i = 0; i < nNum - 1; ++i)
	{
		cout << pokeIn[i].m_cSuit << pokeIn[i].m_nVal << " ";
		if (pokeIn[i].m_cSuit != pokeStable[i].m_cSuit)
		{
			bStable = false;
		}
	}
	cout << pokeIn[nNum - 1].m_cSuit << pokeIn[nNum - 1].m_nVal << endl;
	if (pokeIn[nNum - 1].m_cSuit != pokeStable[nNum - 1].m_cSuit)
	{
		bStable = false;
	}
	if (bStable)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
}

int main()
{
	cPoke pokeIn[36], pokeSelect[36], pokeStable[36];
	int nNum = 0;
	cin >> nNum;
	for (int i = 0; i < nNum; ++i)
	{
		cin >> pokeIn[i].m_cSuit >> pokeIn[i].m_nVal;
		pokeStable[i].m_cSuit = pokeSelect[i].m_cSuit = pokeIn[i].m_cSuit;
		pokeStable[i].m_nVal = pokeSelect[i].m_nVal = pokeIn[i].m_nVal;
	}
	stable_sort(pokeStable, pokeStable + nNum, compare);
	Bubble(pokeIn, nNum);
	Output(pokeIn, nNum, pokeStable);
	Selection(pokeSelect, nNum);
	Output(pokeSelect, nNum, pokeStable);
	return 0;
}


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

int N;
vector<int> A(103);

int main(){

    cin >> N;
    for (int i=0; i<N; i++){
        cin >> A.at(i);
    }

    vector<double> B(103);
    double sum = 0;
    for (int i=0; i<N; i++){
        B.at(i) = 1.0/A.at(i);
        sum += B.at(i);
    }

    double ans = 0;
    ans = 1.0/sum;

    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a, b;
  int j = 0;
  while(1){
    cin >> a >> b;
    if( !a && !b){
      break;
    }
    if(j != 0) cout << endl;
    int cnt = 0;
    for(int i = a; i <= b; i++){

      if(i%4 == 0){
	if(i%400 == 0){
	  cout << i << endl;
	  cnt++;
	}
	else if(i%100 != 0){
	  cnt++;
	  cout << i << endl;
	}
      }
    }
    if(cnt == 0) cout << "NA" << endl;
    j = 1;




  }

}

Measured memory_bytes: 1160
#include<set>
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main()
{
    for(int n,k;cin>>n>>k,n;){
        int card[10];
        for(int i=0;i<n;i++) cin>>card[i];
        sort(card,card+n);
 
        set<int> st;
        bool mask[10]={};
        for(int i=0;i<k;i++) mask[i]=true;
        do{
            int chos[10];
            for(int i=0,j=0;i<n;i++) if(mask[i]) chos[j++]=card[i];
            do{
                int res=0;
                for(int i=0;i<k;i++){
                    if(chos[i]<10)   res=res*10+chos[i];
                    else            res=res*100+chos[i];
                }
                st.insert(res);
            }while(next_permutation(chos,chos+k));
        }while(prev_permutation(mask,mask+n));
 
        cout<<st.size()<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"YES"<<'\n';
}

void no(){
    cout<<"NO"<<'\n';
}

void solve(){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y<<'\n';
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


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

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    ll N;
    cin >> N ;

    vector< vector<ll> > v(N);
    for(int i = 0; i < N; i++){
        v[i].resize(3);
        for(int j = 0; j < 3; j++){
            cin >> v[i][j];    
        }
    }

    vector< vector<ll> > dp(N);
    for(int i = 0; i < N; i++){
        dp[i].resize(3);
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];

    for(int i = 1; i < N; i++){
        ll costs[3][3] ;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                costs[j][k] = 0;
            }
        }
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j != k) costs[j][k] = dp[i-1][j] + v[i][k];
            }
        }
        // costs[j][k]: // i-1日目に j を選んでi日目に k

        for(int j = 0; j < 3; j++){
            ll maxc = 0;
            for(int k = 0; k < 3; k++){
                maxc = max(maxc, costs[k][j] );
            }
            dp[i][j] = maxc;
        }

    }

    ll maxc = 0;
    for(int i = 0; i < 3; i++){
        maxc = max(maxc, dp[N-1][i]);
    }
    cout << maxc << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <queue>

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

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int n, res, t;

int main() {
  while(cin >> n, n) {
    bool flag = false;
    res = 1;
    rep(i, n) {
      cin >> t;
      if(t >= 2) flag = true;
      if(t >= 1) res++;
    }

    if (flag) cout << res << endl;
    else cout << "NA" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
// finish date: 2018/07/23
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi a(N);
    int mi = INF;
    int ma = -1;
    map<int, int> mp;
    rep(i, N) cin >> a[i], mi = min(mi, a[i]), ma = max(ma, a[i]), mp[a[i]]++;
    int miCnt = mp[mi];
    int maCnt = mp[ma];
    if (ma - mi > 1) {
        cout << "No" << endl;
    } else if (maCnt == 1) {
        cout << "No" << endl;
    } else if (ma == mi) {
        if (ma == N - 1 || (1 <= ma && ma <= N / 2)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (1 <= mi - miCnt + 1 && mi - miCnt + 1 <= maCnt / 2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 5376
s = str(input())
s2 = s.replace("A", "a", 1)
s2 = s2.replace("C", "c", 1)
if s[0] != "A" or s.count("C", 2, -1) != 1 or not s2.islower():
    print("WA")
else:
    print("AC")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int N, A, B;
string s;
int main() {
	cin >> A >> B >> s;
	for (int i = 0; i < A; ++i) {
		if (!('0' <= s[i] && s[i] <= '9')){
			cout << "No" << endl;
			return 0;
		}
	}
	if (s[A] != '-') {
		cout << "No" << endl;
		return 0;
	}
	for(int i = A + 1; i <=A+B; ++i) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int data[5][4][11] = {};
	int n, b, f, r, v, i, l, j, k;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		data[b][f][r] = v + data[b][f][r];
		if (data[b][f][r]>9){
			data[b][f][r] = 9;
		}


	}
	for (i = 1; i < 5; i++){
		for (l = 1; l < 4; l++){
			for (j = 1; j < 11; j++){
				cout <<" "<< data[i][l][j];
			}
			cout << endl;
		}
		if (i == 1 || i == 2 || i == 3){ cout << "####################" << endl; }
	}

	return 0;

}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const double esp=1e-6;

ll a[N];
ll n,k;

ll count(ll x){
	ll res=0;
	for(ll i=0;i<n;i++)
		res+=ceil(1.0*a[i]/x)-1;
	return res;
}
void work(){
	
	ll ma=0;
	cin>>n>>k;
	for(ll i=0;i<n;i++)
		scanf("%lld",&a[i]), ma=max(ma,a[i]);
	ll l=1,r=ma;
	ll ans=r;
	//最好记忆，while是含=
	while(l<=r){
		ll mid=(r+l)/2;
		if(count(mid)<=k) ans=mid, r=mid-1;
		else l=mid+1;
	}
	//ans已经记录

	cout<<ans<<endl;
	return ;
}

int main(){
	//work();
//freopen("C:\\Users\\lenovo\\Desktop\\in.txt","r",stdin);
	work();
	return 0;
}


Measured memory_bytes: 5204
// ITP1_4_A:   A / B Problem
#include <stdio.h>
#include <stdlib.h>

#define PI  3.141592653589793

int main()
{
	double r;

	scanf("%lf", &r);
	printf("%lf %lf\n", PI*r*r, 2*PI*r);
	return 0;
}

Measured memory_bytes: 648
<?php

$n = trim(fgets(STDIN));
$n = str_split($n);

if ($n[0] === '7') {
    echo 'Yes' . PHP_EOL;
    exit;
} else if ($n[1] === '7') {
    echo 'Yes' . PHP_EOL;
    exit;
} else if ($n[2] === '7') {
    echo 'Yes' . PHP_EOL;
    exit;
}
echo 'No' . PHP_EOL;



Measured memory_bytes: 16052
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], n, m, k;

int dp(int n)
{
     if (n == 1)
          return 1;
     int ans = 1 + 2 * dp(n / 2);
     return ans;

}

void solve()
{
     cin >> n;
     cout << dp(n);

}

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

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

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

int main()
{
    int a[3],i,c=0,c1=0;
    for(i=0;i<3;i++)
    {
        cin>>a[i];
        if(a[i]==5)c++;
        if(a[i]==7)c1++;
    }
    if(c==2 && c1==1)cout<<"YES\n";
    else cout<<"NO\n";
}



Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t N,ans;
    cin >>N;
    for (int i = 1; i <= (int)(sqrt(N+1)-1); i++)if((N-i) % i == 0)ans+=(N-i)/i;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	  //given n times, and R, an array of currencies/rates
	public int compute_maxprofit(int n,int[] R) {
		int max_profit = -999999999;
		int min_price = R[0];
		for(int i = 0; i < n -1; i ++) {
			if(R[i] < min_price) {
				min_price = R[i];
			}
			max_profit = Math.max(max_profit, R[i+1] - min_price);
		}
		return max_profit;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int rSize = in.nextInt();
		int[] R = new int[rSize];
		
		for(int i = 0; i < rSize; i++) {
			R[i] = in.nextInt();
		}
		
		Main test = new Main();
		System.out.println(test.compute_maxprofit(rSize, R));
	}
}



Measured memory_bytes: 101308
n = int(input())
a = list(map(int, input().split()))
flag = 1
c = 0
while flag:
    flag = 0
    for k in range(1, n):
        if a[k]<a[k-1]:
            a[k-1], a[k] = a[k], a[k-1]
            flag = 1
            c += 1
print(*a)
print(c)


Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

int main(){
    int N;
    cin>>N;
    vector<ll>A(N), B(N);
    ll asum = 0;
    ll bsum = 0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        asum += A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
        bsum += B[i];
    }
    if(bsum > asum){
        cout << -1 <<endl;
        return 0;
    }
    vector<ll>v(N);
    for(int i=0;i<N;i++){
        v[i] = A[i] - B[i];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    int tmp = 0;
    for(int l = 0, r = N;v[l]<0;l++){
        while(tmp+v[l]<0){
            r--;
            tmp+=v[r];
            ans++;
        }
        tmp+=v[l];
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 1;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

string s1 , s2;

void solve(int cs){
    cin >> s1 >> s2;

    int ans = 0;
    for(int i = 0 ; i < 3 ; i ++)ans += (s1[i] == s2[i]);
    printf("%d\n" , ans);
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    rep(i, D){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1<<D); ++mask){ //bit探索
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask>>i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            } else {
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << 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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll t, x; cin >> t >> x;
    cout << 1.0*t/x << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;

struct Unionfind{
  vector<int> rank,p;
  Unionfind(){}
  Unionfind(int size){
		rank.resize(size,0);
		p.resize(size,0);
		for(int i=0;i<size;i++){
	    makeSet(i);
		}
	}
  void makeSet(int x){
		p[x]=x;
		rank[x]=0;
	}
  bool same(int x,int y){
		return (findSet(x)==findSet(y));
  }

  void unite(int x,int y){
		link(findSet(x),findSet(y));
  }

  void link(int x,int y){
		if(rank[x]>rank[y]){
	    p[y]=x;
		}
		else{
	    p[x]=y;
	    if(rank[x]==rank[y]){
				rank[y]++;
	    }
		}
  }

  int findSet(int x){
		if(x!=p[x]){
	    p[x]=findSet(p[x]);
		}
		return p[x];
  }
};

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vint p(n+1);
  REP(i,1,n+1){
    cin>>p[i];
  }

  Unionfind uf(n+1);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    uf.unite(x,y);
  }
  int count=0;
  REP(i,1,n+1){
    if(uf.same(i,p[i])){
      count++;
    }
  }

  cout<<count<<'\n';
  return(0);
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
ll n,k,s;
  cin>>n>>k>>s;
  
  ll ar[n+1];
  ar[1]=s;
  for(int i=2;i<=k;i++){
  ar[i]=s;
}
  for(int i=k+1;i<=n;i++){
    if(s>=100001){
      ar[i]=1;}
    if(s<=9999){
    ar[i]=10000;}
    if(s>=10000&&s<=100000){
      ar[i]=s-1;}
  }
    
    
  
  for(int i=1;i<=n-1;i++){
    cout<<ar[i]<<" ";}
  cout<<ar[n]<<endl;
  return 0;
  
}
  

Measured memory_bytes: 2048
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath> 
using namespace std; 
int main()
{

	int n, l; 
	cin >> n >> l;
	vector<string> a(n); 
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	} 
	sort(a.begin(), a.end());  
	string ans = "";
	for (int i = 0; i < n; i++)
	{
		ans += a.at(i);
	} 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  	int x;
  	cin>>x;
  	
  	int answer = 1;
	int angle = x;
  	while(angle%360){
      	angle %= 360;
      	angle += x;
      	answer++;
    }
  	
  	cout<<answer;
  	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int a[5418888];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)//排序
    {
        for(int j=i;j<=n;j++)
        {
            if(a[j]>a[i])//判断是否交换
            {
                int tmp;
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    int m=0;//定义m,记录k大的数的总和
    for(int i=1;i<=k;i++)
        m+=a[i];
    cout<<m<<endl;//输出
    return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <sstream>
#include <deque>
#define ll long long
using namespace std;
const int maxn=6;
const ll mod=1000000007;
char s[maxn];


int main(){
	int out=0;
	cin>>s;
	for(int i=0;i<6;i++){
		if(s[i]=='1'){
			out++;
		}


	}

	cout<<out;
	return 0;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int main() {
  int N, M, C; cin >> N >> M >> C;
  vector<int> b(M);
  rep(i, M) cin >> b[i];

  vector<vector<int>> a(N, vector<int>(M));
  rep(i, N) rep(j, M) cin >> a[i][j];
  int sum = 0;
  vector<int> s(N);
  rep(i, N) { 
    rep(j, M) {
       sum += a[i][j]*b[j];
      if(j==M-1) {s[i] = sum; sum = 0;} 
    }
  }
  int count = 0;
  rep(i, N) {if(s[i]+C>0) count++;}
  cout << count << endl;
}

Measured memory_bytes: 256
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  vi32 x(n);
  map<int, int> y;
  rep(i, n) {
    x[i] = i + a[i];
    y[i - a[i]] += 1;
  }
  i64 ans = 0;
  rep(i, n) {
    y[i - a[i]] -= 1;
    ans += (i64) y[x[i]];
  }
  cout << ans << endl;
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
//
const int mod = 1e9 + 7;
const int MX = 3002;
int dp[22][(1<<21)+1337]; // 1 - win, 0 - lose
int32_t main()
{
    
    int n;
    cin >> n;
    vector<vector<int>>g(n,vector<int>(n));
    forn(i,n){
        forn(j,n){
            cin >> g[i][j];
        }
    }
    dp[0][0]=1;
    forn(i,n){
        forn(j,(1 << n)){
            if (dp[i][j] == 0) {
                continue;
            }
            forn (k, n) {
                if (g[i][k] && (j & (1 << k)) == 0) {
                    dp[i + 1][j | (1 << k)] += dp[i][j];
                    dp[i + 1][j | (1 << k)] %= mod;
                }
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
    return 0;
}

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

int main()
{
  int a;
  int b;
  cin >> a >> b;
  
  if( a > b && b != 1 )
  {
    cout << "Alice" << endl;
  }
  else if ( a > b && b == 1 )
  {
    cout << "Bob" << endl;
  }
  else if ( a < b && a != 1 )
  {
    cout << "Bob" << endl;
  }
  else if ( a < b && a == 1 )
  {
    cout << "Alice" << endl;
  }
  else
  {
    cout << "Draw" << endl;
  }
  return 0;
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200? s : "red") << endl;

    return 0;
}



Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-15 23:00:12
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int x = 1 - L;
    if (x <= N && x >= 1) {
        ;
    } else if (x > N) {
        x = N;
    } else {
        x = 1;
    }

    int ans = ( (L+N)*(L+N-1) - L*(L-1) - 2*(L+x-1) ) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  S = readint()[1]
  MOD = 10^9+7

  maxkou = S÷3

  if S <= 2
    println(0)
    return
  end

  s = 1
  v = ones(int,S)
  v[1] = 0
  v[2] = 0
  v1 = zeros(int,S)

  for i in 2:maxkou
    v1 = zeros(int,S)
    for j in 3i:S
      v1[j] = mod(v1[j-1]+v[j-3],MOD)
      #for k in 3:j-1
      #  v1[j] = mod(v1[j]+v[j-k],MOD)
      #end   
      #println(i," ",j," ",v1[j])
    end
   

    s = mod(s+v1[S],MOD)
    v = copy(v1)
  end
  println(s)

end

main()


Measured memory_bytes: 210128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
  ll n, max, min, sum = 0;
  cin >> n;
  vector<ll> a(n);
  REP(i, n)  {
    cin >> a.at(i);
    sum += a.at(i);
  }
  cout << MIN(a) << ' ';
  cout << MAX(a) << ' ';
  cout << sum << endl;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
using Graph = vector<vector<int>>;
Graph G;
  
/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;

    rep(i, n){
        auto it_a = lower_bound(a.begin(), a.end(), b[i]);
        auto it_c = upper_bound(c.begin(), c.end(), b[i]);
        int index_a = it_a - a.begin();
        int index_c = it_c - c.begin();
        //cout << index_a << " " << index_c << endl;
        ans += index_a * (n - index_c);
        
    }
    cout << ans << endl;
} 

Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


int main() {
	int n,q,j,k;
	cin >> n>>q;
	vector<pair<int,int>>b(n-1);
	vector<int>t(n,0);
	for (int a = 0; a < n-1; a++) 
	{
		cin >> b[a].first >> b[a].second;
		b[a].first--; b[a].second--;
	}
	for (int a = 0; a < q; a++)
	{ cin >> j >> k; t[j-1] += k; }
	std::sort(b.begin(), b.end());
	for (int a = 0; a < n-1; a++)
	{ t[b[a].second] += t[b[a].first]; }
	for (int a = 0; a < n; a++)
	{ cout << t[a] << ' '; }
	return 0;
}

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

int h,w;

int id(int i,int j){
    return i*w+j;
}

int main(){
    cin >> h >> w;
    vector<string> s(h); rep(i,h) cin >> s[i];
    int d[h*w][h*w]; rep(i,h*w) rep(j,h*w) d[i][j] = 100000;

    if(h == 1){
        cout << w-1 << endl;
        return 0;
    }else if(w == 1){
        cout << h-1 << endl;
        return 0;
    }else{
        int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
        rep(i,h) rep(j,w){
            if(s[i][j] == '#') continue;
            rep(k,4){
                int ny = i + dy[k], nx = j + dx[k];
                if(ny < 0 || nx < 0 || nx >= w || ny >= h) continue;
                d[id(i,j)][id(ny,nx)] = 1;
            }
        }
    }

    // warshal-floyd
    rep(i,h*w) rep(j,h*w) rep(k,h*w) d[j][k] = min(d[j][i] + d[i][k], d[j][k]);

    // calc
    int ans = -1;
    rep(i,h*w) rep(j,h*w){
        if(s[i/w][i%w] == '.' && s[j/w][j%w] == '.') ans = max(ans, d[i][j]);
    }

    // output
    cout << ans << endl;
}

Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n,k;
        n = scanner.nextInt();
        k = scanner.nextInt();
        List<Boolean> snuke = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            snuke.add(false);
        }
        int di,aii;
        for (int i = 0; i < k; i++) {
            di = scanner.nextInt();
            scanner.nextLine();
            for (int j = 0; j < di; j++) {
                aii = scanner.nextInt();
                snuke.set(aii-1,true);
            }
            scanner.nextLine();
        }
        int ret = 0;
        for (Boolean aBoolean : snuke) {
            if (!aBoolean) ret++;
        }
        System.out.println(ret);
    }
}

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

int main() {
  int N;
  string s;
  cin >> N >> s;
  int i=0;
  for(int k=0; k<N; ++k){
    if(s[k]=='R')
      ++i;
    else
      --i;
  }
  if(i>0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    int n,l;
    cin>>n>>l;
    vector<string>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    for(auto x:v)cout<<x;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main()
{
    int a,b;

    while(cin>>a>>b&&!(a==0&&b==0))
    {
        for(int i=0;i<a;i++)
        {
            for(int j=0;j<b;j++)
            {
                if((i+j)%2==0)
                {
                    cout<<'#';
                }else
                {
                    cout<<'.';
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }


    return 0;
}



Measured memory_bytes: 3108
/**
*    author:  Dooloper
*    created: 25.07.2020 20:56:35
**/

#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  if(n>= 400 && n <= 599){
    cout << "8" << endl;
  }
  if(n>= 600 && n <= 799){
    cout << "7" << endl;
  }
  if(n>= 800 && n <= 999){
    cout << "6" << endl;
  }
  if(n>= 1000 && n <= 1199){
    cout << "5" << endl;
  }
  if(n>= 1200 && n <= 1399){
    cout << "4" << endl;
  }
  if(n>= 1400 && n <= 1599){
    cout << "3" << endl;
  }
  if(n>= 1600 && n <= 1799){
    cout << "2" << endl;
  }
  if(n>= 1800 && n <= 1999){
    cout << "1" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
f = input().strip().split()
q = []
for e in f:
    if e == '+':
        q.append(q.pop() + q.pop())
    elif e == '-':
        q.append(-q.pop() + q.pop())
    elif e == '*':
        q.append(q.pop() * q.pop())
    else:
        q.append(int(e))
print(q[0])



Measured memory_bytes: 5600
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <initializer_list>

using namespace std;

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve(){
    vector<char> s;
    string hoge;
    cin >> hoge;
    for(int i=0;i<hoge.length();i++){
        if(hoge[i] == 'B'){
            if(!s.empty()) s.pop_back();
        }else{
            s.push_back(hoge[i]);
        }
    }
    for(int i=0;i<s.size();i++){
        cout << s[i];
    }
}
signed main() {
    solve();
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int r;
  cin >> r;
  cout << (r * r);
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1005
#define INF (1<<26)
 
int N,M,S,T;
int G[MAX_N][MAX_N];
int g[MAX_N][MAX_N];
int base;
int visited[MAX_N];
 
int AS[MAX_N],AT[MAX_N];
 
bool check(int a,int b){
  if(AT[a]&&AS[b])return true;
  else return false;
}
 
void dfsS(int pos){
  AS[pos]=true;
  for(int i=0;i<N;i++){
    if(G[pos][i]==0)continue;
    if(AS[i])continue;
    dfsS(i);
  }
}
 
void dfsT(int pos){
  AT[pos]=true;
  for(int i=0;i<N;i++){
    if(G[i][pos]==0)continue;
    if(AT[i])continue;
    dfsT(i);
  }
}
 
void solve(){
  /*
  
  cout<<endl;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout<<g[i][j]<<' ';
    }
    cout<<endl;
  }
  cout<<endl;

  cout<<endl;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout<<G[i][j]<<' ';
    }
    cout<<endl;
  }
  cout<<endl;
  */
  
  for(int i=0;i<N;i++)
    AS[i]=AT[i]=false;
   
  dfsS(S);
  dfsT(T);
 
  /*
  for(int i=0;i<N;i++){
    cout<<AS[i]<<' ';
  }
  cout<<endl;
 
  for(int i=0;i<N;i++){
    cout<<AT[i]<<' ';
  }
  cout<<endl;
  */
 
  int cnt=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j)continue;
      if(g[i][j]==0)continue;
      if(G[i][j]==0)continue;
      int dist=g[j][i]-G[j][i];
      if(dist<0)continue;
      
      if(check(i,j)){
        cnt+=(G[i][j]-dist);
      }

    }
  }
 
  if(base==0&&cnt==0)cout<<"0 0"<<endl;
  else if(cnt==0)cout<<base<<" 0"<<endl;
  else cout<<base+1<<" "<<cnt<<endl;
}
 
int dfs(int pos,int f){
  if(pos==T)return f;
  visited[pos]=true;
  for(int i=0;i<N;i++){
    if(visited[i])continue;
    if(G[pos][i]==0)continue;
    int d=dfs(i,min(f,G[pos][i]));
    if(d>0){
      G[pos][i]-=d;
      G[i][pos]+=d;
      return d;
    }
  }
  return 0;
}
 
void calc(){
  base=0;
  while(1){
    for(int i=0;i<N;i++)visited[i]=false;
    int f=dfs(S,INF);
    if(f==0)break;
    base+=f;
  }
}
 
void init(){
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      G[i][j]=0;
}
 
int main(){
  int a,b;
  while(1){
    scanf("%d %d %d %d",&N,&M,&S,&T);
    if(N==0&&M==0&&S==0&&T==0)break;
    S--,T--;
    init();
    for(int i=0;i<M;i++){
      scanf("%d %d",&a,&b);
      a--,b--;
      G[a][b]++;
    }
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        g[i][j]=G[i][j];
    calc();
    solve();
  }
  return 0;
}

Measured memory_bytes: 9136
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	
		String s = sc.next();

      // スペース区切りの整数の入力
		int length=s.length();
		// 出力
		//System.out.println(s.charAt(0)+length-2+s.charAt(length-1));
	System.out.print(s.charAt(0));
      System.out.print(length-2);
      System.out.print(s.charAt(length-1));
      }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,i,j;
        cin >> n;
        int p[n+1],q[n+1],a[n+1];
        for(i=1; i<=n; i++) cin >> p[i];
        for(i=1; i<=n; i++) cin >> q[i];
        //vector<int>a;
        for(i=1; i<=n; i++){
            a[i]=i;
        }
        int z=0;
        int ans1,ans2;
    do { 
        int r=0,f=0;
        for(i=1; i<=n; i++){
            if(p[i] == a[i]){
                r++;
            }
            
        }
        if(r==n){
                ans1=z;
            }
        for(i=1; i<=n; i++){
            if(q[i]==a[i]){
                f++;
            }
            
        }
        if(f==n){
                ans2=z;
            }

        z++;
    } while (next_permutation(a+1, a + n+1)); 


        cout << abs(ans1-ans2) << '\n';

}

Measured memory_bytes: 256
def search(x, y, imap, acc):
  imap[x][y] = 0
  acc += 1
  ret = acc
  a = b = c = d = 0
  if imap[x - 1][y]:
    a = search(x - 1, y, imap, acc)
    if ret < a:
      ret = a
  if imap[x + 1][y]:
    b = search(x + 1, y, imap, acc)
    if ret < b:
      ret = b
  if imap[x][y - 1]:
    c = search(x, y - 1, imap, acc)
    if ret < c:
      ret = c
  if imap[x][y + 1]:
    d = search(x, y + 1, imap, acc)
    if ret < d:
      ret = d
  imap[x][y] = 1
  return ret
 

def solve():
  while True:
    m, n  = int(input()), int(input())
    if not m:
      break
    ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)]
    ices.insert(0, [0] * (m + 2),)
    ices.append([0] * (m + 2))
    score = [[0] * (m + 2) for _ in range(n + 2)]
    
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if ices[x][y]:
          score[x - 1][y] += 1
          score[x + 1][y] += 1
          score[x][y - 1] += 1
          score[x][y + 1] += 1
   
    ans = 0
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if score[x][y] in [1, 2] and ices[x][y]:
          a = search(x, y, ices, 0)
          if ans < a:
            ans = a
    
    print(ans)

solve()


Measured memory_bytes: 5816
# -*- coding: utf-8 -*-


def main():
    n, a, b = map(int, input().split())
    x = list(map(int, input().split()))
    ans = 0

    for i in range(n - 1):
        ans += min((x[i + 1] - x[i]) * a, b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15020
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string s[100001];
	vector< vector<char> > V;
	scan(N);
	rep(i,N){
		vector<char> v;
		rep(j,10){
			char c;
			scan(c);
			v.push_back(c);
		}
		sort(v.begin(),v.end());
		V.push_back(v);
	}
	sort(V.begin(),V.end());
	ll A=0;
	ll ans=0;
	rep(i,N-1){
		if(V[i]==V[i+1]) A++;
		else{
			ans+=A*(A+1)/2;
			A=0;
		}
	}
	ans+=A*(A+1)/2;
	prin(ans);
	return 0;
}


Measured memory_bytes: 8756