akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];
ll d[1000000];

void addedge(int st, int ed, int co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

void dijkstra(int s) {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d + V + 10, llmax);
    d[s] = 0;
    que.push(pii(0, s));

    while (!que.empty()) {
        pii p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        int len = G[v].size();
        for (int i = 0; i < len; i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
}

int main() {
    while (1) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        V = 1 << N;
        int t[N][N + 1];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N + 1; j++) {
                cin >> t[i][j];
            }
        }
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < N; j++) {
                if ((i | (1 << j)) > i) {
                    int co = t[j][0];
                    for (int k = 0; k < N; k++) {
                        if ((i & (1 << k)) > 0) {
                            co = min(co, t[j][k + 1]);
                        }
                    }
                    addedge(i, (i | (1 << j)), co);
                }
            }
        }
        dijkstra(0);
        // for (int i = 0; i < V; i++) {
        //     cout << d[i] << " ";
        // }
        // cout << endl;
        // for (int i = 0; i < V; i++) {
        //     int len = G[i].size();
        //     for (int j = 0; j < len; j++) {
        //         cout << G[i][j].to << " " << G[i][j].cost << " ";
        //     }
        //     cout << endl;
        // }
        ll ans = d[(1 << N) - 1];
        cout << ans << endl;
        for (int i = 0; i < V; i++) {
            G[i].clear();
        }
    }
}



Measured memory_bytes: 34244
#include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,head,n) for(int i=(head);i<n;i++)
#define int long long
#define F first
#define S second
#define pb push_back
#define p2(n) (1<<(n))
#define lg2(n) __lg(n)
using namespace std;
using pii = pair<long long,long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);

int n;
int a[200010];

