akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))

dp=[[0]*2 for i in range(n)]
dk=[[0]*2 for i in range(n)]

#--------------- kabu=0
dp[0][0]=1000
dk[0][0]=0
#--------------- all kabu
dp[0][1]=1000%a[0]
dk[0][1]=1000//a[0]

for k in range(1,n):
    dp[k][0]=max(dp[k-1][0],dp[k-1][1]+dk[k-1][1]*a[k])
    dk[k][0]=0

    dpk1=dp[k-1][0]%a[k]
    dkk1=dp[k-1][0]//a[k]
    v1=dk[k-1][1]*a[k]+dp[k-1][1]
    v2=dkk1*a[k]+dpk1
#    if dkk1>dk[k-1][1]:
    if v2>v1:
        dk[k][1]=dkk1
        dp[k][1]=dpk1
    else:
        dp[k][1]=dp[k-1][1]
        dk[k][1]=dk[k-1][1]

print(dp[n-1][0])


Measured memory_bytes: 9192
//! Oos Karim Rokhsat
#include<bits/stdc++.h>
using namespace std;

typedef double                      ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 1e3 + 10;
const ll MXM = 50 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll LOG = 20;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, m, s, e, ans;
ll dis1[MX5], dis2[MX5];
vector<ll> G[MX5];
vector<pll> V;
bool vis[MX5], mark[MX5];

void DFS1(ll u, ll d){
    dis1[u] = d;
    vis[u] = 1;
    for(auto v : G[u]){
        if(!vis[v]) DFS1(v, d + 1);
    }
    return;
}

void DFS2(ll u, ll d){
    dis2[u] = d;
    vis[u] = 1;
    for(auto v : G[u]){
        if(!vis[v]) DFS2(v, d + 1);
    }
    return;
}

void DFS(ll u){
    vis[u] = 1;

    if(dis1[u] >= dis2[u]){
        return;
    }

    for(auto v : G[u]){
        if(!vis[v]){
            DFS(v);
        }
        mark[v] = 1;
    }
    return;
}

