akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
//  ll mod(ll val) {
//      ll res = val % MOD;
//      if (res < 0) res += MOD;
//      return res;
//  }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     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){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


int main() {
    int N, K; cin >> N >> K;
    vector<int> v(N, 1);
    for (int k = 0; k < K; ++k) {
        int d; cin >> d;
        for (int i = 0; i < d; ++i) {
            int a; cin >> a; --a;
            v[a] = 0;
        }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
    // cout << setprecision(10);
    return 0;
}


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

int main()
{
    long long n; scanf("%lld", &n);
    int Count = 0;
    for(int i = 1; i <= n; i++)
    {
        int p = i;
        int Coun = 0;
        while(p)
        {
            Coun++;
            p /= 10;
        }
        if(Coun%2 == 1)
        {
            Count++;
        }
    }
    cout << Count << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int n, k;
vector<int> a, f;
bool test(int ub)
{
    int cnt = 0;
    forn(i, n)
    {
        int now = a[i]*f[i];
        if (now < ub) continue;
        int rem = now - ub;

        int ad = rem / f[i];
        while(ad * f[i] < rem) ++ad;

        cnt += ad;
    }
    return cnt <= k;
}
void solve()
{
    cin>>n>>k;
    a.resize(n);
    f.resize(n);
    forn(i, n) cin>>a[i];
    forn(i, n) cin>>f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    //

    int lf = 0, rg =1e13;
    int fd = 1e13;
    while (lf <= rg)
    {
        int mid = (lf + rg) / 2;
        if (test(mid))
        {
            fd = mid;
            rg = mid - 1;
        }
        else lf = mid + 1;
    }
    cout << fd << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 6336
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        if(d<0){
            cout<<"No"<<endl;
            break;
        }
        //cout<<a<<" "<<b<<" "<<c<<endl;
        if(a>=b){
            b*=2;
        }else if(b>=c){
            c*=2;
        }else{
            cout<<"Yes"<<endl;
            break;
        }
        //cout<<"inoti"<<d<<endl;;
        d--;
    }
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
long long a,b,cnt[100],ans;
void dfs(int x,int a1,bool a2)
{
	if(a1==2&&a2)
	{
		ans++;
		return;
	}
	if(x>97)return;
	dfs(x+1,a1,a2);
	if(cnt[x]>=4&&a1<2)dfs(x+1,a1+1,a2);
	if(cnt[x]>=2&&!a2)dfs(x+1,a1,1);
	if(cnt[x]>=14&&!a2&&a1<2)dfs(x+1,a1+1,1);
	if(cnt[x]>=24&&!a1)dfs(x+1,2,a2);
	if(cnt[x]>=74&&!a1&&!a2)dfs(x+1,2,1);
}
int main()
{
	cin>>a;
	for(int s=2;s<=a;s++)
	{
		b=s;
		for(int v=2;v<=a;v++)
		{
			if(b%v==0)
			{
				cnt[v]++;
				b/=v;
				v--;
			}
		}
	}
	dfs(2,0,0);
	cout<<ans<<endl;
}

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

ans = B[A[0] - 1]

for i in range(1, N):
  ans += B[A[i] - 1]
  if A[i] - 1 == A[i - 1]:
    ans += C[A[i] - 2]

print(ans)

Measured memory_bytes: 3064
#include"bits/stdc++.h"
#define int long long
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<=(b))
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    string s[3];
    rep(i,3)cin>>s[i];
    int turn=0;
    while(1){
    	if(s[turn].size()==0){
    		char ans='A'+turn;
    		cout<<ans<<endl;
    		break;
    	}
    	char tmp=s[turn].front();
    	s[turn].erase(s[turn].begin());
    	turn=tmp-'a';
    }
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

Measured memory_bytes: 256
import math

def main():
    A, B = map(int, input().split())

    # 条件を満たす可能性のある最小の正数を計算
    x_min = max(math.ceil(A / 0.08), math.ceil(B / 0.1))
    # 条件を満たす可能性のある最大の正数を計算
    x_max = min((math.ceil((A + 1) / 0.08), math.ceil((B + 1) / 0.1)))

    # 候補の正数を順番にチェックし、満たすものがあればそれを出力して終了
    for x in range(x_min, x_max + 1):
        if (math.floor(x * 0.08) == A) and (math.floor(x * 0.1) == B):
            print(x)
            quit()

    # ここまで来るときは満たすものがないので、-1を出力
    print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,i,j;
            cin>>n;
            ll ar[n+1],ans=1e15,ct;
            for(i=1;i<=n;++i)
                cin>>ar[i];
            sort(ar+1,ar+n+1);
            for(i=1;i<=100;++i)
            {
                ct=0;
                for(j=1;j<=n;++j)
                {
                    ct=ct+(i-ar[j])*(i-ar[j]);
                }
                ans=min(ans,ct);
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CirclePond solver = new CirclePond();
        solver.solve(1, in, out);
        out.close();
    }

    static class CirclePond {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            pw.println(2d * sc.nextInt() * Math.PI);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 33404
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#define rg register
#define _ 101
using namespace std;
int n,x,a[_];
inline int read()
{
	rg int save=0,w=1;rg char q=getchar();
	while(q<'0'||q>'9'){if(q=='-')w=-1;q=getchar();}
	while(q>='0'&&q<='9')save=(save<<3)+(save<<1)+q-'0',q=getchar();
	return save*w;
}
inline void Input()
{
	n=read(),x=read();
	int i;
	for(i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1);
}
int main()
{
	Input();
	int i,ans=0;
	for(i=1;i<=n;++i)
	{
		if((x==a[i]&&i==n)||(x>=a[i]&&i^n))x-=a[i],ans++;
		else break;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b,h;cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
	int a[3];
	int x,y,wk;
	for(x=0;x<3;x++)	{
		scanf("%d",&a[x]);
	}
	for(x=0;x<2;x++)	{
		for(y=x+1;y<3;y++)	{
			if(a[x]>a[y])	{
				wk=a[x];
				a[x]=a[y];
				a[y]=wk;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 1776
#! ruby -Ku W2 --debug

T = 1 # gets.to_i
lines = []
T.times do
  lines << gets
end

lines.each_with_index do |line, i|
  prices = []
  line.split(/ /).each do |price|
    prices << price.to_i
  end
  prices.sort!
  print prices[0] + prices[1]
end


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(){
    int m,f,r;
    while(cin>>m>>f>>r)
    {
        if(m==-1&&f==-1&&r==-1)
            break;
        else if(m==-1||f==-1||m+f<30)
            cout<<"F"<<endl;
        else if(m+f>=80)
            cout<<"A"<<endl;
        else if(m+f>=65&&m+f<80)
            cout<<"B"<<endl;
        else if((m+f>=50&&m+f<65)||r>=50)
            cout<<"C"<<endl;
        else
            cout<<"D"<<endl;
    }
    return 0;
}


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

int main(){
    string str = "", com;
    cin >> com;
    for(char ch : com){
        if(ch == '0') str += '0';
        if(ch == '1') str += '1';
        if(ch == 'B' && str.size() > 0){
            str.pop_back();
        }
    }
    cout << str << "\n";
    return 0;
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
f=b*(a**2)/2
if x>=f:
  y=2*(b*(a**2)-x)/(a**2)
  if y==0:
    print(0)
    exit()
  print(90-math.degrees(math.atan(a/y)))
else:
  y=2*x/(a*b)
  if y==0:
    print(0)
    exit()
  print(math.degrees(math.atan(b/y)))

Measured memory_bytes: 3064
l = list(map(int,input().split()))

W = l[0]
H = l[1]
x = l[2]
y = l[3]
r = l[4]

if x+r > W or x-r < 0:
    print('No')
elif y+r > H or y-r < 0:
    print('No')
else:
    print('Yes')



Measured memory_bytes: 5596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll m=n/2;
    ll num=0;

    vector<ll>b(n);
    for(int i=m;i<n;i++){
        if(a[i]==0)b[i]=0;
        else {
            b[i]=1;
            num++;
        }
    }

    for(int i=m-1;i>=0;i--){
        ll c=i+(i+1);
        ll d=0;
        while(c<n){
            d+=b[c];
            c+=i+1;
        }
        if(d%2==0&&a[i]==0)b[i]=0;
        else if(d%2==1&&a[i]==1)b[i]=0;
        else {
            b[i]=1;
            num++;
        }
        
    }

    cout<<num<<endl;
    rep(i,n){
        if(b[i]==1)cout<<i+1<<" ";
    }
    cout<<endl;

}



























Measured memory_bytes: 3968
n = int(input())

ans = n*(n+1)//2

a = n // 3
b = n // 5
c = n // 15

aw = (6 + 3*(a-1))*a//2
bw = (10 + 5*(b-1))*b//2
cw = (30 + 15*(c-1))*c//2

print(ans - aw - bw +cw)

Measured memory_bytes: 9188
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
#define sz(v)           ((int)(v).size())
#define rep(i,a,b)      for(int i=a;i<=b;i++)
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
int md=mod;
void oblivious()
{
    int n;
    cin>>n;
    int a[n];
    int pref[n+1];
    int ans=0;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    pref[0]=0;
    for(int i=1;i<=n;i++)
    {
        pref[i]=pref[i-1]+a[i-1];
    }
    for(int i=0;i<n;i++)
    {
        int k=(sum-pref[i+1])%md;
        int k1=a[i]%md;
        ans=((k*k1)%md+ans%md)%md;
    }
    cout<<ans<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    //int z=t;
    while(t--)
    {
        //cout<<"Case #"<<(z-t)<<": ";
        oblivious();
    }
    return 0;
}
//Editorial
/*

    */

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    double c = 2 * PI * r;
    cout << c << endl;

    return 0;
}


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

using namespace std;

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

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	while (cin >> N) {
		ll ans = 0;
		REP(a, 10) REP(b, 10) REP(c, 10) REP(d, 10) {
			if (a + b + c + d == N) {
				++ans;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3000
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int height[10];

	for (int i = 0; i < 10; i++) {
		cin >> height[i];
	}

	sort(height, height+10, greater<int>());

	for (int i = 0; i < 3; i++) {
		cout << height[i] << endl;
		
	}	

	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

const int N = 2005;

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

    int h, w; cin >> h >> w;
    vector<vector<char>> fi(h+5, vector<char>(w+5, '.'));
    for(int i=1; i<=h; ++i) for(int j=1; j<=w; ++j) cin >> fi[i][j];

    vector<vector<int>> left(N, vector<int>(N, 0)), right(N, vector<int>(N, 0)), over(N, vector<int>(N, 0)), under(N, vector<int>(N, 0));
    
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            if(fi[i][j] == '#') left[i][j] = 0;
            else left[i][j] = left[i][j-1]+1;
        }
    }

    for(int i=1; i<=h; ++i){
        for(int j=w; j>=1; --j){
            if(fi[i][j] == '#') right[i][j] = 0;
            else right[i][j] = right[i][j+1]+1;
        }
    }

    for(int j=1; j<=w; ++j){
        for(int i=1; i<=h; ++i){
            if(fi[i][j] == '#') over[i][j] = 0;
            else over[i][j] = over[i-1][j]+1;
        }
    }

    for(int j=1; j<=w; ++j){
        for(int i=h; i>=1; --i){
            if(fi[i][j] == '#') under[i][j] = 0;
            else under[i][j] = under[i+1][j]+1;
        }
    }

    int ans = 0;
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j){
            if(fi[i][j] == '#') continue;

            chmax(ans, left[i][j]+right[i][j]+over[i][j]+under[i][j]-3);
        }
    }

    cout << ans << endl;
    
    return 0;
}



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

#define SLAY ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0);
#define LL long long
#define PII pair<int , int>
#define PLL pair<long long , long long>
#define INPUT freopen("/Users/amrfahmy/Documents/Problem solving/CF/CF/input.txt", "r", stdin);
using namespace std;
 
const LL MOD = 1000000007;
LL arr[1000000];
LL b[1000];
LL n,q,c,cnt,mx,m,temp,k;
string str;



bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){
    return (a.first < b.first);
}

LL solve(LL n){
    string str = to_string(n);
    int len = (int) str.length();
    LL ret =0;
    int i =0;
    cout<<len<<endl;
    while(i<len){
        ret+= ( (len-1-i) * ( 9 * i));
        i++;
        
    }
    return ret;
}
int main()
{
    bool readfromfile=false; if(!readfromfile){SLAY} else{INPUT}
    
 

    cin>>n;
    LL den=10;
    LL ans=0;
    
    if(n&1 & 1){
        cout<<0;
        return 0;
    }
    while(den<=n){
        ans+= (n/den);
        den*=5;
    }
    
    cout<<ans;
    
    return 0;
}
 



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

bool cmp(char a, char b) {
	return a > b;
}

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), cmp);
	char sd[100], td[100];
	for (int i = 0; i < s.size(); i++)
		sd[i] = s[i];
	sd[s.size()] = 0;
	for (int i = 0; i < t.size(); i++)
		td[i] = t[i];
	td[t.size()] = 0;
	if (strcmp(sd, td) < 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ALDS15A2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = int.Parse(s);
            string[]a = getsplit();
            int[] A = new int[n];
            for (int i = 0; i < n; i++)
            {
                A[i] = int.Parse(a[i]);
            }
            int c = getint();
            string[] b = getsplit();
            bool[] M = new bool[c];
            for (int i = 0; i < c; i++)
            {
                M[i] = solve(0, int.Parse(b[i]), A);
                if (M[i])
                {
                    Console.WriteLine("yes");
                }
                else
                {
                    Console.WriteLine("no");
                }
            }
        }
        public static int getint()
        {
            int x = int.Parse(Console.ReadLine());
            return x;
        }
        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }

        public static bool solve(int i, int m, int[] A)
        {
            if (m == 0)
            {
                return true;
            }
            if (i >= A.Length)
            {
                return false;
            }

            bool res = solve(i + 1, m, A) || solve(i + 1, m - A[i], A);
            return res;
        }
    }
}