void solve(){
    cin >> n;
    rep(i,0,n)
        cin >> a[i];
    int sum = 0;
    rep(i,1,n){
        if(a[i]<a[i-1]){
            sum += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout << sum << '\n';
}

signed main(){
    Rushia_mywife
    solve();
}

Measured memory_bytes: 5220
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define DB double
#define M 400020
using namespace std;
int read(){
	int nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,tot,d[M];
DB ans,fs,ed,k,dt;
int main(){
	n=read(),fs=read(),k=read();
	ed=fs+k*(n*2-1);
	for(int i=(n<<1);i;i-=2){
		ans+=((fs+ed)/2.0);
		fs+=(fs*2+k*5)/(i*1.0); dt;
		ed+=dt=(ed*2-k*5)/(i*1.0); dt;
		if(i>2) k=(ed-fs)/((i-2)*1.0-1.0);
	}
	printf("%.17lf\n",ans);
	return 0;
}

Measured memory_bytes: 384
import math
A, B, H, M = map(int, input().split())
a = 0.5 * (H * 60 + M) % 360
b = 6 * (H * 60 + M) % 360
c = math.cos(math.radians(a-b))
C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * c)
print(C)


Measured memory_bytes: 9500
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

x = I()
print(x**3)


Measured memory_bytes: 5988
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    ll x;
    ll ans;
    ll mam = 100;
    cin >> x;
    for (ans = 0;mam  < x; ans++)
    {
        mam = (ll)mam*1.01;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


vector<char> a;

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;
  int left=0, right=0;
  FOR(i,0,SZ(S)-1){
    if(S[i]=='(') ++right;
    else{
      if(right==0) left++;
      else --right;
    }
  }

  string res = "";
  FOR(i,0,left-1) res += '(';
  res += S;
  FOR(i,0,right-1) res += ')';
  cout << res << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[3334],dp[3334][3334];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	for(int i=n-1;i>=0;i--){
		for(int j=i;j<n;j++){
			if((n-i-j-1)%2==0){//taro
				dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
			}
			else{//jiro
				dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}


Measured memory_bytes: 80128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
vector<li>a(3005);li n,n1=0,n2=0,n3=0,k;
li AA[3005][3005][2];
li ff(li i1,li i2,li i3){
    if(i2==i1) {if(i3==0) return(a[i1]);
    else return((-1)*a[i1]);}
    //if(i==0) return(0);
    if(AA[i1][i2][i3]!=-1) return(AA[i1][i2][i3]);    
    li ans;
if(i3==0){ans=max(a[i1]+ff(i1+1,i2,1),a[i2]+ff(i1,i2-1,1));}
else{ans=min(ff(i1+1,i2,0)-a[i1],ff(i1,i2-1,0)-a[i2]);}
AA[i1][i2][i3]=ans;return(ans);
}
int main(){readl(n);memset(AA,-1,sizeof(AA));li i;
for(i=0;i<n;i++) {cin>>a[i];}
li ans=ff(0,n-1,0);
cout<<ans;
}


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

int main(void){
    int r,c;
    cin >> r >>c;
    int a[r+1][c+1];
    for (int i=0; i<=r; i++) {
        for (int j=0 ; j<=c; j++) {
            a[i][j]=0;
        }
    }
    
    for (int i=0; i<r; i++) {
        for (int j=0 ; j<c; j++) {
            cin >> a[i][j];
        }
    }
    
    for (int i =0; i<r ; i++) {
        for (int j=0; j<c; j++) {
            a[i][c] += a[i][j];
        }
    }
    
    for (int j =0; j<c ; j++) {
        for (int i=0; i<r; i++) {
            a[r][j] += a[i][j];
        }
    }
    
    for (int i=0; i<r; i++) {
        for (int j=0; j<c ; j++) {
            a[r][c] += a[i][j];
        }
    }
    
    for (int i=0; i<=r; i++) {
        for (int j=0 ; j<=c; j++) {
            if(j!=c)cout << a[i][j]<<" ";
            else cout << a[i][j];
        }
        cout<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;


	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif
			 
	     	string a,b;
			 cin>>a>>b;

			if(b.size()-a.size()!=1)
			{
				cout<<"No"<<endl;
				return 0;
			}

			 bool flag=true;
			 for(ll i=0;i<b.size()-1;i++)
			 {
				 if(a[i]!=b[i])
				 flag=false;
			 }
			 if(flag)
			 cout<<"Yes";
			 else
			 cout<<"No"<<endl;

			 
			return 0;
		 }	
 

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

using namespace std;

#define ll  long long
#define vi  vector<int>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

int main(){

  int n;cin >> n;
  vi v;

  v.pb(0);
  rep(i,n){
  int a;cin >> a;
  v.pb(a);
  }
  v.pb(0);

  ll ans = 0;
  rep(i,v.size() - 1)  ans += abs(v[i + 1] - v[i]);

  for(int i = 1 ;i<v.size() - 1 ;i++){
    int num = abs(v[i-1] - v[i+1]) - abs(v[i] - v[i-1]) - abs(v[i] - v[i+1]);
    pr(ans + num);
  }

return 0;
}


Measured memory_bytes: 1784
import math

N, D = (int(x) for x in input().split())
X = []
for i in range(N):
    temp = [int(x) for x in input().split()]
    X.append(temp)

ans = 0

for i in range(N):
    for j in range(N):
        if j <= i:
            continue
        temp = 0
        for k in range(D):
            temp += pow((X[i][k] - X[j][k]), 2)
        
        temp = math.sqrt(temp)
        if temp == math.floor(temp):
            ans += 1

print(ans)

Measured memory_bytes: 3064
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 

int h[33];

inline void solve(){
	for (int i=1,p=1;i<=32;i++){
		if (i>=2) h[i] = h[i-2]+p;
		else h[i] = p; 
		p *= 2; 
	}
	int num;
    scanf("%lld",&num); 
    int i=1,c=0;
    int bit[32]={0},sum=0;
    if (num<0) i++,c=1; 
    num = abs(num);
    // 1 -2 4 -8 16 
    while (sum<num){
    	sum = h[i]; 
    	bit[i] = 1; 
    	if (sum<num) i += 2; 
    } 
    int l=i;
    for ( ;i>0;i--){
    	int p=pow(2,i-1);
    	if (sum - p >= num ){
    		sum -= p;
    		bit[i] = ((bit[i]==1)?0:1);
    	}
    }
    for (int i=l;i>0;i--) cout << bit[i] ; 
    cout << endl;
}

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


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

int main() {
    int N;
    cin >> N;
    string u;
    double ans, x;
    for (int i=0; i<N; i++) {
        cin >> x >> u;
        if (u=="JPY") ans+=x;
        else ans+=(x*380000.0);
    }
    cout << ans;
}

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

int n;
int p[200010], q[200010];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n; ++i){
		cin >> p[i];
		q[p[i]] = i;
	}
	int ma = 0;
	int t = -1;
	int s = 0;
	for(int i=1; i<=n; ++i){
		if(q[i] > t) ++s;
		else s = 1;
		t = q[i];
		ma = max(ma, s);
	}
	cout << n - ma << "\n";
}

Measured memory_bytes: 1792
"use strict";
function Main(input) {
    let In = new Inputer(input);
    let N = In.getInt(), M = In.getInt(), Q = In.getInt();
    let T = new Array(N+1).fill(0).map(() => new Array(N+1).fill(0));
    for (let m = 0; m < M; m++) {
        let l = In.getInt(), r = In.getInt();
        T[l][r] += 1;
    }
    for (let p = 1; p <= N; p++) {
        for (let q = 1; q <= N; q++) {
            T[p][q] += (T[p - 1][q] + T[p][q - 1] - T[p - 1][q - 1]);
        }
    }
    for (let n = 0; n < Q; n++) {
        let p = In.getInt(), q = In.getInt();
        console.log(T[q][q] - T[p - 1][q]);
    }
}
class Inputer {
    constructor (input) {
        this.cnt = 0;
        this.items = input.split(/\n|\s/);
    }
    getInt() {
        return this.items[this.cnt++] - 0;
    }
    getIntArray(N) {
        let array = new Array(N);
        for (let n = 0; n < N; n++) array[n] = getInt();
        return array;
    }
    getStr() {
        return this.items[this.cnt++];
    }
    getStrArray(N) {
        let array = new Array(N);
        for (let n = 0; n < N; n++) array[n] = getStr();
        return array;
    }
}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

bool dfs(int si, int sj, int i, int j, vector<vector<pair<int, int> > > a, vector<vector<bool> >& used, vector<vector<bool> > & used2){

    
    if(i == si && j == sj) return true;

    int nexti = a[i][j].first;
    int nextj = a[i][j].second;

    if(nexti == si && nextj == sj) {
        used[nexti][nextj] = true;
        return true;
    }

    used2[i][j] = true;
    if(used[nexti][nextj]) return false;
    if(used2[nexti][nextj]) return false;

    bool flag = dfs(si, sj, nexti, nextj, a, used, used2);

    if(flag){
        used[i][j] = true;
    }

    return flag;
}

int main(){
    
    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<vector<pair<int, int> > > a(n, vector<pair<int, int> > (n));

        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                int x, y; cin >> x >> y;
                a[i][j].first = y;
                a[i][j].second = x;
            }
        }

        vector<vector<bool> > used(n, vector<bool> (n, false));

        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(!used[i][j]){
                    int nexti = a[i][j].first;
                    int nextj = a[i][j].second;
                    if(used[nexti][nextj]) continue;
                    vector<vector<bool> > used2(n, vector<bool> (n, false));
                    used2[i][j] = true;
                    if(dfs(i, j, nexti, nextj, a, used, used2)){
                        ans++;
                        //cout << i << " " << j << endl;
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 19380
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int sum = 0;
  for (int i = 1; i <= n + 1; i++) {
    sum += abs(a[i] - a[i - 1]);
  }
  for (int i = 1; i <= n; i++) {
    int ret = sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]);
    cout << ret << '\n';
  }
  return 0;
}

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

int main(){
	int n;
  	cin >> n;
  	
  	ll ans = 0;
  	vector<int> d(n+1);
  	for(int i = 1;i <= n;i++){
    	for(int j = i; j <= n; j += i) d[j]++;
    }
  
  	for(int i = 1; i <= n; i++) ans += ll(i) * d[i];
  
  	cout << ans << endl;
}

Measured memory_bytes: 42308
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    bool f = false;
    rep(i, 0, n){
        char c;
        cin >> c;
        if(c == 'Y') f = true;
    }
    if(f) cout << "Four" << endl;
    else cout << "Three" << endl;
}

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

int main(){
    int N, n;
    cin >> N;
    n = N % 10;
    if(n == 3) cout << "bon\n";
    else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon\n";
    else cout << "hon\n";
}

Measured memory_bytes: 3556
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 200018
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n,m,q,ans=0;
struct Node{int a,b,c,d;}Q[51];
void XD(vector<int> v)
{
    if(v.size()==n+1)
    {
        int s=0;
        rep(i,1,q) if(v[Q[i].b]-v[Q[i].a]==Q[i].c) s+=Q[i].d;
        ans=max(ans,s);
        return;
    }
    v.pb(v.back());
    while(v.back()<=m)
    {
        XD(v);
        v.back()++;
    }
}
signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    cin>>n>>m>>q;
    rep(i,1,q) cin>>Q[i].a>>Q[i].b>>Q[i].c>>Q[i].d;
    vector<int> v={1};
    XD(v);
    cout<<ans;
}   

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const int MAX_N = 301100;
const int INF = 101100;

