akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 100000
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int m,int n)
{
    n=n%(m-1);
    a=a%m;
    int res=1;
    while(n>0)
    {
        if(n&1) res=(res*a)%m;
        a=(a*a)%m;
        n>>=1;
    }
    return res;
}



void solve()
{
    int t,n,m,i,k,l,r,u,v,w,j,s,pos,sum=0,flag=0,count=0;
    string S,T,U;
    // int h1,m1,h2,m2;
    cin>>n>>m;
    cout<<n*m;
}



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


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    
    int N = 0;
    cin >> N;
    if (N % 1000 == 0) {
        cout << 0;
        return 0;
    }
    cout << 1000 - (N % 1000) << endl;

    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	vector<int> v(n);
	for (int i=0; i<n; i++)
		cin>>v[i];
	sort(v.begin(),v.end(),greater<int>());
	long long ans=v[0];
	long long m=n-2;
	for (int i=0; i<m; i++)
	   ans+=v[i/2+1];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); i++)
 
int main() {
  string s,t,ans;
  ans="No";
  cin>>s>>t;
  int tn=t.size();
  int sn=s.size();
  int co=0;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  rep(i,min(sn,tn)){
    if(t[i]-s[i]>0){
      ans="Yes";
      break;
    }
    if(t[i]==s[i]){
      co++;
    }
  }
  if(co==min(tn,sn)&&sn<tn){
    ans="Yes";
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    x = I()
    if 30<=x:
        print('Yes')
    else:
        print('No')
    exit()

Measured memory_bytes: 27092
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<pair<pair<int,int>,bool>> red(N),blue(N);
  REP(i,N){
    int a,b;cin>>a>>b;
    red[i]={make_pair(b,a),false};
  }
  REP(i,N){
    int a,b;cin>>a>>b;
    blue[i]={make_pair(a,b),false};
  }
  sort(rALL(red));
  sort(ALL(blue));

  int ans=0;

  REP(i,N){
    REP(j,N){
      if(blue[i].first.first>red[j].first.second && blue[i].first.second>red[j].first.first && (!red[j].second)){
        red[j].second=true;
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    vector<int> a;
    int count = 0;

    cin >> n;

    rep(i,n){
        int tmp;
        cin >> tmp;
        

        if(tmp == count + 1){
            count++;
        }
    }

    if(count == 0){
        cout << -1 << endl;
    }else{
        cout << n - count << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <functional>
using namespace std;
using T=tuple<int64_t,int>;

int main(){
    int64_t N,X;
    cin>>N>>X;
    vector<int64_t> B(N),L(N),U(N);
    for(int i=0;i<N;i++){
        cin>>B[i]>>L[i]>>U[i];
    }
    vector<T> V;
    for(int i=0;i<N;i++){
        V.emplace_back(U[i]*(X-B[i])+L[i]*B[i],i);
    }
    sort(V.begin(), V.end(),greater<T>());
    function<bool(int64_t)> test = [&](int64_t sum){
        int64_t total=0;
        for(int i=0;i<N;i++){
            int idx;
            tie(ignore,idx)=V[i];
            if(i<(sum+X-1)/X){
                total+=U[idx]*(X-B[idx]);
            }else{
                total+=-L[idx]*B[idx];
            }
        }
        if(sum%X==0){
            return total>=0;
        }
        int64_t maximum=-10000000000000;
        for(int i=0;i<N;i++){
            int idx;
            tie(ignore,idx)=V[i];
            int64_t diff = max(U[idx]*(sum%X-B[idx]),L[idx]*(sum%X-B[idx]));
            if(i<(sum+X-1)/X){
                maximum = max(maximum, total-U[idx]*(X-B[idx])+diff);
            }else{
                int edge = get<1>(V[(sum+X-1)/X-1]);
                maximum = max(maximum, total-U[edge]*(X-B[edge])-L[edge]*B[edge]+L[idx]*B[idx]+diff);
            }
        }
        // cout<<sum<<' '<<maximum<<' '<<total<<endl;
        return maximum>=0;
    };
    int64_t lb=0,ub=X*N;
    while(ub-lb>1){
        int64_t mid=(lb+ub)/2;
        if(test(mid)){
            ub=mid;
        }else{
            lb=mid;
        }
    }
    if(lb==0&&test(lb)){
        cout<<lb<<endl;
    }else{
        cout<<ub<<endl;
    }
    return 0;
}

Measured memory_bytes: 5748
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main(void) {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(n);
	vector<int> b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for (int j = 0; j < m; j++) {
		cin >> b[j];
	}

	ll t = 0;
	for (int i = 0; i < m; i++) {
		t += b[i];
	}

	int j = m;
	int ans = 0;
	for (int i = 0; i < n + 1; i++) {
		while (j > 0 && t > k) {
			--j;
			t -= b[j];
		}
		if (t > k) {
			break;
		}
		ans = max(ans, i + j);
		if (i == n) {
			break;
		}
		t += a[i];
	}
	cout << ans << endl;
	return 0;
}



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

int main() {
    int N, X, L, D = 0, ans = 1;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> L;
        D += L;
        if (D <= X) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long A[100010]={0},B[100010]={0};
int main(){
	int N;
	cin>>N;
	for(int i=0;i<=N;i++){
		cin>>A[i];
	}//怪兽 
	for(int i=0;i<N;i++){
		cin>>B[i];
	}//英雄 
	long long ans=0;
	for(int i=0;i<N;i++){
	    int sen=B[i]-A[i];
		if(A[i]>B[i]){
			ans=ans+B[i];
		}else{
			ans=ans+A[i];
			if(sen>=A[i+1]){
				ans=ans+A[i+1];
				A[i+1]=0;
			}else{
				ans=ans+sen;
				A[i+1]-=sen; 
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;



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

	cin >> N;
	if (N & 1) {
		vector<vector<int>>v(N + 1, vector<int>(N + 1));
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				v[i][j] = 1;
				ans++;
			}
		}
		for (int i = N; i > 0; i--) {
			v[i][N - i] = 0;
			if (i < N - i)ans--;
		}
		cout << ans << endl;
		for (int i = 0; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (v[i][j])cout << i << " " << j << endl;
			}
		}
		return 0;
	}
	vector<vector<int>>v(N + 1, vector<int>(N + 1));
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			v[i][j] = 1;
			ans++;
		}
	}
	for (int i = N; i > 0; i--) {
		v[i][N - i + 1] = 0;
		if (i < N - i+1)ans--;
	}
	cout << ans << endl;
	for (int i = 0; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			if (v[i][j])cout << i << " " << j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
/*
* author:  shenqihao
* created: 2020-08-15 (Sat)
*/
//#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
#define mod 1000000007
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0;
	string s;
	cin >> n >> s;
	vector<int> dp(1);
	dp[0] = 1;
	for (int i = 1; i < n; i++) {
		vector<int> new_dp(i + 1);
		int sum = 0;
		if(s[i-1]=='<')
			for (int j = 0; j < i; j++) {
				sum = (sum + dp[j]) % mod;
				new_dp[j + 1] = sum;
			}
		else
			for (int j = i - 1; j >= 0; j--) {
				sum = (sum + dp[j]) % mod;
				new_dp[j] = sum;
			}
		dp = new_dp;
	}
	for (int i = 0; i < n; i++) ans = (ans + dp[i]) % mod;
	cout << ans;
	return AC;
}

Measured memory_bytes: 3808
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Console;

class Program
{
  static void Main() => new Program().solve();

  void solve()
  {
    const long mod = 1000000007;
    var n = int.Parse(ReadLine());
    var s = ReadLine();
    var table = new long['z' - 'a' + 1];
    foreach(var ch in s)
    {
      table[ch - 'a']++;
    }

    var ans = table.Aggregate(1L, (acc, i) => i > 0 ? acc * (i+1) % mod : acc) - 1;
    WriteLine(ans);
  }
}

Measured memory_bytes: 13408
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	bool f1=false,f2=false;
	for(int i=0;i<s.length();i++)
	{
		 if(s[i]=='C') f1=true;
		 if(f1==true && s[i]=='F') f2=true; 
	}
	if(f2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const long double pi=3.14159265359;
 
int main()
{
 int t=1;
 //cin>>t;
 while(t--)
 {double r;
  cin>>r;
  cout<<2*pi*r;
//   printf()
 }
 return 0;
}

Measured memory_bytes: 3792
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val ss = next()

    var max = 0
    for (i in 1 until ss.length-1) {
        val left = ss.take(i).toList().distinct()
        val right = ss.takeLast(ss.length-i).toList().distinct()

        var cnt = 0
        left.forEach {
            if (it in right) cnt++
        }
        if (cnt > max) max = cnt
    }

    println(max)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 2000;
ll a[N], mn[N];

void solve() {
  int n, x; cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mn[i] = 1e9;
  }
  ll ans = 1e18;
  for (int cnt = 0; cnt < n; cnt++) {
    for (int i = 0; i < n; i++) {
      int ni = (i - cnt + n) % n;
      mn[i] = min(mn[i], a[ni]);
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
      res += mn[i];
    }
    ans = min(ans, res + cnt * 1LL * x);
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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

vector<bool> seen;
vector<bool> vertex;
inline bool cycle (const vector<vector<int>>& g, int v) {
    seen[v] = true;
    vertex[v] = true;
    bool flag = false;
    for (auto u : g[v]) {
        if (seen[u]) return true;
        if (vertex[u]) continue;
        if (cycle(g, u)) flag = true;
    }
    seen[v] = false;
    return flag;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    seen.resize(n); vertex.assign(n, false);
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        scanf("%d%d", &s, &t);
        g[s].emplace_back(t);
    }
    
    bool ans = false;
    for (int s = 0; s < n; s++) if (!vertex[s]) {
        fill(seen.begin(), seen.end(), false);
        if (cycle(g, s)) { ans = true; break; }
    }
    
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <fstream>
#include <algorithm>
//#define LOCAL
using namespace std;
typedef long long ll;
const int mx=1e3+10;
ll num[mx];


int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n;
cin>>n;
for(ll i=0;i<n;i++) cin>>num[i];
ll qn;
cin>>qn;
for(ll i=1;i<=qn;i++){
    ll b, e, t;
    cin>>b>>e>>t;
    ll k=e-b;
    for(ll d=0;d<k;d++){
        swap(num[b+d], num[t+d]);
    }
}
for(ll i=0;i<n;i++){
    if(0==i) printf("%lld", num[i]);
    else printf(" %lld", num[i]);
}
puts("");

#ifdef LOCAL
fin.close();
#endif // LOCAL
}




Measured memory_bytes: 3232
INF=10**30
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
ans=[]
point=0
for i in range(D):
    d=i+1
    res=-INF
    z=-1
    for j in range(26):
        p=s[i][j]
        for k in range(26):
            if k==j:
                continue
            p-=c[k]*(d-last[k])
        res=max(res,p)
        if res==p:
            z=j
    ans.append(z+1)
print(*ans,sep='\n')

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

typedef long long LL;

int N, A, B, C;
int l[10] = {0};

//合成魔法を使わない場合のmpを計算
int calcmp1(vector<int> v){
	int mp = 1000 * 3;
	int s[10] = {0}, t[10] = {0}, u[10] = {0};
	for(int i = 0; i <= v.size(); i++){
		s[i] = abs(v[i] - A);
		t[i] = abs(v[i] - B);
		u[i] = abs(v[i] - C);
	}

	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v.size(); j++){
			if(j == i) continue;
			for(int k = 0; k < v.size(); k++){
				if(k == i || k == j) continue;
				int v = s[i] + t[j] + u[k];
				if(v < mp){
					mp = v;
				}
			}
		}
	}
	return mp;
}

int bitCount(int b){
	int u = b;
	int ret = 0;
	while(u > 0){
		ret += u % 2;
		u = u / 2;
	}
	return ret;
}

//uを4進数で見たときの右からn桁目の値 (nは0から)
int getDigit4(int u, int n){
	int v = u;
	int ret = v % 4;
	for(int i = 0; i < n; i++){
		v = v / 4;
		ret = v % 4;
	}
	return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> A >> B >> C;
	for(int i = 0; i < N; i++){
		int u;
		cin >> u ;
		l[i] = u;
	}

	//合成魔法を使わない場合の最小値
	vector<int> v;
	for(int i = 0; i < N; i++){
		v.push_back(l[i]);
	}
	int mp1 = calcmp1(v);

	//合成魔法を使う場合
	int ans = mp1;
	for(int e = 0; e < 65536; e++){ // 4**8 = 65536
		v.clear();
		vector<int> a, b, c, d;
		int s = 0, t = 0, u = 0;
		for(int i = 0; i < N; i++){
			int k = getDigit4(e, i);
			if(k == 0){ //Aを構成する竹にする
				a.push_back(l[i]);
				s += l[i];
			}
			else if(k == 1){ //Bを構成する竹にする
				b.push_back(l[i]);
				t += l[i];
			}
			else if(k == 2){ //Cを構成する竹にする
				c.push_back(l[i]);
				u += l[i];
			}
			else if(k == 3){ //それ以外
				d.push_back(l[i]);
				v.push_back(l[i]);
			}
		}
		if(s == 0 || t == 0 || u == 0){ continue; }
		v.push_back(s);
		v.push_back(t);
		v.push_back(u);
		int mp2 = max((int)a.size() - 1, 0) * 10 ; //合成魔法のmpは10
		mp2 += max((int)b.size() - 1, 0) * 10;
		mp2 += max((int)c.size() - 1, 0) * 10;
		mp2 += calcmp1(v);
		if(mp2 < ans){ ans = mp2; }
	}
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n,a,b,c,x;

    while(cin >> n >> a >> b >> c >> x){
        if((n|a|b|c|x) == 0) break;

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

        int pos=0;
        int ret=-1;
        for(int i=0;i<10001;i++){
            if(x == num[pos]){
                pos++;
            }
            if(pos == n){
                ret = i;
                break;
            }
            x = (a*x+b)%c;
        }
        cout << ret << endl;
    }
}

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

long long l,sd[45],r,br,cnt;
vector<int> poz;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);

    cin>>l;
    sd[0]=1;
    int ind=1;
    for(int i=1;i<45;i++)
    {
        sd[i]=sd[i-1]*2;
        if(sd[i]>l&&ind)
        {
            r=i-1;
            ind=0;
        }
    }
    for(int i=0;i<r;i++)
        if((1<<i)&l)
            br++;
    cout<<r+1<<" "<<2*r+br<<endl;
    for(int i=1;i<r+1;i++)
    {
        cout<<i<<" "<<i+1<<" "<<0<<endl;
        cout<<i<<" "<<i+1<<" "<<sd[i-1]<<endl;
    }
    cnt=1<<r;
    for(int i=0;i<r;i++)
    {
        if((1<<i)&l)
        {
            cout<<i+1<<" "<<r+1<<" "<<cnt<<endl;
            cnt+=(1<<i);
        }
    }

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e13;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, a[500];
int memo[500][500];
int check[500][500];
itn SUM[500];

int f(int x, int y) {
    if (x + 1 == y)
        return 0;
    if (check[x][y])
        return memo[x][y];
    check[x][y] = 1;
    int ret = INF;
    FOR(i, x + 1, y) {
        chmin(ret, f(x, i) + f(i, y));
    }
    ret += SUM[y] - SUM[x];

    return memo[x][y] = ret;
}

void solve() {
    cin >> N;
    FOR(N)
    cin >> a[i];
    FOR(i, 1, N + 1)
    SUM[i] = SUM[i - 1] + a[i - 1];

    cout << f(0, N) << endl;
}

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


    solve();
    return 0;
}


Measured memory_bytes: 3456
//Keep Working Hard
  // I__Like__Food
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 305
  #define INF 1e16
  const double PI = acos(-1);

int32_t main()
{


    int n,m;
    cin >> n >> m;

    
    cout << n*(n-1)/2 + m*(m-1)/2;



    

  return 0;
} 

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  
  double X[8],Y[8];
  rep(i,n) cin>>X[i]>>Y[i];
  
  double sum=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      sum+=sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]));
    }
  }
  
  cout<< fixed << setprecision(15) << sum*2/n <<endl;

  return 0;
}

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

