akhauriyash/Code-Regression huggingface dataset:
/*     *******************Bismillahir Rahmanir Rahim************************
                          MD. ASFAKUL GHANI!
                          *ProMAGFAT*!
 SECRET_warning :)->FAT   CSE-25!
                          JAHANGIRNAGAR UNIVERSITY!
                          Dhaka,Bangladesh!
*/

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

#define           fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define           Im int main()
#define           ll long long
#define           sc scanf
#define           pf printf
#define           rn0 return 0
#define           rn return
#define           f0(i,n) for(ll i=0;i<n;i++)
#define           f1(i,n) for(ll i=1;i<=n;i++)
#define           f2(i,n) for(ll i=n-1;i>=0;i--)
#define           pi 2*acos(0.0)
#define           modulo 1000003
#define           dd double
#define           PI 3.14159265358979
#define           pi 2*acos(0.0)
#define           p_b push_back
#define           ps push

/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/

void debug1()
{
    cout << "***" << endl;
}

void debug11(ll n)
{
    cout << n << endl;
}

ll m,n;
vector <ll> v1[101010];
ll in_dg[101010];
bool vis[101010];
stack <ll> s1;

void FAT_dfs(ll u)
{
    vis[u] = 1;
    vector <ll> ::iterator it;
    for (it = v1[u].begin(); it != v1[u].end(); it += 1){
           if (!vis[*it]) FAT_dfs(*it);
    }
    s1.ps(u);
}

void FAT_topSort()
{
   memset(vis,0,sizeof(vis));
   for (ll i = 0; i < n; i += 1){
        if (!vis[i]){
            FAT_dfs(i);
        }
   }
   while (!s1.empty()){
      cout << s1.top() << endl;
      s1.pop();
   }
}

Im
{
    /*#ifdef FAT
       freopen("input.txt","w",stdin);
    #endif // FAT*/

    fasterIO;

    cin>>n>>m;

    for (ll i = 0; i < m; i += 1){
        ll u,v;
        cin>>u>>v;
        v1[u].p_b(v);
    }

    FAT_topSort();

   // main();

    rn0;
}

Measured memory_bytes: 6348
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>

using namespace std;

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

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)

#define      sc1(x)                     scanf("%lld",&x);
#define      sc2(x,y)                   scanf("%lld %lld", &x, &y)
#define      scf1(x)                    scanf("%lf",&x)
#define      scf2(x,y)                  scanf("%lf %lf", &x, &y)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


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