int N,K,L;

vector<int> RL[MAX_N];
vector<int> TL[MAX_N];
int r_visit[MAX_N];
int t_visit[MAX_N];
int ans;

void dfs_r(int v, int index){
    r_visit[v] = index;
    for(int i = 0; i < RL[v].size(); i++){
        int next = RL[v][i];
        if(r_visit[next] == INF){
            dfs_r(next, index);
        }
    }
}

void dfs_t(int v, int index){
    t_visit[v] = index;
    for(int i = 0; i < TL[v].size(); i++){
        int next = TL[v][i];
        if(t_visit[next] == INF){
            dfs_t(next, index);
        }
    }
}

void dfs(int v, bool road, bool train){
    if(train) t_visit[v] = train;
    if(road) r_visit[v] = road;
    if(r_visit[v] == t_visit[v] && t_visit[v] == true) ans++;

    if(train){
        for(int i = 0; i < TL[v].size(); i++){
            int next = TL[v][i];
            if(!t_visit[next]){
                dfs(next, false, train);
            }
        }
    }

    if(road){
        for(int i = 0; i < RL[v].size(); i++){
            int next = RL[v][i];
            if(!r_visit[next]){
                dfs(next, road, false);
            }
        }
    }
}

map<pair<int, int>, int> s;
int main(){
    cin >> N >> K >> L;
    REP(i,K){
        int p,q;
        cin >> p >> q;
        p--; q--;
        RL[p].push_back(q);
        RL[q].push_back(p);
    }
    REP(i,L){
        int r,s;
        cin >> r >> s;
        r--; s--;
        TL[r].push_back(s);
        TL[s].push_back(r);
    }

    int rindex = 0;
    int tindex = 0;
    fill(r_visit, r_visit+N, INF);
    fill(t_visit, t_visit+N, INF);
    for(int i = 0; i < N; i++){
        if(r_visit[i] == INF) dfs_r(i, rindex++);
        if(t_visit[i] == INF) dfs_t(i, tindex++);
    }
    for(int i = 0; i < N; i++){
        s[make_pair(r_visit[i], t_visit[i])]++;
    }
    for(int i = 0; i < N; i++){
        int ans = s[make_pair(r_visit[i], t_visit[i])];
        printf("%d ", ans);
    }
    printf("\n");
    return 0;
}


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

