akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

int n,m,nx,ny,rst[100010];
vector<vector<int>> vc(100010);

ll vin(int qua){
    
    if(rst[qua]!=-1)return rst[qua];
    
    if(vc[qua].size()){
        ll mx=0;
        for(auto it:vc[qua]){
            mx=max(mx,vin(it)+1);
        }
        rst[qua]=mx;
        return mx;
    }
    else{
        rst[qua]=0;
        return 0;
    }
    
}


int main(){
    cin>>n>>m;
    for(int i=0;i<100010;i++)rst[i]=-1;
    
    for(int i=0;i<m;i++){
        cin>>nx>>ny;
        vc[nx].push_back(ny);
        //ft[nx][ny]=true;
    }
    ll ma=0;
    for(int i=1;i<=n;i++){
        ma=max(ma,vin(i));
    }
    C ma E;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long long LL;

const int N = 1e5 + 5;
int a[55], b[55], c[55];

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

  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n - 1; i++) cin >> c[i];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += b[a[i]];
    if (i <= n - 1) {
      if (a[i] == a[i+1] - 1) {
        ans += c[a[i]];
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}


int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    int s,d,t;
    cin>>d>>t>>s;
    if(s*t>=d)
        cout<<"Yes";
    else
        cout<<"No";
    
}


Measured memory_bytes: 3104
#include <map>
#include <cstdio>
using namespace std;
map <int ,map <int ,int > > ma;
long long ans[12];
int dx[12]={0,0,1,0,-1,1,1,-1,-1},
	dy[12]={0,1,0,-1,0,1,-1,1,-1};