using namespace std;
typedef unsigned long long ull;

const ull MOD = 1000000007;
const int M = 13;

int main()
{
    string S;
    cin >> S;
    int N = S.length(), num, mul = 1;

    vector<vector<ull>> dp(N);

    for (int i = N - 1; i > -1; i--)
    {
        dp.at(i).resize(M);
        if (S.at(i) == '?')
        {
            if (i == N - 1)
            {
                for (int j = 0; j < 10; j++)
                {
                    ++dp[i][j];
                }
            }
            else
            {
                for (num = 0; num < 10; num++)
                {
                    for (int k = 0; k < M; k++)
                    {
                        dp[i][(num * mul + k) % M] += dp[i + 1][k];
                        dp[i][(num * mul + k) % M] %= MOD;
                    }
                }
            }
        }
        else
        {
            num = S.at(i) - '0';
            if (i == N - 1)
            {
                ++dp[i][num];
            }
            else
            {
                for (int k = 0; k < M; k++)
                {
                    dp[i][(num * mul + k) % M] += dp[i + 1][k];
                    dp[i][(num * mul + k) % M] %= MOD;
                }
            }
        }
        mul *= 10;
        mul %= M;
    }

    cout << dp[0][5] << endl;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,a;
    while (cin>>n>>m) {
        if (n==0&&m==0) {
            break;
        } else {
            std::deque<int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            int max=0;
            for (int j=0;j<n-1;j++) {
                for (int k=j+1;k<n;k++) {
                    if (deq[j]+deq[k]<=m) {
                        if (deq[j]+deq[k]>max) {
                            max=deq[j]+deq[k];
                        }
                    }
                }
            }
            if (max!=0) {
                cout<<max<<endl;
            } else {
                cout<<"NONE"<<endl;
            }
        }
    }
}