#define INF 1000000000
int main()
{
  int N, K;
  long min;
  cin >> N >> K;
  vector<long> h(N);
  for(int i = 0; i < N; i++)
    cin >> h[i];
  sort(h.begin(), h.end());
  min = INF;
  for(int i = 0; i < N - K + 1; i++){
    if(min > (h[i+K-1] - h[i]))
      min = h[i+K-1] - h[i];
  }
  cout << min;
}
    

Measured memory_bytes: 1024
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
using namespace std;
using ll = long long;
const int mod = 1000000007;

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

int main(){
    ll X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    vector<ll> A(X),B(Y),C(Z);
    for(ll i=0;i<X;i++)cin>>A[i];
    for(ll i=0;i<Y;i++)cin>>B[i];
    for(ll i=0;i<Z;i++)cin>>C[i];
    sort(A.begin(),A.end(),cmp);
    sort(B.begin(),B.end(),cmp);
    sort(C.begin(),C.end(),cmp);
    vector<ll> to_k;
    for(ll a=0;a<X;a++){
        for(ll b=0;b<Y;b++){
            to_k.push_back(A[a]+B[b]);
        }
    }
    sort(to_k.begin(),to_k.end(),cmp);
    priority_queue<ll> res;
    for(ll i=0;i<min(K,(ll)to_k.size());i++){
        for(ll j=0;j<Z;j++){
            res.push(to_k[i]+C[j]);
        }
    }
    for(ll i=0;i<K;i++){
        cout<<res.top()<<"\n";
        res.pop();
    }
}