int main (){
	int n,m,k;scanf ("%d%d%d",&n,&m,&k);
	ans[0]=1ll*(n-2)*(m-2);
	while (k--){
		int x,y;scanf ("%d%d",&x,&y);
		for (int i=0;i<=8;i++){
			int tx=x+dx[i],ty=y+dy[i];
			if (tx<n&&ty<m&&tx>1&&ty>1){
				ans[ma[tx][ty]]--,ans[++ma[tx][ty]]++;
			}
		}
	}
	for (int i=0;i<=9;i++) printf ("%lld\n",ans[i]);
	return 0;
}


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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
  	int count = 0;
    if (a == b) count++;
    if (a == c) count++;
    if (c == b) count++;
    if (count == 1){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if (n % 10 == 2)
            ans++;
        n /= 10;
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  char a, b;
  cin >> a >> b;
  
  if ( a =='H' && b == 'H') cout << 'H';
  if ( a == 'D' && b == 'H')cout <<'D';
  if ( a == 'H' && b == 'D')cout <<'D';
  if ( a == 'D' && b == 'D')cout <<'H';
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 2202020
#define mme(i,j) memset(i,j,sizeof(i))
#define ll long long
#define pb push_back
using namespace std;

int main()
{
    int x;
    while(~scanf("%d",&x))
    {
        ll sum=0;
        for(int i=1;i<=x;i++){
            sum+=i;
            if(sum>=x){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n;
	vector<int> a;

	cin >> n;
	a.resize(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	vector<int> sol(n);

	if (n % 2 == 0)
	{
		int k = n / 2;
		int j = 0;

		for(int i = k; i < n; i++)
		{
			sol[i] = a[j];
			j += 2;
		}

		j = 1;
		for(int i = k-1; i >= 0; i--)
		{
			sol[i] = a[j];
			j += 2;
		}

	}else
	{
		int k = n / 2;
		int j = 1;

		for(int i = k+1; i < n; i++)
		{
			sol[i] = a[j];
			j += 2;
		}

		j = 0;
		for(int i = k; i >= 0; i--)
		{
			sol[i] = a[j];
			j += 2;
		}
	}


	for(int i = 0; i < n; i++)
	{
		cout << sol[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;

int main()
{
	int i, j;
	ll a, b, c, d;
	scanf("%lld%lld%lld", &a, &b, &c);
	d = c - a - b;
	if (d <= 0) {
		printf("No");
		return 0;
	}
	d *= d;
	if (4LL * a*b < d) {
		printf("Yes");
	}
	else printf("No");
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int c = 0;
    int n; cin >> n;
    vll a(n);
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) {
        rep(j,i + 1,n) {
            rep(k, j + 1, n) {
                ll x = a[i];
                ll y = a[j];
                ll z = a[k];
                if(x == y || x == z || z == y) continue;
                vll xz = {x,y,z};
                sort(all(xz));
                if(xz[0] + xz[1] > xz[2]) c++;
            }
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3632
import math

# 下記のように入力する場合のコード
# 5
# 2 5 9 6 5

city_road = list(map(int, input().split())) #cityの数、roadの数の配列
arr = [0]*city_road[1]
for i in range(city_road[1]):
    arr[i] = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる

count = [0]*city_road[0]
for j in range(city_road[0]):
    for i in range(city_road[1]):
        if j+1 in arr[i]:
            count[j] += 1

for i in range(city_road[0]):
    print(count[i])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long int ll;
const ll INF = 100100100100100100;
using namespace std;

ll N;
ll a[200200];
ll rui[200200];
int main(){
    cin >> N;
    rep(i,N){
        cin >> a[i];
    }
    rep(i,N){
        rui[i+1] = rui[i] + a[i];
    }
    sort(rui,rui+N+1);
    ll tmp = INF;
    ll ans = 0;
    ll cnt = 0;
    rep(i,N+1){
        if(tmp != rui[i]){
            ans += cnt*(cnt-1)/2;
            cnt = 1;
            tmp = rui[i];
        }
        else{
            cnt++;
        }
    }
    ans += cnt*(cnt-1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e6;
const long long N = 1e3 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

ll T = 1, n, m, b, ans, y, x, c, a[N][N], used[INF], u[INF], cnt, mn = 1e18;
string s;
vector < ll > v, v1;
set< char > st;
int main(){
    TIME
    for ( int i=0; i<3; i++ ){
        for ( int j=0; j<3; j++ ){
            cin >> a[i][j];
            used[ a[i][j] ] = 1;
        }
    }
    cin >> n;
    for ( int i=0; i<n; i++ ){
        cin >> x;
        u[x] = 1;
    }
    if ( used[ a[0][0] ] == u[a[0][0] ] and used[ a[1][1] ] == u[a[1][1] ] and used[ a[2][2] ] == u[a[2][2] ] )
        return cout << "Yes", 0;
    if ( used[ a[0][2] ] == u[a[0][2] ] and used[ a[1][1] ] == u[a[1][1] ] and used[ a[2][0] ] == u[a[2][0] ] )
        return cout << "Yes", 0;
    if ( used[ a[1][0] ] == u[a[1][0] ] and used[ a[1][1] ] == u[a[1][1] ] and used[ a[1][2] ] == u[a[1][2] ] )
        return cout << "Yes", 0;
    if ( used[ a[0][1] ] == u[a[0][1] ] and used[ a[1][1] ] == u[a[1][1] ] and used[ a[2][1] ] == u[a[2][1] ] )
        return cout << "Yes", 0;
    if ( used[ a[0][0] ] == u[a[0][0] ] and used[ a[1][0] ] == u[a[1][0] ] and used[ a[2][0] ] == u[a[2][0] ] )
        return cout << "Yes", 0;
    if ( used[ a[0][2] ] == u[a[0][2] ] and used[ a[1][2] ] == u[a[1][2] ] and used[ a[2][2] ] == u[a[2][2] ] )
        return cout << "Yes", 0;
    if ( used[ a[0][0] ] == u[a[0][0] ] and used[ a[0][1] ] == u[a[0][1] ] and used[ a[0][2] ] == u[a[0][2] ] )
        return cout << "Yes", 0;
    if ( used[ a[2][0] ] == u[a[2][0] ] and used[ a[2][1] ] == u[a[2][1] ] and used[ a[2][2] ] == u[a[2][2] ] )
        return cout << "Yes", 0;
    return cout << "No", 0;

}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

map<vector<int>, int> memo;
queue<vector<int>> que;
const int vec[4] = { -1,1,4,-4 };

vector<int> makev(vector<int> tv) {
	vector<int> ans(8);
	for (int i = 0; i < 8; i++)ans[i] = tv[i];
	return ans;
}

int main() {
	memo[{0, 1, 2, 3, 4, 5, 6, 7}] = 0;
	que.push({ 0,1,2,3,4,5,6,7,0 });
	while (que.size()) {
		vector<int> tv = que.front();
		que.pop();
		int zeropos;
		for (int i = 0; i < 8; i++)if (tv[i] == 0)zeropos = i;
		for (int i = 0; i < 4; i++) {
			if (i < 2) {//??????
				if (zeropos + vec[i] < 0 || zeropos + vec[i] > 7)continue;
				if ((zeropos == 3 && zeropos + vec[i] == 4) || (zeropos == 4 && zeropos + vec[i] == 3))continue;
				vector<int> tmpv = tv;
				tmpv[8]++;
				swap(tmpv[zeropos], tmpv[zeropos + vec[i]]);
				if (memo.count(makev(tmpv)) == 0) {
					memo[makev(tmpv)] = tmpv[8], que.push(tmpv);
				}
			}
			else {//??????
				if (zeropos + vec[i] < 0 || zeropos + vec[i] > 7)continue;
				vector<int> tmpv = tv;
				tmpv[8]++;
				swap(tmpv[zeropos], tmpv[zeropos + vec[i]]);
				if (memo.count(makev(tmpv)) == 0) {
					memo[makev(tmpv)] = tmpv[8], que.push(tmpv);
				}
			}
		}
	}
	vector<int> input(8);
	while (cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4] >> input[5] >> input[6] >> input[7]) {
		cout << memo[input] << endl;
	}
	return 0;
}

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

int main() {
	int n, s[1000], i;
	double a,m;
	while (cin >> n, n){
		m = 0;
		for (i = 0; i<n; i++){
			cin >> s[i];
			m += s[i];
		}
		m /= n;
		a = 0;
		for (i = 0; i<n; i++){
			a += pow(s[i] - m, 2);
		}
		a /= n;
		printf("%.8f\n", sqrt(a));

	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

// https://atcoder.jp/contests/abc058/tasks/arc071_a
void solve() {
    int n;
    cin >> n;
    map<char,int> mp;
    REP(i,n) {
        string s;
        cin >> s;
        if (i==0) {
            REP(j,s.size()) {
                if(mp.count(s[j])==0) mp[s[j]]=0;
                mp[s[j]]++;
            }
        } else {
            map<char,int> smp;
            REP(j,s.size()) {
                if(smp.count(s[j])==0) smp[s[j]]=0;
                smp[s[j]]++;
            }
            // merge
            for(const auto &it: mp) {
                if(smp.count(it.first) == 0) mp[it.first]=0;
                else chmin(mp[it.first],smp[it.first]);
            }
        }

    }
    for(const auto &it:mp) {
        REP(_,it.second) {
            cout << it.first;
        }
    }
    cout << endl;
}

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


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

// using namespace std;



// const int N = 100000, MAXI = 10000;

// int getRandom(int l, int r) {
//     return l + rand() % (r - l + 1);
// }



// // Driver code to test above functions
// int main() 
// {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
   
//     srand(time(nullptr));
   
//     int tc = 30;
//     cout << tc << "\n";
//     //int n = 2;
//     while (tc--)
//     {
//         int n = getRandom(99900, 100000);
//         cout << n << "\n";
//         int a[n+1];
//         for(int i=1;i<=n;i++)
//         {
//             if(i==1)
//                 a[1] = getRandom(2, n);
//             else if(i==n)
//                 a[n] = getRandom(1, n-1);
//             else
//             {
//                 int x = getRandom(1, i-1);
//                 int y = getRandom(i+1, n);

//                 int flag = rand()%2;

//                 if(flag==0)
//                     x = y;

//                 a[i] = x;
//             }
//             cout << a[i] << " ";
//         }
//         cout << "\n~\n";
//     }

//     return 0;
// }








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


 

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



// int main()
// {
//     freopen("input.txt","r", stdin);
//     freopen("output.txt","w", stdout);

//     ios_base::sync_with_stdio(0);
//     cin.tie(NULL);
//     cout.tie(NULL);

//     int t;
//     cin >> t;
//     while(t--)
//     {
        
//     }
   
//     return 0;
// }














//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 

// Driver code to test above functions
int32_t main()
{
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    
    
    char ch;
    cin >> ch;

    if(0 <= (int)(ch - 'a') and 'z' >= ch)
        cout << 'a';
    else
        cout << 'A';
    
    return 0; 
}



Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length(),flag=0;
    string s2="keyence";
    for(int i=0;i<l;i++)
    {
        for(int j=0;j<l;j++)
        {
            string s3="";
            for(int k=0;k<i;k++)
            s3+=s[k];
            for(int k=j;k<l;k++)
            s3+=s[k];
            if(s3==s2)
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = sum(A) // N
    ans = 10**10
    for x in range(c, c + 2):
        val = 0
        for a in A: val += (x - a) ** 2
        ans = min(ans, val)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61980
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

bool check(ll x, ll y) {
    if (x >= (inf_l/y)+1) return false;
    else return true;
}

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i,n) {
        ll x; cin >> x;
        a[i] = x;
        if (x == 0) {cout << 0 << endl; return 0;}
    }
    ll sum = a[0];
    REP(i,n) {
        if (sum >= inf_l/a[i]+1) {cout << -1 << endl; return 0;}
        else sum *= a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4052
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j, k, l, m, n;
	long int a, b;
	long int work, r, x;
	
	scanf("%ld%ld", &a, &b);
	
	if(a < b) {
		work = a;
		a = b;
		b = work;
	}
	
	r = a % b;
	x = a * b;
	
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	
	printf("%ld\n", x / b);
	
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
using LL=__int128;
template<class T> 
T extgcd(T a,T b,T &x,T &y){
    if(b==0){
        x=1;y=0;
        return a;
    }
    T d=extgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
template<class T> 
pair<T,T> ChineseRem(T b1,T m1,T b2,T m2){
    T p,q;
    T d=extgcd<T>(m1,m2,p,q);
    if((b2-b1)%d!=0){
        return make_pair(0,-1);
    }
    T m=m1*(m2/d);
    T tmp=(b2-b1)/d*p%(m2/d);
    T r=((b1+m1*tmp)%m+m)%m;
    return make_pair(r,m);
}
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end());
	return(ret);
}
int main(){
    ll n;
    cin>>n;
    n*=2;
    V<ll> d=divisor(n);
    LL ans=inf;
    for(ll v:d){
        pair<LL,LL> p=ChineseRem<LL>(0,v,n/v-1,n/v);
        if(p.fi!=0){
            if(ans>p.fi){
                ans=p.fi;
            }
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3752
package main

import (
	"fmt"
)

func main (){
	var n int
	fmt.Scan(&n)

	bs := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		var b int
		fmt.Scan(&b)
		bs[i] = b
	}
	as := make([]int, n)
	// ai= biとbi+1の小さい方
	for i := 0; i < n; i++ {
		if i == 0 {
			as[i] = bs[i]
			continue
		}
		if i == n - 1 {
			as[i] = bs[i-1]
			continue
		}
		if bs[i] > bs[i-1] {
			as[i] = bs[i-1]
		} else {
			as[i] = bs[i]
		}
	}
	fmt.Println(Sum(as...))
}

func Sum(arr ...int) (sum int) {
	for _, x := range arr {
		sum += x
	}
	return
}



Measured memory_bytes: 512
# B - 仲良しうさぎ
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b

n = int(input())
A = list(map(int, input().split()))

ans = 0
for itr, a in enumerate(A):
  if a - 1 > itr and A[a - 1] == itr + 1:
    ans += 1

print(ans)


Measured memory_bytes: 13880
// -*- coding:utf-8-unix -*-

use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [u32; n],
    }
    let mut hm = HashMap::new();
    for i in &a {
        let entry = hm.entry(i).or_insert(0);
        *entry += 1;
    }

    match hm.len() {
        3 => {
            if n % 3 != 0 {
                println!("No");
                return;
            }
            let mut xorsum = 0;
            for (&k, &v) in &hm {
                if v != n / 3 {
                    println!("No");
                    return;
                }
                xorsum ^= k;
            }
            if xorsum == 0x00 {
                println!("Yes");
            } else {
                println!("No");
            }
        },
        2 => {
            if n % 3 != 0 || hm.get(&0) == None {
                println!("No");
                return;
            }
            if hm[&0] != n / 3 {
                println!("No");
                return;
            }
            println!("Yes");
        },
        1 => {
            match a[0] {
                0 => println!("Yes"),
                _ => println!("No"),
            }
        }
        _ => println!("No"),
    }
}


Measured memory_bytes: 6440
L = int(input())

b = bin(L-1)[2:]
l = len(b)
out = []
for i in range(1,l+1):
    out.append([i,i+1,0])
for i in range(2,l+1):
    out.append([i,i+1,1<<(l-i)])

if not "0" in b:
    out.append([1,2,1<<(l-1)])
    b = ""
while len(b)>0 and b != "0":
    if b[-1] == "0":
        out.append([1,len(b)+1,int((b+"0"*l)[:l],2)])
        b = bin(int(b,2)-1)[2:]
    b = b[:-1]

if l < 20:
    print(l+1,len(out))
    for sub in out:
        print(" ".join(map(str,sub)))
else:
    print(l,len(out)-1)
    for u,v,w in out[1:]:
        u = max(1,u-1)
        v = max(1,v-1)
        print(u,v,w)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
 
 
public class Main{
     
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	final int Q = sc.nextInt();
    	
    	for(int i = 0; i < Q; i++){
    		int N = sc.nextInt();
    		int count = 0;
    		
    		while(N >= 10){
    			
    			int len = ((int) Math.log10(N) + 1);
    			
    			int max = -1;
    			
    			for(int j = 1; j < len; j++){
    				int div = (int) Math.pow(10, j);
    				
    				max = Math.max(max, (N / div) * (N % div));
    			}
    			
    			N = max;
    			
    			count++;
    		}
    		
    		System.out.println(count);
    	}
        
    }
     
}

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

int main(){
  int N;
  cin >> N;
  string str;
  cin >> str;
  for(int i=0; i<str.size(); i++){
    if(str[i]+N>'Z'){
      str[i]+=N-26;
    }
    else str[i]+=N;
  }
  cout << str <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
vector<tuple<int,int,int,int>> vec;

int calAns(vector<int>& A){
    int ans = 0;
    for(auto it : vec){
        int a,b,c,d;
        tie(a,b,c,d) = it;
        if(A[b-1]-A[a-1] == c)
            ans += d;
    }
    return ans;
}

int sol(vector<int>& A, int cur, int end, int m){
    if(cur == end){
        return calAns(A);
    }
    int res = 0;
    int s = A.size() ? A[cur-1] : 1;

    for(int i = s; i <= m ; ++i){
        A.push_back(i);
        res = max(res,sol(A,cur+1, end,m));
        A.pop_back();
    }
    return res;
}

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    for(int i = 0,a,b,c,d; i < q ; ++i){
        cin >> a >> b >> c >> d;
        vec.emplace_back(a,b,c,d);
    }
    vector<int> A;
    cout << sol(A,0,n,m);

    return 0;
}

Measured memory_bytes: 3152
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto a = RD;
	auto b = RD;
	auto d = b - a;
	long h;
	foreach (i; 1..d+1)
	{
		h += i;
	}

	writeln(h - b);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e5 + 10;
int n, m;

int deg[maxn];

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    deg[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    deg[s] ^= 1;
    deg[t] ^= 1;
  }
  return 1;
}

void solve() {
  printf(count(deg, deg + n, 0) == n ? "YES\n" : "NO\n");
}

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

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int N, s[3], id;

    scanf("%d", &N);

    while(N-- > 0)
    {
        scanf("%d %d %d", &s[0], &s[1], &s[2]);
        id = s[0] < s[1] ? (s[1] < s[2] ? 2 : 1) : (s[0] < s[2] ? 2 : 0);

        int i, sum = 0;
        for(i = 0; i < 3; ++i)
        {
            if(i != id)
            {
                sum += (s[i] * s[i]);
            }
        }

        printf("%s\n", (sum == (s[id] * s[id]) ? "YES" : "NO"));
    }

    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
 
 
long long gcd(long a, long b){
	if(a%b) return gcd(b,a%b);
	else return b;
}
 
int main(){
long long A,B,S;
int count;
count=1;
cin>>A>>B;
 
  
if(A>B){S = gcd(A,B);}else{S = gcd(B,A);}
 
 for(long long i=2;i*i<=S;i++){
    if(S%i==0){
      count++;
     while(S%i==0) S/=i;
    }
 }
  if(S!=1)count++;
  cout<<count<<endl;
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Author: z0marlin
Title: A.cpp
Time: 24-08-2019T17:29:45+0530 
I suck at CP T_T
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
#include <bits/stdc++.h>
#if DEBUG
#define dprintf(...) printf(__VA_ARGS__)
#else
#define dprintf(...)
#endif
#define FOR(i, a, n) for(int i = a; i < n; ++i)
#define FORE(a, v) for(auto a:v)
#define MAX(a, b) ((a>b)?a:b)
#define MIN(a, b) ((a<b)?a:b)
#define mp(i, j) make_pair(i, j)
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii_t;
typedef pair<ll,ll> pll_t;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
typedef vector<ull> vull_t;

const int MAX_SZ=1e6+2;
const int MOD=1e9+7;
int t = 1, n, m, q, ql, qr;
char ch;

int solve(){
    int cnt=0,d1,d2;
    FOR(i,1,m+1){
        FOR(j,1,n+1){
            d1=j/10;
            d2=j%10;
            if(d1>1&&d2>1&&d1*d2==i) cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

int main(){
    // scanf("%d", &t);
    while(t--){
        scanf("%d%d",&m,&n);
        solve();
    }
}

Measured memory_bytes: 256
#!python3

# input
N = int(input())
S = input()


def main():
    left = {"E": 0, "W": 0}
    right = {"E": S.count("E"), "W": S.count("W")}

    ans = N
    for s in S:
        right[s] -= 1
        ans = min(ans, left["W"] + right["E"])
        left[s] += 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
#include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    int H, W;
    while (cin >> H >> W && (H || W)) {
        vector<string> tiles(H, string(W, ' '));
        for (int i=0; i<H; ++i) {
            for (int j=0; j<W; ++j) {
                cin >> tiles[i][j];
            }
        }

        int x = 0, y = 0;
        int visited[101][101] = {false};
        while ( ! visited[y][x]) {
            visited[y][x] = true;
            switch (tiles[y][x]) {
                case '>':
                    x ++;
                    break;
                case '<':
                    x --;
                    break;
                case 'v':
                    y ++;
                    break;
                case '^':
                    y --;
                    break;
            }
        }
        if (tiles[y][x] == '.') {
            cout << x << " " << y << endl;
        } else {
            cout << "LOOP" << endl;
        }
    }
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll X; cin >> X;
	cout << (X / 500) * 1000 + (X % 500) / 5 * 5 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main(){
  long long a,b,k,i;
  cin >> a >> b >> k;
  long long ansa,ansb;
  ansa=a;
  ansb=b;
  if(a<=k){
    i=k-a;
    ansa=0;
    ansb=b-i;
  }else{
    ansa=a-k;
  }
  if(ansa<0){
    ansa=0;
  }
  if(ansb<0){
    ansb=0;
  }
  cout << ansa << endl;
  cout << ansb << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
count = 0
for i in range(0, n, 2):
    if s[i] == 'R' or  s[i] == 'U' or s[i] == 'D':
        count += 1
for i in range(1, n, 2):
    if s[i] == 'L' or s[i] == 'U' or s[i] == 'D':
        count += 1
if count == n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: Jalpaiguri Govt Enggineering College
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll int
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define endl "\n"
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)
#define level 20
int mod=1000000007;
// int mod=998244353;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int block;
bool test =0;


bool compare(pair <pair <int,int>,int> x, pair <pair <int,int>,int> y) 
{
    int idx1 = x.first.first / block, idx2 = y.first.first / block;
    if (idx1 != idx2) 
        return idx1 < idx2; 
    else if (idx1 & 2)
        return x.first.second >= y.first.second;
    else
        return x.first.second < y.first.second;
}
int n,q,x,y;
void solve()
{

    cin>>n>>q;
    block=sqrt(n);
    if(block*block!=n)
        block++;
    int a[n+5];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    vector<pair<pair<int,int>,int>>v;
    for(int i=0;i<q;i++){
        cin>>x>>y;
        v.pb(mp(mp(x,y),i));
    }
    sort(alt(v),compare);
    vector<int>ans(q+5);
  
    int curl=1, curr=0;
    int L=0,R=0;
    int cnt=0;
    vector<int>m(n+1);
    for(int i=0;i<q;i++)
    {
        L=v[i].ff.ff;
        R=v[i].ff.se;
        int ind=v[i].se;
        while(curr < R)
        {
            curr++;
            if(m[a[curr]]==0) cnt++;
            m[a[curr]]++;
        }
        while(curl > L){
            curl--;
            if(m[a[curl]]==0) cnt++;
            m[a[curl]]++;
        }
        while(curr > R){
            if(m[a[curr]]==1) cnt--;
            m[a[curr]]--;
            curr--;
        }
        while(curl < L){
            if(m[a[curl]]==1) cnt--;
            m[a[curl]]--;
            curl++;
        }
        ans[ind]=cnt;
    }

    for(int i=0;i<q;i++)
        cout<<ans[i]<<"\n";





}






    

















signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 27276
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll n,m,r;
ll rs[8];
struct edge{
    ll to,cost;
};

struct e{
    ll from,to,cost;
};
e es[20010];

ll INF = 200000000000;

ll dist[201][201];
bool used[10];

ll dfs(ll start,bool used[],ll cost){
    
    bool local_used[10];
    memcpy(local_used,used,r);
    
    local_used[start] = true;
    bool flag = true;
    for (int j = 0; j < r; j++){
        flag = flag && local_used[j];
    }
    if(flag){
        return cost;
    }
    
    ll result = INF;
    for (int j = 0; j < r; j++) {
        if(!local_used[j]){
        // std::cout << start<<" "<<j<<" "<< dist[rs[start]][rs[j]] << std::endl;
           result = min(result, dfs(j,local_used,cost + dist[rs[start]][rs[j]]) );
        }
    }
    return result;
}

int main() {
    std::cin >> n>>m>>r;
    for (int i = 0; i < r; i++) {
        std::cin >> rs[i];
    }
    for (int i = 0; i < m; i++) {
        ll a,b,c;
        std::cin >> a>>b>>c;
        es[i]={a,b,c};
    }
    Fill(dist,INF);
    for (int i = 0; i <= n; i++) {
        dist[i][i]=0;
    }
    for (int i = 0; i < r; i++) {
        for (int k = 0; k <= n; k++) {
            for (int j = 0; j < m; j++) {
                dist[es[j].to][rs[i]] = dist[rs[i]][es[j].to] = min(min(dist[rs[i]][es[j].to],dist[es[j].to][rs[i]]),dist[rs[i]][es[j].from]+es[j].cost);
                dist[es[j].from][rs[i]] = dist[rs[i]][es[j].from] = min(min(dist[rs[i]][es[j].from],dist[es[j].from][rs[i]]),dist[rs[i]][es[j].to]+es[j].cost);
            }
        }
    }
    
    ll result = INF;
    for (int i = 0; i < r; i++) {
        result = min(result,dfs(i,used,0));
    }
    std::cout << result << std::endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

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

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, C;
const ll MAX_N  = 100000;
ll x[MAX_N], v[MAX_N];

int main(){
  cin >> N >> C;
  REP(i, N) cin >> x[i] >> v[i];

  ll dpr1[N], dpr2[N], dpl1[N], dpl2[N];
  ll s = v[0] - x[0];
  dpr1[0] = max(0ll, s);
  REP(i, N - 1) {
    s += v[i + 1] - (x[i + 1] - x[i]);
    dpr1[i + 1] = max(dpr1[i], s);
  }
  s = v[0] - x[0] * 2;
  dpr2[0] = max(0ll, s);
  REP(i, N - 1) {
    s += v[i + 1] - (x[i + 1] - x[i]) * 2;
    dpr2[i + 1] = max(dpr2[i], s);
  }
  s = v[N - 1] - (C - x[N - 1]);
  dpl1[0] = max(0ll, s);
  REP(i, N - 1) {
    s += v[N - 1 - i - 1] - (x[N - 1 - i] - x[N - 1 - i - 1]);
    dpl1[i + 1] = max(dpl1[i], s);
  }
  s = v[N - 1] - (C - x[N - 1]) * 2;
  dpl2[0] = max(0ll, s);
  REP(i, N - 1) {
    s += v[N - 1 - i - 1] - (x[N - 1 - i] - x[N - 1 - i - 1]) * 2;
    dpl2[i + 1] = max(dpl2[i], s);
  }

  ll ans = 0;
  REP(i, N - 1) {
    ans = max(ans, max(dpr1[i] + dpl2[N - 1 - i - 1], dpl1[i] + dpr2[N - 1 - i - 1]));
  }
  ans = max(ans, max(dpr1[N - 1], dpl1[N - 1]));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


// ヒープソート(昇順) *****************

int A[200001], B[200001], tmp; // Bでソート(Aは従属) 必要に応じて要素数と型を変える
int length;                    // 要素数:sort()を呼び出す前に設定する


void swap(int i, int j) {
    int tmp;
    tmp  = A[i];
    A[i] = A[j];
    A[j] = tmp;
    tmp  = B[i];
    B[i] = B[j];
    B[j] = tmp;
}

void downheap(int k, int r) {
    int j, v, w;
    v = B[k];
    w = A[k];
    while (1) {
        j = 2 * k + 1;
        if (j > r) break;
        if (j != r) {
            if (B[j + 1] > B[j]) {
                j = j + 1;
            }
        }
        if (v >= B[j]) break;
        B[k] = B[j];
        A[k] = A[j];
        k = j;
    }
    B[k] = v;
    A[k] = w;
}

void sort() {
    int i;
    for (i = (length - 2) / 2; i >= 0; i--) {
        downheap(i, length - 1);
    }
    for (i = length - 1; i > 0; i--) {
        swap(0, i);
        downheap(0, i - 1);
    }
}

// ***************** ヒープソート(昇順) 


int main() {
  unsigned int N, result;
  int i, j, k;
  scanf ("%d", &N);
  
  for (i=0;i<N;i++) {
      scanf("%d", &B[i]);
  }
  
  length = N;
  sort();
  
  result = 0;
  for (i=0;i<N-2;i++) {
    for (j=i+1;j<N-1;j++) {
      for (k=j+1;k<N;k++) {
        if (B[k]<B[i]+B[j]) result++;
        else break;
      }
    }
  }
  
  
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define ll unsigned long long
#define pb push_back
using namespace std;
const int N = 100005;
int a[N], d[N];
int main () {
	int n, k, mn;
	cin >> n >> k;
	for (int i=0; i<n; i++) cin >> a[i];
	d[0]=0;
	d[1]=abs(a[0]-a[1]);

	for (int i=2; i<n; i++){
		d[i]=d[i-1]+abs(a[i]-a[i-1]);
		for (int j=1; j<=k; j++)
			if (i-j>=0)
				d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]));
	}
	cout << d[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
        return 0;
    }
    string ans = "";
    rep(i, K) ans.push_back(S[i]);
    cout << ans << "..." << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}

////////////////////////////////////////////////////////////////////




int main() {
int a,b,c;
cin>>a>>b>>c;
if(a+b==c || a+c==b || b+c==a){
	cout<<"Yes"<<endl;
}
else{
	cout<<"No"<<endl;
}
return 0;

}




Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}

type keyVal struct{ key, val int }
type byKey []keyVal

func (a byKey) Len() int           { return len(a) }
func (a byKey) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byKey) Less(i, j int) bool { return a[i].key < a[j].key }

func main() {
	io := newIo()
	n := io.nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = io.nextInt()
	}
	sort.Ints(a)

	dic := map[int]int{}
	for _, v := range a {
		dic[v]++
	}

	cntTbl := []keyVal{}
	for k, v := range dic {
		cntTbl = append(cntTbl, keyVal{k, v})
	}
	sort.Sort(byKey(cntTbl))

	ans := 1
	for i := 0; i < len(cntTbl); i++ {
		cnt := cntTbl[i].val
		if i != 0 && cntTbl[i-1].key == cntTbl[i].key-1 {
			cnt += cntTbl[i-1].val
		}
		if i != len(cntTbl)-1 && cntTbl[i+1].key == cntTbl[i].key+1 {
			cnt += cntTbl[i+1].val
		}
		ans = max(ans, cnt)
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 13824
W,H,N = [int(i) for i in input().split()]

p1 = [W,H]
p2 = [0,H]
p3 = [0,0]
p4 = [W,0]

g = []
for i in range(N):
    x,y,a = [int(i) for i in input().split()]
    g.append([x,y,a])


for i,j,k in g:
    if(k == 1):
        if(i > p2[0]):
            p2[0] = i
            p3[0] = i
        else:
            continue
    elif(k == 2):
        if(i < p1[0]):
            p1[0] = i
            p4[0] = i
        else:
            continue
    elif(k == 3):
        if(j > p3[1]):
            p3[1] = j
            p4[1] = j
        else:
            continue
    else:
        if(j < p2[1]):
            p1[1] = j
            p2[1] = j
        else:
            continue

w = p1[0] - p2[0]
h = p1[1] - p4[1]

if(w<=0 or h<=0):
    print(0)
else:
    print(w*h)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,m;
char sn[55][55], sm[55][55];
bool flag, ok;
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++)scanf("%s", &sn[i]);
	for(int i = 0; i < m; i++)scanf("%s", &sm[i]);
	for(int i = 0; i <= n - m; i++){
		for(int j = 0; j <= n - m; j++)
		{
			flag = 0;
				if(sn[i][j] == sm[0][0])
				{
					for(int k = 0; k < m; k++)
						for(int s = 0; s < m; s++)
							if(sn[i + k][j + s] != sm[k][s])
							{
								flag = 1;
							}
				if(flag == 0){ok = 1;break;}
				}
		}
		}
		if(ok)printf("Yes\n");
		else printf("No\n");
}

Measured memory_bytes: 128