int main(){
    fast_io
    //file_io
    cin >> n >> s >> e;
    m = n - 1;
    for(int i = 0; i < m; i ++){
        ll u, v;
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    DFS1(s, 0);
    fill(vis, vis + MX5, 0);
    DFS2(e, 0);
    fill(vis, vis + MX5, 0);
    DFS(s);

    for(int i = 1; i <= n; i ++){
        V.pb({dis2[i], i});
    }

    sort(all(V), greater<pll>());
//cerr << endl;
    for(auto Pr : V){
        ll v = Pr.S, d = Pr.F;
        if(mark[v]){
            //cerr << v << sep << d << endl;
            ans = max(ans, d - 1 + (dis1[v] == dis2[v] ? 1 : 0));
        }
    }

    cout << ans;

    return 0;
}

//! N.N


Measured memory_bytes: 12404
s=input()
lst=[]
c='L'
cnt=0
for i in s:
    if c == i: cnt+=1
    else:
        lst.append(cnt)
        c=i
        cnt=1
if not cnt==0: lst.append(cnt)
lst.remove(0)
rst=[0]*len(s)
p=True
idx=0
for i in lst:
    idx+=i
    if p:
        if i%2==0:
            rst[idx]+=i>>1
            rst[idx-1]+=i>>1
        else:
            rst[idx-1]+=(i>>1)+1
            rst[idx]+=i>>1
        p=False
    else:
        if i%2==0:
            rst[idx-i]+=i>>1
            rst[idx-i-1]+=i>>1
        else:
            rst[idx-i]+=(i>>1)+1
            rst[idx-i-1]+=i>>1
        p=True
print(' '.join(map(str, rst)))


Measured memory_bytes: 11252
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
 
int d[200][200],s[200];
int main() {
	int n,m,r;scanf("%d%d%d",&n,&m,&r);
	memset(d,0x3f,sizeof(d));
	rep(i,n)d[i][i]=0;
	rep(i,r)scanf("%d",&s[i]),s[i]--;
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		d[a][b]=d[b][a]=c;
	}
	rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	sort(s,s+r);
	int Min=INT_MAX;
	do{
		int cnt=0;
		rep(i,r-1)cnt+=d[s[i]][s[i+1]];
		Min=min(Min,cnt);
	}while(next_permutation(s,s+r));
	printf("%d",Min);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll binarysearch(ll b[],ll i, ll n){
	//find the smallest index j such that b[j]>i
	ll k=n;
	for(int size=n;size>0;size/=2)
		while(k-size>=0 && b[k-size]>i)k-=size;
	return k;
}
ll binarysearch1(ll b[], ll i, int n){
	//find largest index k such that b[k]<i
	ll k=0;
	for(int size=n;size>0;size/=2)
		while(k+size<n && b[k+size]<i) k+=size;
	return k;
}

int main(){
	ll n;
	cin >> n;
	ll a[n],b[n],c[n];
	FOR(i,n){
		cin >>a[i];
	}
	FOR(i,n){
		cin >> b[i];
	}
	FOR(i,n){
		cin >> c[i];
	}
	ll sum=0;
	
	sort(a,a+n);
	//sort(b,b+n);
	sort(c,c+n);
	//cout << binarysearch(b,1,n);
	FOR(j,n){
		ll m=(lower_bound(a,a+n,b[j])-a);
		ll q=n-(upper_bound(c,c+n,b[j])-c);
		sum+=m*q;
	}
	cout << sum;
	/*cout <<"\n";
	sum=0;
	FOR(j,n){
		ll q=binarysearch1(a,b[j],n)+1;
		ll w=binarysearch(c,b[j],n);
		sum+=q*(n-w);
	}
	cout << sum;*/
	
	return 0;
}

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

int main(void){
    string s;
    int ans = 0;
    
    cin >> s;
    
    for(int i = 0; i < 4; i++){
        if(s[i] == '+')
            ans++;
        else
            ans--;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, i, cnt = 0;
    cin>>n;
    vector<int> a(n);
    for(i=0;i<n;++i)    cin>>a[i];
    for(i=0;i<n;++i)
    {
        if(a[i] != i+1)  ++cnt;
    }
    if(cnt > 2) cout<<"NO";
    else    cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
    auto s = sread();
    // writeln(s);
    // writeln(s[0 .. (s.length) / 2]);
    // writeln(s[(s.length) / 2 .. $]);
    foreach (i; 2 .. (s.length))
    {
        // writeln(s[0 .. $ - i]);
        if (func(s[0 .. $ - i]))
        {
            writeln(s[0 .. $ - i].length);
            return;
        }
    }

}

auto func(string s)
{
    if (s[0 .. (s.length) / 2] == s[(s.length) / 2 .. $])
    {
        return true;
    }
    else
    {
        return false;
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    ll n, k;
    cin >> n >> k;
    cout << min(n % k, k - n % k) << endl;

    return 0;
}

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

int main() {
	ll x, a = 0, b = 0, TmpAnswer = 0, Pow5Memory[3003] = {};
	cin >> x;
	for (ll i = 0; i < 3000; i++)
	{
		Pow5Memory[i] = i * i * i * i * i;
		//cout << Pow5Memory[i] << endl;
	}
	for (ll i = 0; i < 3000; i++)
	{
		for (ll j = 0; j < 3000; j++)
		{
			if (Pow5Memory[i] + Pow5Memory[j] == x)
			{
				cout << i << " " << -j << endl;
				return 0;
			}
			else if (Pow5Memory[i] - Pow5Memory[j] == x)
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	//while (x != TmpAnswer)
	//{
	//	ll TmpA = a;
	//	ll TmpB = b;
	//	for (int i = 0; i < 5; i++)
	//	{
	//		TmpA *= TmpA;
	//		TmpB *= TmpB;
	//	}
	//	ll TmpAnswer = TmpA - TmpB;
	//	if (x < TmpAnswer)
	//	{
	//		a++;
	//	}
	//	else
	//	{
	//		b++;
	//	}
	//}
	//cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 3556
#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 main(){
  int a,b;
  cin >> a >> b;

  if(a + b == 15){
    cout << "+" << endl;
  }
  else if(a * b == 15){
    cout << "*" << endl;
  }
  else{
    cout << "x" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

		
	    public static void main(String[] args) throws java.io.IOException{
	        Scanner scan = new Scanner(System.in);
	        boolean [] prime = new boolean[1299710];
	        for(int i=2;i<prime.length;i++)prime[i]=true;
	        for(int i=2;i<=Math.sqrt(prime.length-1);i++){
	        	if(prime[i]){
	        		for(int j=i*2;j<=prime.length-1;j+=i)prime[j]=false;
	        	}
	        }
	        
	        while(true){
	        	int k=scan.nextInt();
	        	if(k==0)break;
	        	if(prime[k])System.out.println(0);
	        	else{
	        		int lp=0;
	        		for(int i=k;i>1;i--)
	        			if(prime[i]){
	        				lp=i;
	        				break;
	        			}
	        		int rp=0;
	        		for(int i=k;i<1299710;i++)
	        			if(prime[i]){
	        				rp=i;
	        				break;
	        			}
	        		System.out.println(rp-lp);
	        	}
	        }
	    }
}
	    

Measured memory_bytes: 13000
import sys
input = sys.stdin.readline
mod = 2019
s = input().rstrip()
n = len(s)
mod_list = [0]
for i in range(n - 1, -1, -1):
    mod_list.append((mod_list[-1] + int(s[i]) * pow(10, n - 1 - i, mod)) % mod)
from collections import Counter
c = Counter(mod_list)
ans = 0
for i in c.keys():
    ans += c[i] * (c[i] - 1) // 2
print(ans)





Measured memory_bytes: 75952
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int A[m], B[m];
    int k = 0;
    for(int i = 0; i < m; i++)
    {
        cin >> A[i] >> B[i];
    }
    sort(A, A+m);
    for(int j = 1; j < m; j++)
    {
        k = k + max(0, n - A[j]);
    }
    cout << k << endl;
    
}

Measured memory_bytes: 3148
K = int(input())

N = 10**6
dp = [1] * (N+1)
dp[0] =  dp[1] =  0

def pw(j,i):
    while(j%i==0):
        j //= i
        
    if j == 1:
        return True
    else:
        return False

for i in range(2,N+1):
    if dp[i]:
        for j in range(i*i, N+1, i):
            #if not pw(j,i):
            dp[j] = 0
ans = 0
for n in range(N):
    i = 0
    while(1):
        i+=1
        v = pow(n,i)
        if (dp[n] == 1 and K%v==0):
            K //= v
            ans += 1
        else:
            break

for n in range(N):
    while(dp[n] == 1 and K%n==0):
        K //= n

#print (K)
if K!=1:
    ans += 1
print (ans)





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

long long dp[4][5555];
long long dq[4][25111111];

int main(){
	long long N;
	int ga,sa,ba,gb,sb,bb;
	cin >> N >> ga >> sa >> ba >> gb >> sb >> bb;
	int AAA[3]={ga,sa,ba};
	int BBB[3]={gb,sb,bb};
	
	for(int i=0;i<4;i++)for(int j=0;j<=N;j++)dp[i][j]=-1;
	for(int i=0;i<4;i++)dp[i][0]=0;
	
	for(int i=0;i<3;i++)for(int j=0;j<=N;j++){
		dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		if(BBB[i]>AAA[i]){
			if(j>=AAA[i])dp[i+1][j]=max(dp[i+1][j-AAA[i]]+BBB[i]-AAA[i],dp[i+1][j]);
		}
		//printf("dp[%d][%d]=%lld\n",i+1,j,dp[i+1][j]);
	}
	
	long long M=0;
	for(int j=0;j<=N;j++){
		M=max(M,dp[3][j]);
	}
	
	M+=N;
	
	
	for(int i=0;i<4;i++)for(int j=0;j<=M;j++)dq[i][j]=-1;
	for(int i=0;i<4;i++)dq[i][0]=0;
	
	for(int i=0;i<3;i++)for(int j=0;j<=M;j++){
		dq[i+1][j]=max(dq[i+1][j],dq[i][j]);
		if(AAA[i]>BBB[i]){
			if(j>=BBB[i])dq[i+1][j]=max(dq[i+1][j-BBB[i]]+AAA[i]-BBB[i],dq[i+1][j]);
		}
		//printf("dq[%d][%d]=%lld\n",i+1,j,dq[i+1][j]);
	}
	
	long long ans=0;
	for(int j=0;j<=M;j++)ans=max(ans,dq[3][j]);
	cout << ans+M << endl;
	return 0;
}

Measured memory_bytes: 784768
import java.util.Scanner;

public class Main {
    public long getMaxProduct(int a, int b, int c, int d) {
        long cand1 = (long) a * (long) c;
        long cand2 = (long) a * (long) d;
        long cand3 = (long) b * (long) c;
        long cand4 = (long) b * (long) d;
        return Math.max(Math.max(cand1, cand2), Math.max(cand3, cand4));
    }

    public static void main(String[] args) throws Exception {
        Main solution = new Main();

        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = scanner.nextInt();

        long answer = solution.getMaxProduct(a, b, c, d);
        System.out.println(answer);
    }
}

Measured memory_bytes: 35408
#!/usr/bin/env python

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

dp = list(float('inf') for i in range(n))
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
    else:
        jump1 = dp[i - 1] + abs(h[i] - h[i - 1])
        jump2 = dp[i - 2] + abs(h[i] - h[i - 2])
        dp[i] = min(jump1, jump2)

print(dp[n - 1])


Measured memory_bytes: 13908
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long ll;
int main()
{
	int r,d,x,i;
	ll a;
	cin>>r>>d>>x;
	a=x;
	for(i=0;i<10;i++)
	{
		a=r*a-d;
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
y = int(s)
for i in range(1, 2**(len(s)-1)):
    t = []
    for j in range(len(s)-1):
        if ((i >> j) & 1):
            t.append(j+1)
    y += int(s[:t[0]])
    y += int(s[t[-1]:])
    if len(t) >= 2:
        for j in range(len(t)-1):
            y += int(s[t[j]:t[j+1]])
print(y)

Measured memory_bytes: 3064
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int R,C,N;
vector<pair<pii,pii>> b;
int ans = 0;

int getint(pii x) {
    if (x.s == 0) return x.f;
    if (x.f == R) return R+x.s;
    if (x.s == C) return 2*R+C-x.f;
    return 2*R+2*C-x.s;
}

bool test() {
    vi cur;
    vector<pair<pii,int>> z;
    
    int co = 0;
    for (auto a: b) {
        z.pb({{min(getint(a.f),getint(a.s)),1},co});
        z.pb({{max(getint(a.f),getint(a.s)),-1},co});
        co++;
    }
    
    sort(z.begin(),z.end());
    for (auto a: z) {
        if (a.f.s == 1) cur.pb(a.s);
        else {
            if (cur[cur.size()-1] != a.s) return 0;
            cur.erase(cur.begin()+cur.size()-1);
        }
    }
    return 1;
}

int main() {
    cin >> R >> C >> N;
    F0R(i,N) {
       pair<pii,pii> x; cin >> x.f.f >> x.f.s >> x.s.f >> x.s.s;
       if (x.f.f != 0 && x.f.f != R && x.f.s != 0 && x.f.s != C) continue;
       if (x.s.f != 0 && x.s.f != R && x.s.s != 0 && x.s.s != C) continue;
       b.pb(x);
    }
    if (test()) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + 7;
const int N = 202;

int n,x,s[N];
int fac[N];
LL dp[202][100000 + 10];
LL A[202][202];
int main() {
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++){
		scanf("%d", &s[i]);
	}
	dp[0][x] = 1;
	sort(s + 1, s + 1 + n);
	for (int i = 0; i <= n; i ++) {
		for (int j = 0; j <= x; j ++) {
			if (dp[i][j] == 0) continue;
			int cnt = n - i;
			for (int k = 1; k <= n; k ++) {
				if (s[k] <= j) {
					(dp[i+1][j % s[k]] += dp[i][j]);
					if (dp[i+1][j % s[k]] > MOD) dp[i+1][j%s[k]] -= MOD;
					cnt --;
				} else {
					break;
				}
			}
			(dp[i+1][j] += dp[i][j] * cnt) %= MOD;
		}
	}
	LL ans = 0;
	for (int i = 0; i <= x; i ++) {
		ans = (ans + dp[n][i] * i) % MOD;
	}
	cout << ans << endl;

}	

Measured memory_bytes: 156288
// AtCoder Regular Contest 099
// Problem E - Independence
#include <cstdio>
#include <cstring>
#include <iostream>
using std::cin; using std::cout; using std::endl;
#include <algorithm>
using std::sort;
#include <vector>
using std::vector;
#include <queue>
using std::queue; using std::priority_queue;
#include <utility>
using std::pair;
#include <bitset>
using std::bitset;
typedef long long LL;
#define pass printf("%s : Line.%d\n", __FUNCTION__, __LINE__);
const int maxN = 700 + 5;
int n, m;
bool G[maxN][maxN];
int col[maxN];
typedef pair<int, int> pii;
int iter = 0;
pii a[maxN];
bitset<maxN> f[maxN], base;

bool dfs(int u) {
	for(int v = 1; v <= n; ++v) if(G[u][v] && v != u) {
		if(col[v]) if(col[v] == col[u]) return false; else continue; else;
		if((col[v] = col[u]^1) == 2) a[iter].first++; else a[iter].second++;
		if(!dfs(v)) return false;
	}
	return true;
}

inline int val(int x) {
	return x*(x-1) / 2 + (n-x)*(n-x-1) / 2;
}

int solve() {
	memset(col, 0, sizeof(col));
	col[0] = 2;
	for(int u = 1; u <= n; ++u) if(!col[u]) {
		++iter; col[u] = 3;
		a[iter] = pii(0, 1);
		if(!dfs(u)) return -1;
	}
	for(int i = 0; i <= n; ++i) base[i] = 1;
	f[0] = 0;
	f[0][0] = 1;
	for(int i = 1; i <= iter; ++i) {
		f[i] = (f[i-1] << a[i].first) | (f[i-1] << a[i].second);
	}
	int r = -1;
	for(int i = 0; i <= n; ++i) if(f[iter][i] && val(i) < val(r)) r = i;
//	for(int i = 1; i <= iter; ++i) printf("(%d, %d),%c", a[i].first, a[i].second, i == iter ? '\n' : ' ');
	if(r < 0) return -1;
	else return val(r);
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			G[i][j] = true;
	for(int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		G[x][y] = G[y][x] = false;
	}
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll mod = pow(10,9) + 7;
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(m);
  for(int i = 0;i < n;i++)cin >> a[i];
  for(int i = 0;i < m;i++)cin >> b[i];
  ll casea = 0;
  for(int i = 0;i < n;i++){
    casea += a[i] * (i - (n - i - 1));
    casea %= mod;
  }
  ll caseb = 0;
  for(int i = 0;i < m;i++){
    caseb += b[i] * (i - (m - i - 1));
    caseb %= mod;
  }
  ll res = casea * caseb;
  res %= mod;
  cout << res << endl;
}

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

int main() {
    int i,j,k;
    ll a,b;
    cin >> a >> b;
  
  if(a>2*b)
  {
     cout << a-2*b<<endl;
  }else
  {
     cout << 0<<endl;
  }
  
  }



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {  
    string S;
    cin >> S;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if(S[i]=='R'){
            cnt++;
        }else{
            cnt=0;
        }
        chmax(ans, cnt);
    }
    
    cout << ans << endl;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    vector<ll> v(3);
    REP(i, 3) cin >> v[i];
    SORT(v);
    
    if (v[0] + v[1] == v[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var cin = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(cin));
        Console.Out.Flush();
    }
    static object Solve(Scanner cin) {
        int diff = 0, modmin = 10, result = 0;
        for (int i = 0; i < 5; i++) {
            var x = cin.NextInt();
            var ceil = (int) Math.Ceiling((double) x / 10) * 10;
            result += ceil;
            if (x % 10 == 0) continue;
            (modmin, diff) = x % 10 < modmin ? (x % 10, ceil - x) : (modmin, diff);
        }
        return result - diff;
    }
}

class Scanner
{
    string[] s;
    int i;
    char[] cs = {' '};

    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public long NextLong() => long.Parse(Next());
    public double NextDouble() => double.Parse(Next());
    public int[] ArrayInt(int N, int add = 0) {
        var Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextInt() + add;
        }
        return Array;
    }
    public long[] ArrayLong(int N, long add = 0) {
        var Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextLong() + add;
        }
        return Array;
    }
    public double[] ArrayDouble(int N, double add = 0) {
        var Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 27380
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        self.size = [1]*(n+1)
    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        xRoot = self.find(x)
        yRoot = self.find(y)
        if xRoot == yRoot:
            return
        if self.size[xRoot]>self.size[yRoot]:
            self.parents[yRoot] = xRoot
            self.size[xRoot] += self.size[yRoot]
            self.size[yRoot] = 0
        else:
            self.parents[xRoot] = yRoot
            self.size[yRoot] += self.size[xRoot]
            self.size[xRoot] = 0

V,E = map(int,input().split())
tree = UnionFind(V)
edges = [list(map(int,input().split())) for _ in range(E)]
edges.sort(key=lambda x: x[2])
cost = 0
for s,t,w in edges:
    if tree.find(s) != tree.find(t):
        cost += w
        tree.unite(s,t)

print(cost)


Measured memory_bytes: 28684
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N; cin >> N ;
  vl a(N),b(N);
  rep(i,N){
    ll p;
    cin >> p;
    p--;
    a[p] = ll(i+1)+p*N;
    b[p] = ll(i+1)+(N-p)*N;
  }
  rep(i,N) cout << a[i] << (i==N-1 ? "\n" : " ");
  rep(i,N) cout << b[i] << (i==N-1 ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 1024
# AtCoder Beginners Selection Otoshidama
import math

N,Money = map(int, input().split())
if(1000*N<=Money<10000*N):
    tenthousand_list=[num for num in range(0,Money+1,10000)]
    fivethousand_list=[num for num in range(0,Money+1,5000)]
    possible_tenthousand=math.floor(Money/10000)
    while (possible_tenthousand >=0):
        ##残り金額と残り枚数を計算
        zan_number=N-possible_tenthousand
        zan_Money=(Money-tenthousand_list[possible_tenthousand])
        if(5000*zan_number>=zan_Money):
            possible_fivethousand=math.floor(zan_Money/5000)
            while (possible_fivethousand>=0):
            
                if(tenthousand_list[possible_tenthousand]+fivethousand_list[possible_fivethousand]+
                   (1000*(N-possible_tenthousand-possible_fivethousand))==Money):
                    zan_Money=0
                    break
                else:
                    possible_fivethousand-=1
        else:
            print("-1 -1 -1")
            break
        
        if((zan_Money==0) and (possible_fivethousand!=-1) ):
            print(str(possible_tenthousand) + " " + str(possible_fivethousand)+ " " + str(N-possible_tenthousand-possible_fivethousand) )
            break

            
        possible_tenthousand-=1

        
        if(possible_fivethousand==-1 and possible_tenthousand ==-1):
            print("-1 -1 -1")
            break
        

        
elif(Money==10000*N):
    print(str(N) + " 0 "+ "0") 

else:
    print("-1 -1 -1")






Measured memory_bytes: 9336
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
r = []
g = []
b = []
cnt = 1
for i in S:
    if i == "R":
        r.append(cnt)
    elif i == "G":
        g.append(cnt)
    else:
        b.append(cnt)
    cnt += 1

ans = len(r)*len(g)*len(b)
for i in r:
    for j in range(1,4001):
        if i + j -1 >= N:
            break
        if i - j -1 < 0:
            break
            
        s1 = S[i+j-1]
        s2 = S[i-j-1]
        if s1 != "R" and s2 != "R" and (s1 != s2):
            ans -= 1
for i in g:
    for j in range(1,4001):
        if i + j - 1 >= N:
            break
        if i - j -1 < 0:
            break
            
        s1 = S[i+j-1]
        s2 = S[i-j-1]
        if s1 != "G" and s2 != "G" and (s1 != s2):
            ans -= 1
for i in b:
    for j in range(1,4001):
        if i + j - 1 >= N:
            break
        if i - j - 1 < 0:
            break
            
        s1 = S[i+j-1]
        s2 = S[i-j-1]
        if s1 != "B" and s2 != "B" and (s1 != s2):
            ans -= 1
print(ans)

Measured memory_bytes: 68644
#include <stdio.h>
#include <string.h>

char unit[200][17];
int ulen=0;

int getnum(char *s)
{
    for (int i=0; i<ulen; i++)
      if (strcmp(s, unit[i])==0) return i;
    strcpy(unit[ulen], s);
    return ulen++;
}

int main()
{
    int i, j, x, y, z, n, dx, dy, x0, y0;
    char buf[64], *p;
    char a[17], b[17];
    int s[200],d[200];
    while (1) {
        ulen=0;
        fgets(buf, 64, stdin);
        if (buf[0]=='0') break;
        for (n=0,p=buf; *p!='\n'; n = n * 10 + *(p++) - '0');
        for (i=0; i<200; s[i]=i,d[i]=0,i++);
        for (i=0; i<n; i++) {
            fgets(buf, 64, stdin);
            for (j=0,p=buf+2; *p!=' '; a[j++]=*(p++));  a[j]=0;
            while (*(p++)!='^');
            z = 0;
            if (*p=='-') for (p++; *p>='0'; z=z*10-(*(p++)-'0'));
            else         for (; *p>='0'; z=z*10+*(p++)-'0');
            for (j=0,p++; *p!='\n'; b[j++]=*(p++));  b[j]=0;
	    x = getnum(a);
	    y = getnum(b);
            for (x0=x,dx=0; s[x]!=x; dx+=d[x], x=s[x]);
            s[x0]=x;
            d[x0]=dx;
            for (y0=y,dy=0; s[y]!=y; dy+=d[y], y=s[y]);
            s[y0]=y;
            d[y0]=dy;
            if (x==y && dy-dx!=z) {
	      fputs("No\n", stdout);
	      for (j=i+1;j<n;j++) fgets(buf, 64, stdin);
	      break;
            }
            s[y] = x;
            d[y] = z + d[x0] - d[y0];
        }
	if (i==n) fputs("Yes\n", stdout);
    }
    return 0;
}



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

int main(){
    long long int x, k, d;
    cin >> x >> k >> d;

    long long int l = abs(x)/d;
    if(l >= k){
        cout << abs(abs(x)-k*d) << endl;
    }else if(l+1 == k){
        //cout << min(abs(abs(x)-k*d), abs(abs(x)-(k-2*d)) << endl;
        cout << abs(abs(x)-k*d) << endl;
    }else{
        long long int hanpuku = l-k;
        if(hanpuku % 2 == 0){
            cout << abs(abs(x)-l*d) << endl;
        }else{
            cout << abs(abs(x)-(l+1)*d) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double total = 0.0;
        int[] e = new int[N];
        for (int i = 0; i < N; i++) {
			e[i] = sc.nextInt();
		}
        Arrays.sort(e);
        double tmp = 0.0;
        for (int i = 0; i < N; i++) {
        	if (i == 0) {
        		tmp = e[i];
        	}
        	tmp = (e[i] + tmp)/2.0;
        }
        System.out.println(tmp);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  string s;
  cin >> s;

  int expected_rsl = 7;

  string rsl = "";
  for(int bit = 0; bit < (1 << 3); ++bit) {
      int tmp = s[0] - '0';
      string tmp_op = "";
      for(int mask = 0; mask < 3; ++mask) {
          if(bit & (1 << mask)) {
              tmp += s[mask + 1] - '0';
              tmp_op += '+';
          } else {
              tmp -= s[mask + 1] - '0';
              tmp_op += '-';
          }
      }
      if(tmp == expected_rsl) {
          rsl = rsl + s[0];
          rep(i, 0, 3) rsl = rsl + tmp_op[i] + s[i + 1];
          cout << rsl << "=7" << endl;
          return 0;
      }
  }

}


Measured memory_bytes: 256
H,W=[int(i) for i in input().split()]
N=int(input())
a=[int(i)for i in input().split()]
tile=[[0 for i in range(W)]for j in range(H)]

x=0
y=0
for idA in range(1,len(a)+1):
        num=a[idA-1]
        while num>0:
                tile[y][x]=idA
                if y%2==0:
                        x+=1
                else:
                        x-=1

                if x==-1:
                        y+=1
                        x=0
                elif x==W:
                        y+=1
                        x=W-1
                num-=1
for y in range(H):
        for x in range(W):
                if x!=0:
                        print(" ",end="")
                print(tile[y][x],end="")
        print()

Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

bool can(int a, int b) {
	while (a % b == 0 && a > 0) {
		// cout << a << ' ' << b << endl;
		a = a / b;
	}
	return a % b == 1;
}

signed main() {

	int n;
	cin >> n;
	
	vector<int> candidates;
	for (int i=1; i*i<n+2; i++) {
		if (n % i == 0) {
			candidates.push_back(i);
			candidates.push_back(n/i);
		}
		if ((n-1) % i == 0) {
			candidates.push_back(i);
			candidates.push_back((n-1)/i);
		}
	}
	
	sort(candidates.begin(), candidates.end());
	
	int last = -1;
	
	int v = 0;
	
	for (int i=0; i<candidates.size(); i++) {
		if (candidates[i] == last) continue;
		last = candidates[i];
		if (candidates[i] == 1) continue;
		v += can(n, candidates[i]);
	}
	
	cout << v << endl;
	
}


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

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

    int h = S / 3600;
    int m = (S-h*3600) / 60;
    int s = S - h*3600 - m*60;
  
  	cout << h << ':' << m << ':' << s << endl;
}


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

const ll MOD = 1e9 + 7;

int mpow(int base, int exp);
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<pair<ll,ll>> vpll;
typedef  vector<pair<int, int>> vpii;
typedef  pair<int, int> pii;
typedef  pair<ll, ll> pll;
typedef  unordered_map<ll, ll> umpll;
typedef  unordered_map<int, int> umpii;
typedef  unordered_map<ll, int> umpli;
typedef  unordered_set<int> usi;
typedef  unordered_set<ll> usll;
typedef  set<int> si;
typedef  set<ll> sll;
typedef  set<pair<int, int>> spii;
typedef  set<pair<ll, ll>> spll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fo(i,n) for(i = 0;i < n; i++)
#define Fo(i,k,n) for(i = k;k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", "<< #z << " = " << z << endl

ll randGen(ll lower, ll upper) { return (rand() % (upper - lower + 1)) + lower; }
ll dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
// cout << fixed;
// cout.precision(10);
//******************          Function here          *********************//

   void solve(){
      int n;
      cin >> n;
      ll a[n];
      for(int i = 0; i < n; i++)cin >> a[i];
      ll mx = a[0], ans = 0;
      for(int i =  1; i < n; i++) {
         if(a[i] > mx) mx = a[i];
         ans += mx - a[i];
      }
      cout << ans << endl;
   }

//*********************************************************************//

int main()
{
    #ifndef ONLINE_JUDGE
      string inputFile, outputFile;
      inputFile = "input.txt";
      outputFile = "output.txt";
      freopen(inputFile.c_str(), "r", stdin);
      freopen(outputFile.c_str(), "w", stdout);
    #endif

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



/**********************   Utility Functions  *****************************/
   int mpow(int base, int exp) {
     base %= MOD;
     int result = 1;
     while (exp > 0) {
       if (exp & 1) result = ((ll)result * base) % MOD;
       base = ((ll)base * base) % MOD;
       exp >>= 1;
     }
     return result;
   }
/***********************************************************************/


Measured memory_bytes: 5152
#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


void solve()
{
    string s, t; cin>>s >>t;
    int ans = 1e9;
    for(int i=0;i + sz(t) - 1 <sz(s);++i)
    {
        int cnt = 0;
        for(int j = 0; j < sz(t); ++j)
        {
            cnt += s[i+j] != t[j];
        }
        ans = min(ans, cnt);
    }
    cout << ans << '\n';

}

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


Measured memory_bytes: 3660
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

// ***************************************


int main(){

    int N, M, K;
    cin >> N >> M >> K;

    UnionFind T(N);
    vector<int> no(N);

    int a, b;
    REP(i, M){
        cin >> a >> b;
        a--; b--;
        T.merge(a, b);
        no[a]++;
        no[b]++;
    }

    int c, d;
    REP(i, K){
        cin >> c >> d;
        c--; d--;
        if (T.issame(c, d)){
            no[c]++;
            no[d]++;
        }
    }

    REP(i, N){
        cout << T.size(i) - no[i] - 1;
        if (i < N - 1) cout << " ";
        else cout << endl;
    }

    

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main()
{
    string s;
    cin >> s;
    set<char> se;
    for(int i = 0; i < s.size(); i++){
        se.insert(s[i]);
    }
    if(se.count('a') !=0 && se.count('b') !=0 && se.count('c') !=0){
        cout <<"Yes" << endl;    
    }else{
        cout <<"No" << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    int n,x,max=0;
    cin >> n >> x;
    vector<int> m(n);
    for(int i = 0; i < n; i++){
        cin >> m[i];
        max += m[i];
    }
    x -= max;
    sort(m.begin(),m.end());
    int count = n;
    while(x - m[0] >= 0){
        count++;
        x -= m[0];
    }
    cout << count;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	
	if (N * A < B) {
		cout << N * A << endl;
	}
	else if (N * A > B) {
		cout << B << endl;
	}
	else cout << B << endl;
}

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

signed main(){
  int n;
  cin >> n;
  
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  
  map<char,int> list;
  rep(i,n) list[ s[i][0] ]++;
  
  vector<int> num(5);
  num[0] = list['M'];
  num[1] = list['A'];
  num[2] = list['R'];
  num[3] = list['C'];
  num[4] = list['H'];
  
  int ans = 0;
  for(int i=0;i<5;i++){
    for(int j=i+1;j<5;j++){
      for(int k=j+1;k<5;k++){
        ans += num[i]*num[j]*num[k];
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

  

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll H,W,M,i,j,y,x;scanf("%lld%lld%lld",&H,&W,&M);
  ll TH[H] = {},TW[W] = {};pair<ll,ll> B[M];
  for(i=0;i<M;i++){
    scanf("%lld%lld",&y,&x);y--;x--;
    B[i] = make_pair(y,x);
    TH[y]++;TW[x]++;
  }
  set<ll> MH,MW;ll nh = 0,nw = 0;
  for(i=0;i<H;i++){
    if(TH[i] > nh){
      set<ll>({i}).swap(MH);
      nh = TH[i];
    }
    else if(TH[i] == nh) MH.insert(i);
  }
  for(i=0;i<W;i++){
    if(TW[i] > nw){
      set<ll>({i}).swap(MW);
      nw = TW[i];
    }
    else if(TW[i] == nw) MW.insert(i);
  }
  ll ans = nh+nw,cnt = MH.size()*MW.size();
  if(cnt > M){
    printf("%lld\n",ans);return 0;
  }
  for(i=0;i<M;i++){
    if(MH.count(B[i].first) && MW.count(B[i].second)) cnt--;
  }
  printf("%lld\n",cnt > 0 ? ans:ans-1);
}

Measured memory_bytes: 41160
S = input()
N = len(S)

cnt = 0
ans = 0
for i in range(N):
    if cnt >= 1:
        if S[i] == 'g':
            ans += 1
        cnt -= 1
    else:
        if S[i] == 'p':
            ans -= 1
        cnt += 1
    
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>


int main(void){
    //nとttの読み取り
    int n, tt;
    scanf("%d %d", &n, &tt);
    //cとtの読み取り
    int i;
    int c[n], t[n];
    for(i = 0 ; i < n ; i++){
        scanf("%d %d", &c[i], &t[i]);
    }
    //計算
    int c_min;
    c_min = 1001;
    for(i = 0 ; i < n ; i++){
        if(t[i] <= tt){
            if(c[i] < c_min){
                c_min = c[i];
            }
        }
    }
    //表示
    if(c_min == 1001){
        printf("TLE\n");
    }
    else{
        printf("%d\n", c_min);
    }

    return 0;
}

Measured memory_bytes: 128
S=input()
V=[]
ans=0
num=[-1]*len(S)
for s in S:
	if len(V)==0 or V[-1][0]!=s:
		V.append([s,1])
	else:
		V[-1][1] += 1
if len(V)==1:print(V[0][1]*(V[0][1]+1)//2);exit()
c=len(V)
if V[0][0]==">":
  ans+=V[0][1]*(V[0][1]+1)//2
  del V[0]
  c-=1
if V[-1][0]=="<":
  ans+=V[-1][1]*(V[-1][1]+1)//2
  del V[-1]
  c-=1

for i in range(c//2):
  M=max(V[2*i][1],V[2*i+1][1])
  m=min(V[2*i][1],V[2*i+1][1])
  ans+=M*(M+1)//2+m*(m-1)//2
print(ans)

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	int x,y;
	cin>>x>>y;
	int A,B,C;
	A= x+y;
	B=x-y;
	C=x*y;
	int ans =max(max(A,B),C);
	cout<<ans<<endl;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0;
  vector<pair<int,int>> a(5);
  for(int i=0;i<5;i++){
    cin>>a.at(i).second;
    a.at(i).first=a.at(i).second%10;
  }
  sort(a.begin(),a.end());
  int i;
  for(i=0;i<5;i++)
    if(a.at(i).first!=0)break;
  for(int j=0;j<5;j++){
    if(j<=i)ans+=a.at(j).second;
    else ans=ans+a.at(j).second-a.at(j).first+10;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256