Measured memory_bytes: 42884
package main

import (
	"fmt"
	"strconv"
)

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return (-a)
}

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

func main() {
	var S string
	fmt.Scan(&S)
	ans := 999
	for i := 0; i <= len(S)-3; i++ {
		num, _ := strconv.Atoi(S[i : i+3])
		ans = min(ans, abs(num-753))
	}
	fmt.Println(ans)
}


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

int main()
{
 int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v)
    cin>>i;
  sort(v.begin(),v.end());
  cout<<abs(v[n-1]-v[0])<<"\n";
  
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,a,b,c,t[101],d,e,f,dl,ans,nans,cal;
	
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	dl=a;
	scanf("%d",&c);
	cal=c;
	ans=cal/dl;
	for(d=0;d<n;d++){
		scanf("%d",&t[d]);
	}
	for(d=0;d<n;d++){
		for(e=d+1;e<n;e++){
			if(t[d]<=t[e])f=t[d],t[d]=t[e],t[e]=f;
		}
	}
	for(d=0;d<n;d++){
		cal+=t[d];
		dl+=b;
		nans=cal/dl;
		if(nans>=ans)ans=nans;else break;
	}
	printf("%d\n",ans);
	return 0;
} 

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    
    if(a>b)swap(a,b);
    
    int count = 0;
    
    for(int i=a; i>0; i--){
        if(a%i==0 && b%i==0)
            count++;
        
        if(count==k){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, V[20], C[20], i, value, kei = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &V[i]);
	}
	for (i = 0; i < N; i++) {
		scanf("%d", &C[i]);
	}

	for (i = 0; i < N; i++) {
		value = V[i] - C[i];
		if (value > 0) {
			kei = kei + value;
		}
	}

	printf("%d\n", kei);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll x, y, z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y <<endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
a, b = list(map(int, input().split(' ')))
s = input().strip()

ok = True

for i in range(a + b + 1):
    if i != a:
        if not s[i].isdigit():
            ok = False
    else:
        if s[i] != '-':
            ok = False
if ok:
    print('Yes')
else:
    print('No')

    


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

const LL mod=(1e9)+7;
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    LL mx=INF;
    REP(i,n)
    {
        cin>>a[i];
    }
    REP(i,101)
    {
        LL s=0;
        for(LL j=0;j<n;j++)
        {
            s+=(i-a[j])*(i-a[j]);
        }
        mx=min(s,mx);

    }
    cout<<mx;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
 
using namespace std;
ll AAA(ll i,ll j) {
    ll count=0;
    while(i<j) {
        i*=2;
        count+=1;

    }
    return count;
}
int main() {
    ll N,K;
    cin>>N>>K;
    double a=0;
    double b=1.0/2.0;
    rep(i,1,N+1) {
      
        a+=1.0/N*pow(b,AAA(i,K));
    }
    
    printf("%.10lf\n",a);



    }


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll solve(ll l, ll r, vector<ll> &A){
  ll res = 0;
  ll mid = (l+r)/2;
  if(r - l == 1) return res;
  res += solve(l, mid, A);
  res += solve(mid, r, A);
  vector<ll> B;
  ll x = l, y = mid;
  while(x < mid || y < r){
    ll bs = B.size();
    if(x == mid){
      B.pb(A[y++]);
    }else if(y == r){
      res += bs - x + l;
      B.pb(A[x++]);
    }else{
      if(A[x] <= A[y]){
        res += bs - x + l;
        B.pb(A[x++]);
      }else{
        B.pb(A[y++]);
      }
    }
  }
  for(ll i = l; i < r; i++) A[i] = B[i-l];
  return res;
}