Measured memory_bytes: 3100
#include<stdio.h>
#include<vector>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<math.h>
typedef long long lnt;
lnt f[410],p[410],t[410],pp[410];
int l[410],r[410];
const lnt mod=1e9+7;
int main(){
	int n,c,k,i,j;
	lnt x;
	scanf("%d%d",&n,&c);
	f[0]=1;
	for(k=1;k<=n;k++){
		scanf("%d",&l[k]);
	}
	for(k=1;k<=n;k++){
		scanf("%d",&r[k]);
	}
	for(k=1;k<=n;k++){
		memset(t,0,sizeof(t));
		memset(pp,0,sizeof(pp));
		for(i=l[k];i<=r[k];i++){
			p[0]=1;
			for(j=1;j<=c;j++){
				p[j]=p[j-1]*i;
				p[j]%=mod;
			}
			for(j=0;j<=c;j++){
				pp[j]+=p[j];
				pp[j]%=mod;
			}
		}
		for(i=0;i<=c;i++){
			for(j=0;j<=i;j++){
				t[i]+=f[j]*pp[i-j];
				t[i]%=mod;
			}
		}
		for(i=0;i<=c;i++){
			f[i]=t[i];
		}
	}
	printf("%I64d\n",f[c]);
}

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

int main() {
  
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  int ans = 0;
  if(a > k) ans += k;
  else {
    ans+= a; 
    k -= a;
  }
  if(b < k) {
    ans -= (k - b);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
n = int(input())
a = []
for i in range(n - 1):#h:高さ
    a.append([int(m) for m in input().split()])

cp = 0
for i in range(n):
    if i == n - 1:
        print(0)
    else:
        for j in range(i, n - 1):
            if cp == 0:
                k = a[j][1] + a[j][0]
            else:
                if k < a[j][1]:
                    k = a[j][1]
                    k += a[j][0]
                else:
                    if (k - a[j][1]) % a[j][2] == 0:
                        r = 0
                    else:
                        r = a[j][2] - (k - a[j][1]) % a[j][2]
                    k += a[j][0]
                    k += r
            cp = 1
        print(k)
        cp = 0

Measured memory_bytes: 3188
def main():
    N = int(input())
    C = [0] * N
    T = 0
    for i in range(N):
        A, B = map(int, input().split())
        C[i] = A + B
        T += A
    C.sort(reverse=True)
    print(T - sum(C[1::2]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 47192
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


vector<int> ng;
bool can(int s, int g) {
    for (int x : ng) {
        if (s <= x && x <= g) return false;
    }
    return true;
}

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, n) {
        if (s[i] == '#') {
            cnt++;
            continue;
        }
        if (cnt >= 2) ng.push_back(i - cnt);
        cnt = 0;
    }
    if (cnt >= 2) ng.push_back(n - cnt);
    cnt = 0;
    int min_change = -1;
    for (int i = b-1; i < n; i++) {
        if (s[i] == '.') {
            cnt++;
            continue;
        }
        if (cnt >= 3) {
            min_change = i - cnt;
            cnt = 0;
            break;
        }
        cnt = 0;
    }
    if (cnt >= 3) min_change = min(min_change, n - cnt);

    if (!(can(a, c) && can(b, d))) {
        puts("No");
        return 0;
    }

    if (c < d) {
        puts("Yes");
        return 0;
    }

    if (min_change == -1 || min_change > d-1) {
        puts("No");
        return 0;
    }

    if (can(min_change + 2, c) && can(min_change + 1, d)) puts("Yes");
    else puts("No");

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());
  cout << as.back() - as.front() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hh   puts("");
#define db double
#define ull unsigned long long
#define maxn 1000010

int main(){
    int a,b;
    cin>>a>>b;
    if(a%b==0)cout<<a/b;
    else cout<<a/b+1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string> vec_w(n);
    int len;
    bool flag=false;
    for(int i=0;i<n;i++){
        cin >> vec_w.at(i);
        if(i!=0){
            len =vec_w.at(i-1).size();
            if(vec_w.at(i-1).at(len-1)!=vec_w.at(i).at(0)){
                flag = true;
                break;
            }
            for(int j=0;j<i;j++){
                if(vec_w.at(j)==vec_w.at(i)){
                    flag = true;
                    break;
                }
            }
        }
    }
    if(flag ==true){
        cout << "No"<< endl;
    }else{
        cout <<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int C[1100];
vector<int> V[1100];

int main(){
    int N,t;
    cin>>N;
    bool flag=false;
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            cin>>t; t--;
            V[i].push_back(t);
        }
    }
    queue<int> que;
    int count=N,temp=0;
    for(int i=0;i<N;i++) que.push(i);

    for(int i=0;;i++,flag=false){
        int h[1100];
        memset(h,-1,sizeof(h));

        for(int k=0;k<count;k++){
            int j=que.front(); que.pop();
            if(C[j]==N-1 || h[j]==0) continue;
            int x=V[j][C[j]];
            if(V[x][C[x]]==j && h[x]==-1){
                temp+=2;
                que.push(j); que.push(x);
                //cout<<i<<" "<<j<<" "<<x<<endl;
                h[x]++; h[j]++;
                C[j]++; C[x]++;
                flag=true;
            }
        }
        count=temp; temp=0;
        if(!flag){
            for(int i=0;i<N;i++){
                //cout<<C[i]<<endl;
                if(C[i]!=N-1){
                    cout<<-1<<endl;
                    return 0;
                }
            }
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4352
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 2 ** 61 - 1
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    cnt = collections.defaultdict(int)
    ans = 0
    S = [SI() for _ in range(N)]
    for s in S:
        h = 0
        for i in range(len(s)-1,0,-1):
            h = (h * 27 + ord(s[i]) - ord('a') + 1) % MOD
        cnt[h] |= 1<<(ord(s[0])-ord('a'))

    for s in S:
        a = []
        bit = 0
        for x in s:
            x = ord(x) - ord('a')
            bit |= 1 << x
            a.append(bit)
        h = 0
        for i in range(len(s)-1,0,-1):
            ans += bin(cnt[h] & a[i]).count('1')
            h = (h * 27 + ord(s[i]) - ord('a') + 1) % MOD

    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 274960
/**
 * author: BueVonHun 🐼🎋
 * More Info: https://github.com/Bue-von-hon
**/

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>

typedef long long ll;
using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
template<class T> void read(T& x) {cin >> x;}

int test_case;
int main(void) {
    fast_cin();

    int n,d, count=0;
    cin >> n >> d;

    for (int i = 0; i < n; i++) {
        double x,y,distance;
        cin >> x >> y;
        distance = sqrt(pow(x,2)+pow(y,2));
        if (distance<=d)
            count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<vector<Int> > G(n);
  for(Int i=0;i<m;i++){
    Int u,v;
    cin>>u>>v;
    u--;v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  vector<Int> used(n,-1);
  Int cnt=0,flg=0;
  function<void(Int)> dfs=[&](Int v){
    cnt++;
    for(Int u:G[v]){
      if(~used[u]){
	flg|=~(used[v]-used[u])&1;
      }else{
	used[u]=used[v]+1;
	dfs(u);
      }
    }
  };
  Int x=0,y=0,z=n;
  for(Int i=0;i<n;i++){
    if(~used[i]) continue;
    cnt=flg=used[i]=0;
    dfs(i);
    if(cnt!=1){
      z-=cnt;
      if(flg) y++;
      else x++;
    }
  }
  Int ans=n*n-(n-z)*(n-z);
  ans+=(x+y)*(x+y);
  ans+=x*x;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 13312
#include<bits/stdc++.h>
#define ll long long 

using namespace std;

int main()
{
    
    
    
    ll a = 0,b = 0,c = 0;cin >> a >> b >> c;
    cout << min(min(min(min(min(a+b,b+c),a+c),b+c),a+c),b+c);
    
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#define MAX 8

using namespace std;

struct Field{
	int base[MAX*2][MAX*2],*tmp[MAX*2],**val;
};

int	die[3][4]={{2,4,5,3},{1,3,6,4},{1,5,6,2}};
Field	rank,top;

void cvt(Field*);
void fall(int,int,int,int);
void rot(int []);

int main(void){
	int	n,t,f,nums[6];

	cvt(&rank);
	cvt(&top);

	do{
		cin >> n;

		if(n!=0){
			memset(rank.base,0,sizeof(rank.base));
			memset(top.base,0,sizeof(top.base));
			memset(nums,0,sizeof(nums));

			for(int i=0;i<n;i++){
				cin >> t >> f;
				fall(0,0,t,f);
			}

			for(int i=0;i<MAX*2;i++)
				for(int j=0;j<MAX*2;j++)
					if(top.base[i][j])
						nums[top.base[i][j]-1]++;

			for(int i=0;i<5;i++)
				cout << nums[i] << " ";
			cout << nums[5] << endl;
		}
	}while(n>0);
}

void cvt(Field *fld){
	for(int i=0;i<MAX*2;i++)
		(*fld).tmp[i]=&(*fld).base[i][MAX];
	(*fld).val=&(*fld).tmp[MAX];
}

void fall(int x,int y,int t,int f){
	int	sel,cur[5],nxt=4;
	bool	torb,dr[4];

	sel=(t<4?t:7-t)-1;
	torb=t<4;
	cur[4]=0;

	while(die[sel][torb?0:3]!=f)
		rot(die[sel]);
	for(int i=0;i<4;i++){
		cur[i]=die[sel][torb?i:3-i];
		dr[i]=cur[i]>3&&rank.val[x][y]>(i%2==0?rank.val[x][y+i-1]:rank.val[x+i-2][y]);
	}

	for(int i=0;i<4;i++)
		if(dr[i]&&cur[i]>cur[nxt])
			nxt=i;

	if(nxt==4){
		rank.val[x][y]++;
		top.val[x][y]=t;
	}
	else
		fall(nxt%2==0?x:x+nxt-2,nxt%2==0?y+nxt-1:y,7-cur[nxt],(nxt%2!=0?f:(nxt==0?t:7-t)));
}

void rot(int dice[]){
	int tmp=dice[0];
	for(int i=0;i<3;i++)
		dice[i]=dice[i+1];
	dice[3]=tmp;
}

Measured memory_bytes: 1160
import math
from functools import reduce
from collections import defaultdict

#素因数分解O(√n)
def primeFactor(n):
    res = defaultdict(lambda: 0)
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            res[i] += 1
            n = n // i
    if n != 1:
        res[n] += 1
    return res

    

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

def gcd(*numbers):
    return reduce(math.gcd, numbers)

MOD = 10**9+7
GCD = gcd(*A)

P = defaultdict(lambda: 0)

for i in range(N):
    factors = primeFactor(A[i])
    for k, v in factors.items():
        if v > P[k]:
            P[k] = v


P_mod = 1
for k in P.keys():
    P_mod = P_mod*(k**P[k])%MOD

ans = 0
for i in range(N):
    b = A[i]
    mod_inv = pow(b, MOD-2, MOD)
    ans = (ans + P_mod * mod_inv) % MOD

print(ans)




Measured memory_bytes: 10828
#include<iostream> 
#include<vector>
using namespace std ;
typedef long long ll ;
#define rep(i,n) for(int i = 0 ; i < n ;i++ )

const int MOD = 1000000007;

int main(){
    int n ;cin >> n ;
    ll A[n] ;
    rep(i,n) cin >> A[i] ;
    ll ans = 0 ;
    rep(i,60){
        ll x  = 0 ;
        rep(j,n) if(A[j]>>i&1) ++x ;
        ll now = x * ( n - x ) % MOD ;
        rep(j,i) now = now * 2 % MOD  ;
        ans += now ;
        ans %= MOD ;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    h = readInt()
    dp = [INF for i in range(n+1)]
    dp[1] = 0
    for i in range(1,n+1):
        for j in range(i+1,i+3):
            if j>n:
                continue
            dp[j] = min(dp[j],dp[i] + abs((h[j-1]-h[i-1])))
    print(dp[n])
    return

if __name__=='__main__':
    main()


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

int n, k, ans;
int a[1000000];
vector<int> v, t;
set<int> s;

int main(){
    cin >> n >> k;
    s.insert(k);
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        s.insert(a[i]);
    }
    set<int>::iterator it;
    for (it = s.begin(); it != s.end(); it++) v.push_back(*it);
    ans = v[1] - v[0];
    for (int i = 2; i < v.size(); i++){
        ans = __gcd(ans, v[i] - v[i-1]);
    }
    cout << ans;
}

Measured memory_bytes: 6012
import sys
from collections import deque

input = sys.stdin.readline
H,W=map(int,input().rstrip().split())
maze=[list(input().rstrip()) for i in range(H)]
def resolve():
    seen=[[0 for i in range(W)] for j in range(H)]
    ans=0
    for i in range(H):
        for j in range(W):
            if maze[i][j]=="#":
                continue
            #maze[k][l]=1#end
            buf=bfs(maze,seen,i,j)
            ans=max(ans,buf)
            seen = [[0 for i in range(W)] for j in range(H)]
            #maze[k][l]="."
    print(ans)

def bfs(maze, seen, sh, sw): #sh,swはスタート
    stack = deque([[sh, sw]])
    seen[sh][sw] = 1
    expandcount=0#今のdepthに展開されたノードを親ノードとしたときの子ノードの数
    expanded=-1#今のdepthに展開されたノード数、最初は-1にする
    popcount=0#popした数、今のdepthでの探索回数
    depth=0#ルートからの深さ
    while stack:
        h, w = stack.popleft()
        popcount+=1
        
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue

            elif maze[new_h][new_w] != "#" and  seen[new_h][new_w] == 0:#未発見
                seen[new_h][new_w] = 1#発見済みにする
                stack.append([new_h, new_w])#隣接を探索予定に
                expandcount+=1

        if popcount==expanded or expanded==-1:#今のdepthが全て探索済みなら、下のdepthの探索に移る
            expanded=expandcount
            popcount=0
            expandcount=0
            depth+=1

    return depth-1
"""
    for i in range(H):
        for j in range(W):
            if(S[i][j]=="#"):
                for dir in range(4):
                    nx=j+dx[dir]
                    ny=i+dy[dir]

                    if(nx<0 or nx>=W):
                        continue
                    if(ny<0 or ny>=H):
                        continue

                    if(S[i][j]==S[ny][nx]):
                        break
                else:
                    print("No")
                    return
    print("Yes")
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
...
...
..."""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 5
...#.
.#.#.
.#..."""
        output = """10"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    int p = 1;
    for(int i=0;i<m;i++){
        p *= 2;
    }
    cout << (100*n+1800*m)*p << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define nMax 1000000000
int main(void){
    int min,i,t,n,rMax;
    min = nMax;
    rMax = -10000000000;
    scanf("%d",&t);
    scanf("%d",&min);	
    for(i=1;i<t;i++){
        scanf("%d",&n);
        if(n-min > rMax)rMax = n-min;
    	if(n < min)min = n;
    }
printf("%d\n",rMax);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n/2) {
        if(s[i]!=s[n-i-1]) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

const MaxBuf = 200100

var sc = bufio.NewScanner(os.Stdin)
var buf []byte = make([]byte, MaxBuf)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, MaxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	var h int
	h, _ = readInt(), readInt()
	s := make([]string, h)
	for i := 0; i < h; i++ {
		s[i] = readString()
		fmt.Println(s[i])
		fmt.Println(s[i])
	}
}


Measured memory_bytes: 640
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input()) - 1])

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m,a,b,c,i,j,x,y;
    cin>>n>>m>>c;
    int arr[n][m],brr[m];
    i=a=0;
    while(i<m) {
      cin>>brr[i];
      i++;
    }
    i=0;
    while(i<n) {
      j=0;
      b=c;
      while(j<m) {
        cin>>arr[i][j];
        j++;
      }
      i++;
    }
    i=0;
    while(i<n) {
      j=0;
      b=c;
      while(j<m) {
        x=arr[i][j];
        y=brr[j];
        b+=(x*y);
        j++;
      }
      if(b>0)
        a++;
      b=c;
      i++;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()

#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	
	string s; cin>>s;
	vector<ll> dp(2019);
	ll answer = 0;
	for(char c: s){
		vector<ll> new_dp(2019);
		rep(i, 2019){
			new_dp[(i * 10 + (c - '0')) % 2019] += dp[i];
		}
		new_dp[c - '0']++;
		answer += new_dp[0];
		dp = new_dp;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 3784
//
//  main.cpp
//  Product Max
//
//  Created by Bryan on 13/09/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    long long a,b,c,d;
    scanf ("%lld %lld %lld %lld",&a,&b,&c,&d);
    long long max = a*c;
    if (a*d>max)
        max = a*d;
    if (b*c>max)
    max = b*c;
    if (b*d>max)
        max = b*d;
    printf ("%lld\n",max);
}


Measured memory_bytes: 3820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int minhalf=0;
		int N = sc.nextInt();
		int K = sc.nextInt();
		int map[][]=new int[N+1][K+1];
		for(int i=1;i<=N;i++) 
			map[i][sc.nextInt()]=1;
		
		for(int i=1;i<=N;i++) 
			for(int j=1;j<=K;j++) 
				if		(	map[i][j]==1 && j <  (K - j)  )	minhalf += j;
				else	 if	(	map[i][j]==1 && j >= (K - j)  )	minhalf += (K-j);
		System.out.println(minhalf * 2);
	}

}


Measured memory_bytes: 22864
#include <stdio.h>

int main(void)
{
	int n;
	scanf("%d", &n);

	int i, t[101], sum = 0;
	for(i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		sum += t[i];
	}

	int j, m, p, x;
	scanf("%d", &m);
	for(i = 0; i < m; i++) {
		scanf("%d %d", &p, &x);
		printf("%d\n", sum + x - t[p - 1]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<int, int, int> t3i;

template <class T>
struct BIT {
    int NN;
    vector<T> data;

    BIT(int N, T default_value) {
        NN = N;
        data = vector<T>(NN + 1, default_value);
    }

    void add_at(int idx, T val) {
        for (int i = idx + 1; i <= NN; i += (i & (-i))) {
            data[i] += val;
        }
    }

    T sum_to(int idx) { // [0, idx]
        T res = 0;
        for (int i = idx + 1; i >= 1; i -= (i & (-i))) {
            res += data[i];
        }
        return res;
    }

    T sum_in(int l, int r) { // [l, r]
        return sum_to(r) - sum_to(l - 1);
    }
};


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

    int N, Q;
    cin >> N >> Q;
    
    auto C = vector<int>(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }

    auto queries = vector<vector<t3i>>(N, vector<t3i>());
    for (int i = 0; i < Q; i++) {
        int l, r; 
        cin >> l >> r;
        l--; r--;
        queries[r].push_back({i, l, r});
    }

    auto ans = vector<int>(Q, -1);
    auto V = *max_element(C.begin(), C.end());
    auto last = vector<int>(V + 1, -1);
    
    auto bit = BIT<int>(N, 0);
    for (int i = 0; i < N; i++) {
        if (last[C[i]] != -1) {
            bit.add_at(last[C[i]], -1);
        }
        bit.add_at(i, +1);
        last[C[i]] = i;
        for (auto&& [id, l, r]: queries[i]) {
            ans[id] = bit.sum_in(l, r);
        }
    }

    for (auto x : ans) {
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 34192