Measured memory_bytes: 8880
import Data.List

main = do
    n <- readLn :: IO Int
    s <- getLine
    let sw = map (check s) [[True,True], [True,False], [False,True], [False,False]]
    let ans = filter (not . null) sw
    putStrLn $ if null ans then "-1" else format (head ans)

f (xs@(x:_),this) c | this && c == 'o' = ((this:xs), x)
                    | this && c == 'x' = ((this:xs), not x)
                    | c == 'o' = ((this:xs), not x)
                    | c == 'x' = ((this:xs), x)

check s (x:y:_) | x == l && y == next = rev
                | otherwise = []
    where (ps,next) = foldl' f ([x],y) s
          l = head ps
          rev = tail $ reverse ps

format xs = map (\p -> if p then 'S' else 'W') xs

Measured memory_bytes: 14852
import Data.List
main :: IO ()
main = do
  _ <- getLine
  ts <- parse . map (map read . words) . lines <$> getContents
  print $ solve ts

solve :: [[[Int]]] -> Int
solve = maximum . map (length.map snd) . filter validate. subsequences . addIndex
  where
    addIndex = zipWith (\n t -> (n, t)) [1..]

parse :: [[Int]] -> [[[Int]]]
parse [] = []
parse ls = h : parse rest
  where
    (h, rest) = break ((/=2).length) . tail $ ls