int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = solve(0, N, A) * K % MOD;
  A.pb(INFL);
  rep(i, N){
    ll cnt = 1;
    while(A[i] == A[i+1]){
      i++;
      cnt++;
    }
    ll right = N - i - 1;
    ans += K * (K-1) / 2 % MOD * right % MOD * cnt % MOD;
    ans %= MOD;
  }
  cout << ans << endl;




}


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

int main() {
    string S,T;
    cin >> S;
    cin >> T;
    int ans = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    
    if (ans == 0) {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    
    
    
    
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cmath>
#include <iostream>

#define rep( i, n, m ) for (int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for (int i = ( n ); i < ( m ); i--)

int main( void ){
	int n;
	if(!scanf( "%d", &n ))
		return -1;
	printf("%d\n", n*n*n);
	return 0;
}


Measured memory_bytes: 256
import java.lang.Math

fun main(args: Array<String>) {
    val S = readInputLine()

    var a = 0
    var b = 0
    var c = 0

    S.forEach {
        when (it) {
            'a' -> a++
            'b' -> b++
            'c' -> c++
        }
    }

    if (Math.abs(a - c) >= 2 || Math.abs(b - c) >= 2 || Math.abs(a - b) >= 2) {
        println("NO")
    } else {
        println("YES")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33876
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    while(j>=0):
        if A[i] + B[j] <= K:
            ans = max(ans,i+j)
            break
        j -= 1
    """for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
    """
print(ans)

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

int main(){
    int h, w;

    while(true){
        cin >> h >> w;
        if(h == 0 && w == 0)
            break;

        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                if((i+j) % 2 == 0){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
            cout <<'\n';
        }
        cout << '\n';
    }
    return 0;
}

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

int main () {
    int N;
    int A;
    int B;
    cin >> N>>A>>B;
    int max;
    int min;

    if (A == B) {
        max = A;
        min = B;
    }
    if (A + B < N) {
        min = 0;
        max = (A < B) ? A : B;
    }
    if (A + B >= N ) {
        max = (A > B) ? B : A;
        min = A + B - N;
    }
    cout << max << ' ' << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
using namespace std;  
typedef long long ll; 
typedef long double ld; 
const int INF = 0x3f3f3f3f;  
const int N = 100000 + 5;
double a[N];
ld b[N];
 
int main()
{
	ll x;
	cin >> x;
	ll t1 = x / 500,t2 = x % 500 / 5;
	ll sum = t1*1000+t2*5;
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var X, A, ans int

func main() {
	fmt.Scan(&X, &A)
	if X < A {
		fmt.Println(0)
	} else {
		fmt.Println(10)
	}
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}
type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 512
s = input()

a = 0
b = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '1':
            a += 1
        else:
            b += 1
    else:
        if s[i] == '0':
            a += 1
        else:
            b += 1

print(min(a, b))        


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

int main() {
	int n,m;
	cin >> n;
	vector<string> blue(100);
	for (int i = 0; i < n; i++)cin >> blue.at(i);
	cin >> m;
	vector<string> red(100);
	for (int i = 0; i < m; i++)cin >> red.at(i);
    int M=max(n,m);
	int Max = 0;
	for (int i = 0; i < n; i++) {
		int count = 0;
		for (int j = 0; j < M; j++) {
			if (blue.at(i) == blue.at(j))count++;
			if (blue.at(i) == red.at(j))count--;
		}
		if (Max < count)Max = count;
	}
	cout << Max << endl;
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double a = int.Parse(input[0]);
            double b = int.Parse(input[1]);

            Console.WriteLine(Math.Ceiling(a/ b));
        }
    }
}

Measured memory_bytes: 13140
import sys

# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
import bisect


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    A = sorted(list(map(int, input().split())))
    mod = 10 ** 9 + 7

    if N == K:
        ans = 1
        for i in range(N):
            ans *= A[i]
            ans %= mod
        print(ans % mod)



    elif K % 2 == 0:
        ans = 1
        j = 0
        i = N - 1
        for _ in range(K // 2):
            if A[j] * A[j + 1] > A[i] * A[i - 1]:
                ans *= A[j] * A[j + 1]
                ans %= mod
                j += 2
            else:
                ans *= A[i] * A[i - 1]
                ans %= mod
                i -= 2
        print(ans % mod)

    elif A[-1] < 0:
        ans = 1
        for i in range(K):
            ans *= A[-(i + 1)]
            ans %= mod
        print(ans % mod)
    else:
        ans = A[-1]
        j = 0
        i = N - 2
        for _ in range(K // 2):
            if A[j] * A[j + 1] > A[i] * A[i - 1]:
                ans *= A[j] * A[j + 1]
                ans %= mod
                j += 2
            else:
                ans *= A[i] * A[i - 1]
                ans %= mod
                i -= 2
        print(ans % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32448
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    input! { n, a: [usize; n] };
    let mut ans = 0usize;
    let mut c = vec![0usize; n + 1];
    for i in 0..n {
        if i >= a[i] {
            ans += c[i - a[i]];
        }
        if i + a[i] <= n {
            c[i + a[i]] += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6748
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#include <iostream>
#include<algorithm>  
using namespace std;
int n,s,k;
int f[11][21][156]; 
int main()
{
 while(1)
  {
   scanf("%d%d%d",&n,&k,&s);
   if(n==0&&k==0&&s==0) break;
   memset(f,0,sizeof(f));
   for(int i=1;i<=n;i++)
    f[1][i][i]=1;
   for(int i=2;i<=k;i++)
    for(int j=1;j<=n;j++)
     for(int t=1;t<=s;t++)
      for(int p=1;p<j;p++)
       {
        if(t-j>=1)
         f[i][j][t]+=f[i-1][p][t-j];
       }
   int ans=0;
   for(int i=1;i<=n;i++)
    ans+=f[k][i][s];
   printf("%d\n",ans) ;
  }
 return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
// combination mod prime
// comnputing order k

int main(void) {
	int n; cin >> n;
	vll a(5,0);
	rep(i,n){
		string s; cin >> s;
		if(s[0]=='M') a[0]++;
		if(s[0]=='A') a[1]++;
		if(s[0]=='R') a[2]++;
		if(s[0]=='C') a[3]++;
		if(s[0]=='H') a[4]++;
	}
	ll ans = 0;
	for(int i=0; i<5; i++){
		for(int j=i+1; j<5; j++){
			for(int k=j+1; k<5; k++){
				ans += a[i]*a[j]*a[k];
			}
		}
	}
	cout << ans << endl;
}	


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 998244353
int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	
	std::vector<int> fastest;
	{
		int cnt[n][2];
		for (int i = 0; i < n; i++) cnt[i][0] = s[i] - '0', cnt[i][1] = 2 - cnt[i][0];
		std::vector<int> res;
		for (int i = 0; i < 2 * n; i++) {
			if (cnt[0][0]) cnt[0][0]--, res.push_back(0);
			else if (cnt[0][1]) cnt[0][1]--, res.push_back(1);
			for (int j = 1; j < n; j++) {
				if (cnt[j][0]) cnt[j][0]--, cnt[j - 1][0]++;
				else if (cnt[j][1]) cnt[j][1]--, cnt[j - 1][1]++;
			}
		}
		for (int i = 0; i < 2 * n; i++) if (res[i] == 0) fastest.push_back(i);
	}
	std::vector<int> latest;
	{
		int cnt[n][2];
		for (int i = 0; i < n; i++) cnt[i][0] = s[i] - '0', cnt[i][1] = 2 - cnt[i][0];
		std::vector<int> res;
		for (int i = 0; i < 2 * n; i++) {
			if (cnt[0][1]) cnt[0][1]--, res.push_back(1);
			else if (cnt[0][0]) cnt[0][0]--, res.push_back(0);
			for (int j = 1; j < n; j++) {
				if (cnt[j][1]) cnt[j][1]--, cnt[j - 1][1]++;
				else if (cnt[j][0]) cnt[j][0]--, cnt[j - 1][0]++;
			}
		}
		for (int i = 0; i < 2 * n; i++) if (res[i] == 0) latest.push_back(i);
	}
	int sz = fastest.size();
	int dp[2 * n + 2];
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	for (int i = 0; i < sz; i++) {
		int new_dp[2 * n + 2];
		memset(new_dp, 0, sizeof(new_dp));
		for (int j = 0; j < 2 * n; j++) {
			new_dp[std::max(j, fastest[i]) + 1] += dp[j];
			if (new_dp[std::max(j, fastest[i]) + 1] >= MOD) new_dp[std::max(j, fastest[i]) + 1] -= MOD;
			new_dp[latest[i] + 2] += MOD - dp[j];
			if (new_dp[latest[i] + 2] >= MOD) new_dp[latest[i] + 2] -= MOD;
		}
		for (int j = 0; j < 2 * n; j++) {
			new_dp[j + 1] += new_dp[j];
			if (new_dp[j + 1] >= MOD) new_dp[j + 1] -= MOD;
		}
		memcpy(dp, new_dp, sizeof(dp));
	}
	std::cout << std::accumulate(dp, dp + 2 * n + 1, 0LL) % MOD << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n,m; cin >> n >> m;
    ll time = 100*(n-m) + 1900 * m;
    cout << time * pow(2,m) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		List<List<Hen>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			int c = Integer.parseInt(sa[2]);
			list.get(a).add(new Hen(b, c));
			list.get(b).add(new Hen(a, c));
		}

		sa = br.readLine().split(" ");
		int q = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]) - 1;
		int[] x = new int[q];
		int[] y = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			x[i] = Integer.parseInt(sa[0]) - 1;
			y[i] = Integer.parseInt(sa[1]) - 1;
		}
		br.close();

		long[] d = new long[n];
		Arrays.fill(d, Long.MAX_VALUE);
		Queue<Integer> que = new ArrayDeque<>();
		que.add(k);
		d[k] = 0;
		while (!que.isEmpty()) {
			int cur = que.poll();
			for (Hen h : list.get(cur)) {
				if (d[h.v] == Long.MAX_VALUE) {
					que.add(h.v);
					d[h.v] = d[cur] + h.c;
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			pw.println(d[x[i]] + d[y[i]]);
		}
		pw.flush();
	}

	static class Hen {
		int v, c;

		public Hen(int v, int c) {
			this.v = v;
			this.c = c;
		}
	}
}


Measured memory_bytes: 83056
#include<stdio.h>

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

    scanf("%d%d%d", &a, &b, &c);

    if ((a <= b) && (b <= c))
    {
        printf("%d %d %d\n", a, b, c);
    }
    else
    {
        if ((a <= b) && (c <= b)&&(a <= c))
        {
            printf("%d %d %d\n", a, c, b);
        }
        else
        {
            if ((b <= a) && (a <= c))
            {
                printf("%d %d %d\n", b, a, c);
            }
            else
            {
                if ((b <= a) && (c <= a) && (b <= c))
                {
                    printf("%d %d %d\n", b, c, a);
                }
                else
                {
                    if ((c <= a) && (a <= b))
                    {
                        printf("%d %d %d\n", c, a, b);
                    }
                    else
                    {
                        printf("%d %d %d\n", c, b, a);
                    }

                }

            }
        }
    }
    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int);
int pop(void);

int top,X[1000];

int main(){
  int x,y,n,m;
  char s[100];
  
  top=0;
  
  while( scanf("%s",s) != EOF){
    if ( s[0] == '+' ){
      n=pop();
      m=pop();
      push(n+m);
    } else if ( s[0] == '-' ){
      n=pop();
      m=pop();
      push(m-n);
    } else if ( s[0] == '*' ){
      n=pop();
      m=pop();
      push(n*m);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}

void push(int x){
  X[top]=x;
  top++;
}

int pop(){
  top--;
  return X[top];
}
  
  
  



Measured memory_bytes: 2040