int main()
{
    // Faster;



    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    test
    {
        string s;

        cin >> s;

        if(s[0] == 'A')
        {
            ac++;
        }
        if(s[0] == 'W')
        {
            wa++;
        }
        if(s[0] == 'T')
        {
            tle++;
        }
        if(s[0] == 'R')
        {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}






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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	map<ll,ll> mp;
	FOR(i,1,1000)
	{
		mp[i*(i+1)/2] = i;
	}
	ll a,b;
	cin>>a>>b;
	ll ans = 1;
	for(ans = 1;ans<=499500;ans++)
	{
		ll t1 = a+ans;
		ll t2 = b+ans;
		if(mp[t1]&&mp[t2]&&mp[t2]-mp[t1] == 1)
		{
			cout<<ans<<Endl;
			return 0;
		}
	}
	return 0;
} 


Measured memory_bytes: 34528
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main( void )
{
	int e;
	while(cin >> e, e) {
		bool hit = false;
		int answer = 1000001;
		for(int z=100; z > -1 && !hit; --z) {
			int sum_z = z * z * z;
			if(sum_z == e) { answer = z; break; }
			else if(sum_z > e) continue;
			else {
				int y = (int)sqrt((double)(e - sum_z));
				int sum_zy = sum_z + y * y;
				answer = min(answer, (z + y + e - sum_zy));
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
d = {}
while True:
    try:
        w, n = input().split()
        n = int(n)
        temp = d.get(w, [])
        temp.append(n)
        d[w] = temp
    except:
        key = list(d.keys())
        key.sort()
        for k in key:
            print(k)
            d[k].sort()
            for n in range(len(d[k])):
                if n != 0: print(' ', end='')
                print(d[k][n], end='')
            print('')
        break

Measured memory_bytes: 6716
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

ll M = 1000000007;

int digit(int x){
	if(x == 0)return 0;
	if(x < 10)return 1;
	return digit(x/10)+1;
}

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k%2 == 1){ ret *= x; ret %= M; }
	return ret;
}

ll inv(ll x){
	return modpow(x,M-2);
}

ll C[202][202];
void C_init(){
	rep(i,202){
		C[i][0] = 1;
		rep1(j,i){
			C[i][j] = C[i][j-1]*(i-j+1); C[i][j] %= M;
			C[i][j] *= inv(j); C[i][j] %= M;
		}
	}
}

ll F[202],G[202];
void FG_init(){
	rep(x,202){
		F[x] = 0;
		G[x] = 0;
		ll a = 1;
		rep(i,x+1){
			F[x] += a;
			G[x] += a*(i+1);
			if(i < x){ a *= x-i; a %= M; }
		}
		F[x] %= M;
		G[x] %= M;
	}
}

ll H[202];
void H_init(){
	H[0] = 1;
	rep1(i,201){
		H[i] = H[i-1]*i;
		H[i] %= M;
	}
}

ll N[802];
void N_init(){
	N[0] = 1;
	rep1(i,801){
		N[i] = N[i-1]*10;
		N[i] %= M;
	}
}

int main(){
	C_init();
	FG_init();
	H_init();
	N_init();
	int n;
	int a[202];
	scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	
	int dig[202];
	rep(i,n)dig[i] = digit(a[i]);
	
	int c[5] = {};
	int sum[5] = {};
	rep(i,n){
		c[dig[i]] ++;
		sum[dig[i]] += a[i];
	}
	
	ll ret = 0;
	rep1(d,4){
		if(c[d] == 0)continue;
		c[d] --;
		int b[5];
		b[0] = 0;
		for(;b[0]<=c[0];b[0]++){
			b[1] = 0;
			for(;b[1]<=c[1];b[1]++){
				b[2] = 0;
				for(;b[2]<=c[2];b[2]++){
					b[3] = 0;
					for(;b[3]<=c[3];b[3]++){
						b[4] = 0;
						for(;b[4]<=c[4];b[4]++){
							ll ret_ = 1;
							rep(i,5){ ret_ *= C[c[i]][b[i]]; ret_ %= M; }
							ret_ *= H[b[0]+b[1]+b[2]+b[3]+b[4]]; ret_ %= M;
							ret_ *= N[b[0]+b[1]+2*b[2]+3*b[3]+4*b[4]]; ret_ %= M;
							if(c[0]-b[0] == 0){ ret_ *= F[c[0]+c[1]+c[2]+c[3]+c[4]-b[0]-b[1]-b[2]-b[3]-b[4]]; ret_ %= M; }
							else { ret_ *= G[c[1]+c[2]+c[3]+c[4]-b[1]-b[2]-b[3]-b[4]]; ret_ %= M; }
							ret += ret_*sum[d];
							ret %= M;
						}
					}
				}
			}
		}
		c[d] ++;
	}
	
	cout << ret << endl;
}
	

Measured memory_bytes: 3568
import sys


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    s = sum(p[:k])
    max_sum = s
    for i in range(k, n):
        s += p[i]
        s -= p[i - k]
        max_sum = max(max_sum, s)
    print((k + max_sum) / 2)


if __name__ == "__main__":
    main()


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

int main() {
    int n;
    cin >> n;
    vector<P> red(n);
    vector<P> blue(n);
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        red[i] = {a,b};
    }
    rep(i,n) {
        int c,d;
        cin >> c >> d;
        blue[i] = {c,d};
    }
    sort(blue.begin(),blue.end());
    auto judge = [&](P bl,P re) {
        return re.first < bl.first && re.second < bl.second;
    };
    int ans = 0;
    vector<bool> used(n,false);
    for(auto bl : blue) {
        int maxy = -1;
        int now;
        rep(i,n) {
            if(used[i]) continue;
            if(judge(bl,red[i])) {
                if(red[i].second > maxy) {
                    now = i;
                    maxy = red[i].second;
                }
            }
        }
        if(maxy != -1) {
            used[now] = true;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<x<<" "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2e5+10, maxn = 1e6+5;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const ll mod =  998244353;

int n, m, k;

void solve()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i) {
        scanf("%d", &k);
        n -= k;
    }
    if(n<0) n = -1;
    printf("%d\n", n);
}


int main()
{
//    int _; scanf("%d", &_); while(_--)
//    while(~scanf("%d%d", &n, &d))
//    while(~scanf("%lld", &n))
    solve();
    return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N,ans=0; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++) {
		ans += a[i]-1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m;
  while(cin>>n>>m,n){
    int used[501]={},a[501][501]={};
    r(i,m){
      int x,y;
      cin>>x>>y;
      a[x][y]=a[y][x]=1;
    }
    int sum=0;
    used[1]=1;
    vector<int>v;
    r(i,501)if(a[1][i])v.push_back(i),sum++,used[i]=1;
    r(i,v.size())r(j,501)if(a[j][v[i]])
      if(!used[j])sum++,used[j]=1;
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 4116
#include <iostream>
using namespace std;
int main(){
    string t = "CODEFESTIVAL2016";
    string s; cin >> s;
    int c = 0;
    for(int i = 0; i < t.size(); i++) {
        if(t[i] != s[i]) c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    long N, x, a, b, n=0;
    cin >> N >> x >> a;
    for (long i=1; i<N; i++){
        cin >> b;
        if (a + b > x ){
            n += a + b - x;
            if (x - a >= 0){
                b = x - a;
            }else{
                b = 0;
            }
        }
        a = b;
        //cout << n << endl;
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3608
from heapq import heappush, heappop


def dijkstra():
    g = n - 1
    heap = [(-x, 0, 0)]  # estimate(cost-height), cost, tree
    visited = [float('inf')] * n
    while heap:
        est, cost, tree = heappop(heap)
        h = cost - est
        if tree == g:
            return cost + trees[tree][0] - h
        if visited[tree] <= est:
            continue
        visited[tree] = est
        for t, tree2 in trees[tree][1]:
            ht = trees[tree2][0]
            if t > h:
                new_cost = cost + t + t - h
                new_h = 0
            elif h - t > ht:
                new_cost = cost + h - ht
                new_h = ht
            else:
                new_cost = cost + t
                new_h = h - t
            new_est = new_cost - new_h
            if visited[tree2] >= new_est:
                heappush(heap, (new_est, new_cost, tree2))
    return -1


n, m, x = map(int, input().split())
trees = [[int(input()), set()] for i in range(n)]
for _ in range(m):
    a, b, t = map(int, input().split())
    a -= 1
    b -= 1
    if trees[a][0] >= t:
        trees[a][1].add((t, b))
    if trees[b][0] >= t:
        trees[b][1].add((t, a))
print(dijkstra())

Measured memory_bytes: 155744
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}


int main() {

	int n;
	ll x,a[4002];
	ll t[2001];

	cin>>n>>x;
	rep(i,n){
		cin>>a[i];
		a[n+i]=a[i];
		t[i]=INF;
	}
	ll ans=INF;
	rep(i,n){
		ll total=0;
		for(int j=n; j<n*2; j++){
			t[j-n]=min(t[j-n],a[j-i]);
			total+=t[j-n];
		}
		ans=min(ans,total+i*x);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,T,pre;
	int A[3000],B[3000];
	int time[6001]={0};
	int max=0;
	cin>>N>>T;
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	for(int i=0;i<N-1;i++){
		for(int j=0;j<N-i-1;j++){
			if(A[j]>A[j+1]){
				pre=A[j];
				A[j]=A[j+1];
				A[j+1]=pre;
				pre=B[j];
				B[j]=B[j+1];
				B[j+1]=pre;
			}
		}
	}
	for(int i=0;i<N;i++){
		for(int j=T-1;j>=0;j--){
			if((j==0||time[j]!=0)&&time[j+A[i]]<time[j]+B[i]){
				time[j+A[i]]=time[j]+B[i];
				if(time[j+A[i]]>max)max=time[j+A[i]];
			}
		}
	}
	cout<<max;
	return 0;
}

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


int main() {
    int n, a, b;
    cin >> n >> a >> b;
    printf("%d %d\n", min(a,b), max(0, a+b-n));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

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

ll mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector <ll> l(n);
    rep(i, n){
        cin >> l[i];
    }
    sort(ALL(l));
    
    ll res = 0;
    ll a, b, c;
    rep(i, n){
        a = l[i];
        For(j, i+1, n){
            b = l[j];
            ll aminusb = abs(a - b);
            ll aplusb = a+b;
            For(k, j+1, n){
                c = l[k];
                
                if(aminusb < c && c < aplusb){
                    res ++;
                }
            }
        }
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000000;
const int INF = 2000000000; //1e9 * 2
const double EPS = 1e-7;
const double PI = acos(-1.0);

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

//start

int* table[5010];

int main(){
	FOR(i,5010) table[i] = (int*)calloc((i+3),sizeof(int));

	int n,m; cin>>n>>m;
	FOR(i,m){
		int a,b,x; cin>>a>>b>>x;
		a--; b--;
		table[a][b]++;
		table[a][b+1]--;
		table[a+x+1][b+x+2]++;
		table[a+x+1][b]--;
		table[a+x+2][b+1]++;
		table[a+x+2][b+x+2]--;
	}
	
	//右
	FOR(i,n+2) FOR(j,i+1) table[i][j+1] += table[i][j];
	//下
	FOR(i,n+1) FOR(j,i+1) table[i+1][j] += table[i][j];
	//右下
	FOR(i,n+1) FOR(j,i+1) table[i+1][j+1] += table[i][j];


	int ans = 0;
	FOR(i,n) FOR(j,i+1) ans += table[i][j] > 0;
	cout << ans << endl;

	return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>>a(h, vector<char>(w));
	for (size_t i = 0; i < h; i++) {
		for (size_t j = 0; j < w; j++)cin >> a.at(i).at(j);
	}
	vector<int>fh, fw;
	for (int i = 0; i < h; i++) {
		bool f = false;
		for (int j = 0; j < w; j++) {
			if (a.at(i).at(j) == '#')f = true;
		}
		if (f == false)fh.push_back(i);
	}
	for (int i = 0; i < w; i++) {
		bool f = false;
		for (int j = 0; j < h; j++) {
			if (a.at(j).at(i) == '#')f = true;
		}
		if (f == false)fw.push_back(i);
	}
	for (int i = 0; i < h; i++) {
		if (count(fh.begin(), fh.end(), i))continue;
		else {
			for (int j = 0; j < w; j++) {
				if (count(fw.begin(), fw.end(), j))continue;
				else cout << a.at(i).at(j);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long ul;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const double pi = acos(-1);

//....................................................................................................................//



int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(10);
    ll n, m;
    cin >> n >> m;
    if (n % 2)
        for (int i = 0; i < m; ++i) {
            cout << i + 1 << sep << n - i << endl;
        }
    else {
        for (int i = 0; i < min(m, n / 4); ++i) {
            cout << i + 1 << sep << n - i << endl;
        }
        for (int i = n / 4; i < m; ++i) {
            cout << i + 1 << sep << n - i - 1 << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int main(){
  int h,w;
  int x[8]={1,0,-1,0,1,-1,-1,1};
  int y[8]={0,1,0,-1,1,1,-1,-1};
  string s[60];
  cin>>h>>w;
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
    if(s[i][j]=='#') continue;
    int cnt=0;
    for(int k=0;k<8;k++){
      int dx=i+x[k];
      int dy=j+y[k];
      if(0>dx || 0>dy || dx>=h || dy>=w) continue;
      if(s[dx][dy]=='#') cnt++;
    }
    s[i][j]=char(cnt+'0');
  }
}
for(int i=0;i<h;i++) cout<<s[i]<<endl;



}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int search(vi &s, int n){
  int left = -1, right = s.size();
  while(left + 1 < right){
    int middle = (left + right) / 2;
    if(s[middle] >= n) right = middle;
    else left = middle;
  }
  return left;
}
int main(){
  int n;
  cin >> n;
  vi l(n);
  rep(i, n) cin >> l[i];
  sort(all(l));
  int ans = 0;
  for(int a = 0; a < n - 2; a++){
    for(int b = a + 1; b < n - 1; b++){
      int num = search(l, l[a] + l[b]);
      if(num != -1 || num != a || num != b) ans += max(0, num - b);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll H[100000]{ 0 };
ll C[100000]{ 0 };
int main() {
    ll N, M;
    //ll A[100000]{ 0 };
    //ll B[100000]{ 0 };
    
    cin >> N >> M;

    rep(i,N) {
        cin >> H[i];
    }
    rep(i,M) {
        ll tmpA, tmpB;
        cin >> tmpA >> tmpB;
        if (H[tmpA -1]<H[tmpB -1]) {
            C[tmpA - 1] = 1;
        }
        else if (H[tmpB - 1] < H[tmpA - 1]) {
            C[tmpB - 1] = 1;
        }
        else {
            C[tmpA - 1] = 1;
            C[tmpB - 1] = 1;
        }
    }
    ll count = 0;
    rep(i,N) {
        if (C[i] == 0)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 5156
//https://www.youtube.com/watch?v=83yW2Pp6HMk&t=200s
#include <bits/stdc++.h>

using namespace std;
using ll = long long;


const int mod = 2019;


void solve()
{
	string s;
	cin >> s;
	const int n = s.length();
	long long suff = 0, ans = 0, p = 1;
	vector<int> cnt(mod, 0);
	cnt[suff]++; //Case of empty suffix
	for (int i = n - 1; i >= 0; i--)
	{
			suff = (suff + (s[i]-'0') * p) % mod;
			p = (p * 10) % mod;
			ans += cnt[suff];
			cnt[suff]++;
	}
	cout << ans << endl;
}
int main()
{
	
	solve();
	
	return 0;
}


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

#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pair<int,int>>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define inf         INT_MAX
#define llinf       LLONG_MAX

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

using namespace std;
void solve()
{
    string s;
    cin>>s;
    if(s[sz(s)-1]=='s')s+="es";
    else s+="s";
    cout<<s;
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

typedef long long ll;
#define endl '\n'
#define inf 0x3f3f3f3f+1

ll n, w;
//c[i] -> weight of i-th item
//v[i] -> val of i-th item
ll c[102], v[102];
ll dp[103][100005];

//dp[a][b] -> minimum weight to achieve val=b, using itens 1 to a

ll peso(int i, int val){
  //no item is required to achieve val<=0, so minimum weight is 0
  if(val<=0) return 0;
  //with zero itens,  it is impossible to achieve any val, so minimum weight is inf
  if(i==0) return inf;
  //dp memo
  if(dp[i][val]!=-1) return dp[i][val];
  //choose whether to pick an item or not
  return dp[i][val]=min(peso(i-1, val), peso(i-1, val-v[i]) + c[i]);
}

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

  cin >> n >> w;
  for(int i=1; i<=n; i++) cin >> c[i] >> v[i];

  for(int i=1; i<=n; i++){
    for(int j=1; j<=100000; j++){
      dp[i][j]=-1;
    }
  }

  //find max val whose minimum weight required is less than or equal to capacity
  for(int val=100000; val>=0; val--) {
    if(peso(n, val)<=w){
      cout << val << endl;
      break;
    }
  }

/*
  for(int i=1; i<=n; i++){
    for(int j=1; j<=17; j++){
      if(dp[i][j]==inf) cout << "inf" << "\t";
      else cout <<  dp[i][j] << "\t";
    }
    cout << endl;
  }
  */
}

Measured memory_bytes: 79360
M = input().split()

a = int(M[0])
b = int(M[1])

x = 10 * b
ans = -1


while (x < 10 * (b + 1)) and (ans == -1):
  if int(x * (1 / 10)) != b:
    x += 1
  else:
    ans = x

ans = -1

if x < (a + 1) * (25 / 2):
  while (x < (a + 1) * (25 / 2)) and (ans == -1 ):
    if int(x * (2 / 25)) == a:
      ans = x
    else:
      x += 1

  if int(x * (1 / 10)) == b:
    ans = x
  else:
    ans = -1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << (a - c) *(b - d);
	

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 2 != 0) ans++;
  }
  double p = (double)ans / (double)N;
  cout << fixed << setprecision(10) << p << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s[] = new String[n];
		for(int i=0; i<n; i++){
			s[i] = sc.next();
		}
		int m = sc.nextInt();
		String t[] = new String[m];
		for(int i=0; i<m; i++){
			t[i] = sc.next();
		}
		int num = 0;
		int sco = 0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(s[i].equals(s[j]))num++;
			}
			for(int k=0; k<m; k++){
				if(s[i].equals(t[k]))num--;
			}
			if(num>sco)sco = num;
			num = 0;
		}
		System.out.println(sco>0? sco : 0);
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

using namespace std;

int main(void){
  string str;
  int sum=0;
  while(cin>>str){
    int next=0;
    rep(i,str.size()){
      if('0'<=str[i]&&str[i]<='9'){
	if('0'<=str[i+1]&&str[i+1]<='9'){
	  next = next * 10 + (str[i] - '0') ;
	  //	  cout<<next<<" "<<str[i]<<endl;
	}else if('0'<=str[i-1]&&str[i-1]<='9' || !('0'<=str[i+1]&&str[i+1]<='9')){
	  
	  //	  cout<<next*10+str[i]-'0'<<endl;
	  sum+=next*10+str[i]-'0';next=0;
	}
      }
    }

  }
  cout<<sum<<endl;
}

Measured memory_bytes: 1184
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt() - 1;
    int y = sc.nextInt() - 1;
    
    int[] ans = new int[n];
    int k;
    
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        k = Math.min(Math.abs(i-x)+1+Math.abs(j-y),j-i);
        ans[k] += 1;
      }
    }
    
    
    for(int i=1;i<n;i++){
      System.out.println(ans[i]);
    }

  }
}

Measured memory_bytes: 24404
S2 = input()
T = input()

S_all = []
for i in range(len(S2) - len(T) + 1):
    tmp = S2[i: i+len(T)]

    flag = True
    for j in range(len(tmp)):
        if tmp[j] != '?' and tmp[j] != T[j]:
            flag = False
            break

    if flag:
        S_tmp = S2[:i] + T + S2[i+len(T):]
        S = ''

        for k in range(len(S_tmp)):
            if S_tmp[k] == '?':
                S += 'a'
            else:
                S += S_tmp[k]

        S_all.append(S)

if len(S_all) == 0:
    print('UNRESTORABLE')
else:
    S_all.sort()
    print(S_all[0])


Measured memory_bytes: 3064
import functools

MOD = 1000000007

fact = [None] * 300000
fact[0] = 1
for i in range(1, 300000):
    fact[i] = (i * fact[i - 1]) % MOD

def comb(h, w):
    numer = fact[h - 1 + w - 1]
    denom = (fact[h - 1] * fact[w - 1]) % MOD
    # print('numer, denom =', numer, denom)

    return (numer * pow(denom, MOD - 2, MOD)) % MOD

H, W, A, B = map(int, input().split())
ans = 0
for h in range(H - A):
    x = comb(h + 1, B)
    y = comb(H - h, W - B)
    # print(x, y)
    ans += x * y
    ans %= MOD
print(ans)


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

int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n];
  rep(i,n){
    cin >> a[i];b[i]=a[i];
  }
  sort(a,a+n);
  //cout << a[n-1] << endl;
  rep(i,n){
    if(b[i]==a[n-1])cout<<a[n-2]<<endl;
    else{cout << a[n-1] << endl;}
  }
}


Measured memory_bytes: 3200
n,t=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab_r=list(reversed(ab))

dp1=[[0 for j in range(t)] for i in range(n+1)]
dp2=[[0 for j in range(t)] for i in range(n+1)]

for i in range(n):
    for j in range(t-1):
        if ab[i][0] <= j:
            dp1[i+1][j] = max(dp1[i][j],dp1[i][j-ab[i][0]]+ab[i][1])
        else:
            dp1[i+1][j] = dp1[i][j]
            
        if ab_r[i][0] <= j:
            dp2[i+1][j] = max(dp2[i][j],dp2[i][j-ab_r[i][0]]+ab_r[i][1])
        else:
            dp2[i+1][j] = dp2[i][j]
            
m=0
for i in range(1,n+1):
    for j in range(t-1):
        m=max(m,dp1[i-1][j]+dp2[n-i][t-1-j]+ab[i-1][1])
print(m)


Measured memory_bytes: 195992
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[150];
long long sum;
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        sum=0;
        for(i=0;i<n;i++)
        {
            sum+=(n-i)*a[i];
        }
        printf("%lld\n",sum);
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

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

int main(){

    int N,A,B;
    cin>>N>>A>>B;

    cout << min(A,B) <<" "<<max(0,A+B-N)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




typedef long long ll;
#define MOD 1000000007
map<ll, int> enumpr(ll n) {
	map<ll, int> V;
	for (ll i = 2; i*i <= n; i++) while (n%i == 0) V[i]++, n /= i;
	if (n>1) V[n]++;
	return V;
}
//-----------------------------------------------------------------
int N;
int main() {
	cin >> N;

	map<int, int> m;
	rep(i, 2, N + 1) {
		auto e = enumpr(i);
		for (auto p : e) m[p.first] += p.second;
	}

	ll ans = 1;
	for (auto p : m) {
		ans = (ans * (p.second + 1)) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    
    
    length = sum(t)*2
    
    dp = [0]*(length+1)
    border = v[0]
    count = t[0]*2
    index = 0
    for i in range(length):
        dp[i+1] = min(dp[i]+0.5, border)
        count -= 1
        if i == length-1:
            break
        if count == 0:
            index += 1
            border = v[index]
            count = t[index]*2
    
    dp[length] = 0
    border = v[n-1]
    count = t[n-1]*2
    index = n-1
    for i in range(length, 0, -1):
        dp[i-1] = min([dp[i]+0.5, border, dp[i-1]])
        count -= 1
        if i == 0:
            break
        if count == 0:
            index -= 1
            border = v[index]
            count = t[index]*2
    
    ans = 0
    for i in range(length):
        ans += (dp[i]+dp[i+1])/4
        
    print(ans)
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 74664
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;

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

Measured memory_bytes: 3188
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;

int32_t target_x, target_y;
char S[8100];
std::vector<int32_t> move_x;
std::vector<int32_t> move_y;

std::unordered_map<int32_t,bool> dp[8000];
bool funcx(int32_t i, int32_t now)
{
	if (i == move_x.size()) { return now == target_x; }
	if (dp[i].count(now)) { return dp[i][now]; }
	return dp[i][now]=funcx(i + 1, now + move_x[i]) || funcx(i + 1, now - move_x[i]);
}
bool funcy(int32_t i, int32_t now)
{
	if (i == move_y.size()) { return now == target_y; }
	if (dp[i].count(now)) { return dp[i][now]; }
	return dp[i][now] = funcy(i + 1, now + move_y[i]) || funcy(i + 1, now - move_y[i]);
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> S>> target_x>> target_y;
	{
		auto iter_s = S;
		while (*iter_s == 'F') {
			--target_x;
			++iter_s;
		}
		bool xmode = true;
		while (*iter_s == 'T') {
			++iter_s; xmode = !xmode;
			int32_t count = 0;
			while (*iter_s == 'F') {
				++count;
				++iter_s;
			}
			if (xmode) { move_x.push_back(count); }
			else { move_y.push_back(count); }
		}
	}

	bool x = funcx(0, 0);
	for (auto& i : dp) { i.clear(); }
	if (x&&funcy(0, 0)) {
		out << "Yes\n";
	}
	else {
		out << "No\n";
	}

	return 0;
}
#endif


Measured memory_bytes: 160768
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::min;

fn main() {
    let nab: Vec<u64> = read_vec();
    let n = nab[0];
    let a = nab[1];
    let b = nab[2];

    if (b - a) % 2 == 0 {
        println!("{}", (b - a) / 2);
    } else {
        println!("{}", min((a + b - 1) / 2, n - (a + b - 1) / 2));
    }
}


Measured memory_bytes: 4352
import sys

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

def solve():
    readline = sys.stdin.readline
    H, W = map(int, readline().split())
    ch, cw = map(int, readline().split())
    dh, dw = map(int, readline().split())
    S = ['#'] * (W+2)
    for _ in range(H):
        S += ['#'] + list(readline().rstrip()) + ['#']
    S += ['#'] * (W+2)
    H += 2
    W += 2

    uf = UnionFind(H*W)
    for i in range(H*W):
        if S[i] == '#':
            continue
        for d in [-W, -1, 1, W]:
            if S[i+d] == '.':
                uf.union(i, i+d)

    now = ch*(W) + cw
    goal = dh*(W) + dw
    # print(now, goal)
    # print(uf.find(now), uf.find(goal))
    if uf.same(now, goal):
        print(0)
        return
    ans = 0
    q = set()
    q.add(now) 
    next_area = set() 
    visited = [False] * (H*W)

    # for i in range(H):
    #     print(S[6*i:6*i+6])
    while True:
        while q:
            x = q.pop()
            if x == goal:
                print(ans)
                return
            visited[x] = True
            for dy in [-2*W, -W, 0, W, 2*W]:
                for dx in [-2, -1, 0, 1, 2]:
                    xx = x + dy + dx
                    if 0 <= xx < W*H and S[xx] == '.' and not visited[xx]:
                        if uf.same(x, xx):
                            q.add(xx)
                        else:
                            next_area.add(xx)
        if next_area:
            q = next_area
            next_area = set()
        else:
            print(-1)
            return 
        ans += 1

if __name__ == '__main__':
    solve()


Measured memory_bytes: 157332
#include<string>
#include<cctype>
#include<iostream>
#include<map>
#include<sstream>
#include<cstdlib>

using namespace std;

map<int, int> val[128];
int size[128];
string s;

typedef string::const_iterator State;

char array_name(State &begin);
int number(State &begin);
int expression(State &begin);
void declaration(State &begin);
void program(State &begin);
void assignment(State &begin);

void assignment(State &begin)
{
  char name = array_name(begin);
  if(size[name] == -1) throw("assignment:allocate_error");
  begin++; // [
  int ret = expression(begin);
  if(ret >= size[name] ) throw("assignment:error");
  begin++; // ]
  begin++; // =
  int ret2 = expression(begin);
  begin++; // new_line
  val[name][ret] = ret2;
}


// assignment or declaration
void program(State &begin)
{
  int len =  s.length();
  bool flg = false;
  for(int i=0; i<len;i++)
  {
      if(s[i] == '=')
      {
        flg=true;
        break;
      }
  }
  if(flg) assignment(begin);
  else  declaration(begin);

}

void declaration(State &begin)
{
  char name = array_name(begin);
  begin++; // [
  int ret = number(begin);
  begin++; // ]
  begin++; // new_line
  size[name] = ret;
}

char array_name(State &begin)
{
  if(isalpha(*begin))
  {
    char name =  *begin;
    begin++;
    return name;
  }
  else
  {
    throw("array_name");
  } 
}

int number(State &begin)
{
  string s;
  while(isdigit(*begin))
  {
    s+= *begin;
    begin++;
  }
  return atoi(&s[0]);

}

int expression(State &begin)
{
  if(isdigit(*begin)){
    return number(begin);
  }

  else
  { 
    char name = array_name(begin);
    
    if(size[name] == -1) throw("error");

    if (*begin == '[')
    {
      begin++; // [
      int res = expression(begin);
      begin++; // ]
      if ( size[name] <= res || val[name].find(res)==val[name].end() ||  size[name] == -1) throw("error");
      return val[name][res];
    }
  }
}



int main()
{
  while(1)
  {
    // initial
    bool bug = false;
    for(int i=0; i<128;i++)
    {
      val[i].clear();
      size[i] = -1;
    }

    for(int set=1;;set++)
    {
      cin>>s;
      if(s == ".")
      {
        if ( set == 1 ) return 0;
        if(!bug) cout<<0<<endl;
        break;
      }
      
      State begin = s.begin();

      if(!bug)
      {
        try{
        program(begin);
        }
        catch(const char* mes)
        {
          bug = true;
          cout<<set<<endl;
        }
      }

    }

  }
}

Measured memory_bytes: 1312