validate :: [(Int, [[Int]])] -> Bool
validate ts = honestsOk && unkindsOk
  where
    indexes = map fst ts
    honestsOk = and . map (`elem` indexes) . concatMap (map head . filter ((==1).head.tail) . snd) $ ts
    unkindsOk = and . map (`notElem` indexes) . concatMap (map head . filter ((==0).head.tail) . snd) $ ts

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

int main(){
    int A, B, Ans, p, q, r;
    cin >> A >> B;
    p = A+B;
    q = A-B;
    r = A*B;
    
    Ans = max({p, q, r});
   
    cout << Ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    cout << 1 << endl;
    return 0;
  }

  
  s.pop_back();
  int len = s.size();
  int leng;
  for (int i = 0; i < len; ++i) {
    leng = len - i;
    string t = s.substr(0, leng / 2), p = s.substr(leng / 2, leng);
    // cout << t << " " << p << endl;
    if (leng % 2 == 0) {
      if (t == p) {
        break;
      }
    }
    s.pop_back();
  }

  cout << leng << endl;
}

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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, i=0, power=1, hap=0, j;
    char c[100];
    cin>>n;
    while(n>hap)
    {
        power*=26;
        hap+=power;

        i++;
    }
    hap-=power;
    n-=(hap+1);
    for(j=1;j<=i;j++)
    {
        c[j]=(97+n%26);
        n/=26;
    }
    for(j=i;j>0;j--)
    printf("%c", c[j]);
    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
char str[max_n];
void reads(string& s){scanf(" %s",str);s=str;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
ll mx=(1e18);
int n,a[max_n];
int main(){
    mx++;
    //cout<<mx<<endl;
    ll ans=1;
    scanf("%d",&n);
    bool f=false;
    for(int i=1;i<=n;i++){
        ll x;scanf("%lld",&x);
        if(x==0)ans=0,f=false;
        else if(ans>=ceil(mx,x)){
            f=true;
        }
        else ans*=x;
    }
    if(f)printf("-1\n");
    else printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3840
fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map(String::toInt)

    var max = 0
    var min = 0
    var med = 0
    if (a > b) {
        if (a > c) {
            max = a
            if (b > c) {
                med = b
                min = c
            } else {
                med = c
                min = b
            }
        } else {
            max = c
            med = a
            min = b
        }
    } else {
        // b > a
        if (c > b) {
            max = c
            med = b
            min = a
        } else {
            max = b
            if (a > c) {
                med = a
                min = c
            } else {
                med = c
                min = a
            }
        }
    }

    val ans = max * 10 + med + min
    println(ans)
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vi w(n);
    ll l=0,r=0;
    REP(i,n) {
        cin>>w[i];
        r += w[i];
    }
    
    ll ans = INT_MAX;
    REP(i,n-1){
        l += w[i];
        r -= w[i];
        ans = min(ans, abs(l-r));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,K;

int main(){
  cin >> N >> K;
  vector<int> a(N);
  rep(i,0,N - 1){
    cin >> a[i];
  }

  vector<int> pp,nn;
  rep(i,0,N - 1){
    if(a[i] >= 0){
      pp.push_back(a[i]);
    }
    else{
      nn.push_back(a[i]);
    }
  }
  sort(all(pp));
  sort(all(nn));
  reverse(all(nn));
  i64 ans = 1e18;
  for(int i = 0;i <= K;i++){
    int j = K - i;
    if(i > pp.size() || j > nn.size()) continue;
    int left = (j == 0) ? 0 : abs(nn[j - 1]);
    int right = (i == 0) ? 0 : pp[i - 1];
    i64 res = min(left * 2 + right , left + right * 2);
    ans = min(ans , res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int x,y,z; cin>>x>>y>>z;

    cout << z <<" "<< x <<" "<< y << endl;


}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

bool query(ll n) {
    cout << "? " << n << endl;
    string res;
    cin >> res;
    return res == "Y";
}

bool answer(int n) {
    cout << "! " << n << endl;
}

int main(void) {
    int len = 10;
    for (int x = 1e9-1; x > 0; x /= 10, len--) {
        if (!query(x)) break;
    }
    if (len == 1) {
        for (long long x = 10; x <= 1e9; x *= 10, len++) {
            if (!query(x)) break;
        }
        if (len == 10) {
            answer(1);
            return 0;
        }
    }
    ll l = pow(10,len-1)-1;
    ll r = pow(10,len)-1;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        if (query(m * 10))
            r = m;
        else
            l = m;
    }
    answer(r);
    return 0;
}

Measured memory_bytes: 596
#include <cstdlib>
#include <iostream>


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

  int k, s;
  std::cin >> k >> s;

  int cnt = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (0 <= z && z <= k) {
        cnt++;
      }
    }
  }
  std::cout << cnt << std::endl;

  return EXIT_SUCCESS;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s = "aiueo";
    char c; cin >> c;
    for (auto e: s) {
        if (e == c) {
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 10 00:13:41 2020

@author: liang
"""

N = int(input())
A = [int(input()) for i in range(N)]
B = A.copy()
B.sort()

for i in range(N):
    if A[i] == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

int main(){
  char c[2][3];
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 3; ++j)
      cin >> c[i][j];
  bool f = true;
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 3; ++j)
      f &= c[i][j] == c[1-i][2-j];
  cout << (f?"YES":"NO") << endl;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S; cin >> S;
  for (int i = 0; i < S.length(); i++) {
    for (int j = i; j < S.length(); j++) {
      string subs = S.substr(0,i) + S.substr(j,S.length()-j);
      if (subs == "keyence") {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

ll prime_factor(int n) {
  if (n==1) return 1ll;
  map<int, ll> ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  ll res = 1ll;
  for (auto p: ret) {
    res*=(p.second+1);
  }
  return res;
}

int main() {
  INCANT;
  cin >> N;
  ll total = 0ll;
  for (int c=1; c<N; c++) {
    int ab = N-c;
    total += prime_factor(ab);
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
#define PI 3.14159265359
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
signed main() {
	int n, z = 1;
	cin >> n;
	bool b = false;
	f(i, n) {
		int a;
		cin >> a;
		if (a == 0) {
			puts("0");
			return 0;
		}
		if (mypow(10, 18, LLONG_MAX) / z < a) {
			b = true;
		}
		if(!b) z*= a;
	}
	if (b)puts("-1");
	else cout << z << endl;
}


Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    s=s+a[i]
m=s/n
mi=round(m)
s=0
for i in range(n):
    s=s+int(pow(a[i]-mi,2))
print(s)
    

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  if(b-a == c-b) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] w = new int[n];
        int s1 = 0, s2 = 0;
        for(int i=0; i<n; i++){
            w[i] = sc.nextInt();
            s2 += w[i];
        }

        int ans = Integer.MAX_VALUE;
        for(int i=0; i<n; i++){
            s1 += w[i];
            s2 -= w[i];
            ans = Math.min(ans, Math.abs(s1-s2));
        }
        System.out.println(ans);
    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


Measured memory_bytes: 23124
import sys
sys.setrecursionlimit(100000)
class UnionFind:
    def __init__(self, n):
        self.p=[i for i in range(n)]
        self.r=[0 for i in range(n)]
    
    def root(self,x):
        if self.p[x]==x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    
    def uni(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if(x==y):
            return
        if self.r[x]<self.r[y]:
            self.p[x]=y
        else:
            self.p[y]=x
            if self.r[x]==self.r[y]:
                self.r[x]+=1
    
    def same(self,x,y):
        return self.root(x)==self.root(y)

n,m=map(int,input().split())
p=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    uf.uni(p[x-1]-1,p[y-1]-1)
count=0
for i in range(n):
    if uf.same(i,p[i]-1):
        count+=1
print(count)

Measured memory_bytes: 13812
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define pb push_back
#define pa pair<int,int>
#define rint register int
#define Set set
#define debug(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-') w=-1;ch=getchar();} while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();} return w*s;}
//struct node{int to,next;} e[201010];
int n,fa[101001];
map<pa,int> mp;
Set<int> S[101010];
//inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
queue<pa> q;
inline int find(int x){if(x==fa[x]) return x;else return fa[x]=find(fa[x]);}
inline void add(int x,int y){
	S[x].insert(y);
	S[y].insert(x);
	if(x>y) swap(x,y);
	mp[mk(x,y)]++;
	if(mp[mk(x,y)]==2) q.push(mk(x,y)); 
}
inline void del(int x,int y){
	S[x].erase(y);
	S[y].erase(x);
	if(x>y) swap(x,y);
	mp.erase(mk(x,y));
}
queue<pa> q2; 
int main(){
	n=read();
	for(rint i=1;i<=n;++i) fa[i]=i;
	for(rint i=1;i<n;++i){
		int x=read(),y=read();
		add(x,y);
	}
	for(rint i=1;i<n;++i){
		int x=read(),y=read();
		add(x,y);
	}
	for(rint i=1;i<n;++i){
		if(q.empty()){cout<<"NO\n";exit(0);}
		pa tmp=q.front();q.pop();
		int x=tmp.first,y=tmp.second;
		int xx=find(x),yy=find(y);
		if(S[xx].size()<S[yy].size()) swap(xx,yy);
		fa[yy]=xx;
		del(xx,yy);	//	debug(i);
		for(auto o:S[yy]){
			int p=yy,q=find(o);
			if(p==q) continue;
//			del(p,q);
			q2.push(mk(p,q));
			add(xx,o);
		}
		while(!q2.empty()){del(q2.front().first,q2.front().second);q2.pop();}
	}
	cout<<"YES\n";
	return 0;
}	

Measured memory_bytes: 36608
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    string s;ll n,p;cin>>n;
    map<string,vector<pair<ll,ll>>> m;
    for(ll i=0;i<n;i++)
    {
    	cin>>s>>p;
    	m[s].pb(make_pair(p,i));
	}
	for(auto x:m)
	{
		vector<pair<ll,ll>> v =x.second;
		sort(v.begin(),v.end());reverse(v.begin(),v.end());
		for(ll i=0;i<v.size();i++)
		   cout<<(v[i].second+1)<<endl;
	}
	
    
	
	
	
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(void){
    string s; cin >> s;
    reverse(s.begin(), s.end());

    int id = 0;
    int N = s.size();

    while(id < N){
        if(s.substr(id, 5) == "maerd") id += 5;
        else if(s.substr(id, 7) == "remaerd") id += 7;
        else if(s.substr(id, 5) == "esare") id += 5;
        else if(s.substr(id, 6) == "resare") id += 6;
        else{
            cout << "NO" << endl;
            return 0;
        } 
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
int main(){
  ll n, A[200100], tmp = 0, ans = 0;
  cin >> n;
  for(int i=0; i<n; ++i) cin >> A[i];
  for(int i=n-2; i>=0; --i){
      tmp += A[i+1];
      tmp = tmp%MOD;
      ans += A[i]*tmp%MOD;
      ans = ans%MOD;
  } 
  cout << ans << endl;
}


Measured memory_bytes: 5232