akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}



int main(){
  cout<<setprecision(1000);
  ll Q;
  cin>>Q;
  tree<ll,null_type,less_equal<ll>,rb_tree_tag, tree_order_statistics_node_update> s;
  ll b=0;
  ll minans=0;
  auto minx=s.begin();
  For(times,Q){
    ll cmd;
    cin>>cmd;
    if(cmd==1){
      ll x,y;
      cin>>x>>y;
      b+=y;
      minans+=y;
      if(s.empty()){
        s.insert(x);
        minx=s.begin();
      }else{
        s.insert(x);
        auto tmp=s.find_by_order(s.size()/2-(s.size()%2==0?1:0));
        if(*tmp!=*minx){
          if(s.size()%2!=1){
            minans+=abs(*tmp-*minx);
          }
          minx=tmp;
        }
        minans+=abs(*minx-x);
      }
    }else{
      cout<<*minx<<" "<<minans<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12800
n,x=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
a.sort()

if sum(a) < x:
  ans=n-1
elif  sum(a) == x:
  ans=n
else:
  i=0
  val=0
  while val <= x:
    val+=a[i]
    i+=1
#    print(i,x)
  ans=i-1
  
print(ans)



Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%2==0&&a%3!=0&&a%5!=0){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a>b && a>c){
        if(b>c){        
        cout << c << " " << b << " " << a << endl;
        } else {
        cout << b << " " << c << " " << a << endl;            
        }
    } else if(b>a && b>c){
        if(a>c){        
        cout << c << " " << a << " " << b << endl;
        } else {
        cout << a << " " << c << " " << b << endl;            
        }
    } else {
        if(a>b){        
        cout << b << " " << a << " " << c << endl;
        } else {
        cout << a << " " << b << " " << c << endl;            
        }        
    }
    return 0;
}


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main ()
{
    int a,b;
    cin>>a>>b;
    if(b == 1) cout<<"0"<<endl;
    else if(a>=b) cout<<"1"<<endl;
    else {
        int socket=0;
        int c=0;
        while(socket <= b){
            socket+=a;
            c++;
            if(socket >= b)
                break;
            socket--;
        }
        cout<<c<<endl;
    }
}

Measured memory_bytes: 384
#include<stdio.h>
int main() {
	char S[100];
	scanf("%s", &S);

	for (int i = 0; i < 100; i++) {
		if (S[i] == '\0')
			break;
		S[i] = 'x';
	}
	printf("%s\n", S);
	return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>   
using namespace std;
#define N 10000
#define REP(i, n) for(int i=0; i<n; i++)
string s;
int n;
long long ans;
int main(void){
    cin>>s;
    n=s.size()-1;
//bit全探索
    for(int i=0;i<(1<<n);i++){
        long long a=s[0]-'0';
        long long sum=0;
        for(int j=0;j<n;j++){
            if(1&(i>>j)){//穴（１）があるならば
                sum+=a;
                a=s[j+1]-'0';
            }else{
                a=a*10+(s[j+1]-'0');
            }
           
        }
        sum+=a;
        ans+=sum;
        
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t = sc.next();
			int slen = s.length();
			int tlen = t.length();
			int ans = Integer.MAX_VALUE;
			for (int i = 0; i <= slen - tlen; i++) {
				int tmpans = 0;
				String tmps = s.substring(i, i + tlen);
				for (int j = 0; j < tlen; j++) {
					if (tmps.charAt(j) != t.charAt(j)) {
						tmpans++;
					}
				}
				ans = Math.min(ans, tmpans);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 36708
def examB():
    N = I()
    St = LS()
    d = defaultdict(str)
    for s in St:
        d[s] = 1
    if len(d)==3:
        ans = "Three"
    elif len(d)==4:
        ans = "Four"
    if ans:
        print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 38512
import math


def is_prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            return False
    return True


n = int(input())
count = 0
for _ in range(n):
    m = int(input())
    if is_prime(m):
        count += 1
print(count)



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

using namespace std;

using ll = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  ll n, k, d, a, ans = 0;
  cin >> n >> k;
  vector<int> A(n, 0);
  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> a;
      A[a-1]++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (A[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int N, i;
    cin >> N;
    long A[N];
    for(i=0; i<N; i++) {
        cin >> A[i];
    };
    int cnt, flag;
    cnt = 0;
    flag = 0;
    long x, y;
    x = A[0];
    for(i=1; i<N; i++) {
        y = A[i];
        if(x > y) {
            if(flag == -1){
               flag = 0;
               cnt++;
            } else {
               flag = 1;
            }
        }
        if(x < y) {
            if(flag == 1){
                flag = 0;
                cnt++;
            } else {
                flag = -1;
            }
        }
        x = y;
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 1152
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var input = make([]string, 2)
	var n, r int
	if scanner.Scan() {
		input = strings.Split(scanner.Text(), " ")
		n, _ = strconv.Atoi(input[0])
		r, _ = strconv.Atoi(input[1])
	}

	if n < 10 {
		fmt.Println(r + (100*(10-n)))
	} else {
		fmt.Println(r)

	}

}


Measured memory_bytes: 640
/*input
7
5 0 7 8 3 3 2
*/
#include "bits/stdc++.h"
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	long long sum = 0, ans = 0;
	for(int i=1;i<=n;++i){
		cin >> a[i];
		sum += a[i];
	}
	for(int i=1;i<=n;++i){
		ans += a[i] * (sum - a[i]);
	}
	assert(ans%2==0);
	cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int level;
            for (int l = 0; l < 32; ++l) {
                if (((i ^ j) >> l) & 1) {
                    level = l;
                    break;
                }
            }
            cout << level + 1;
            if (j + 1 == n) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    return 0;
}


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

using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio { ios_base::sync_with_stdio(false), cin.tie(NULL); }
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#ifdef RICARDO
//Header here
	#include "E:\\Code\\dbg.h"
#else
	#define bug(...) "RICARDO MILOS"
#endif


template<class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

//=================================================CODE=================================================//

signed main()
{	
	fastio;
	cout.precision(10);
	cout << fixed;
#ifdef RICARDO		
	freopen("i", "r", stdin);
#endif
	int n; cin >> n;
	vi a(n + 1);
	vpi b(n + 1);
	vi f(n + 1);
	a[0] = 0;
	b[0] = {0, 0};
	f[0] = 0;
	for1(i, n) {
		cin >> a[i];
		f[i] = a[f[i - 1]] < a[i] ? i : f[i - 1];
		b[i] = {a[i], i};
	}

	sort(all(b));
	i64 great = 0;
	int cnt = 0;
	vi64 ANS(n + 1);
	i64 pref = 0;
	for(int cur = f[n]; cur;) {
		int p = cur;
		cur = f[cur - 1];
		i64 delt = a[p] - a[cur];
		great = great + delt * cnt;
		while(b.size() && b.back().fi > a[cur]) {
			if(b.back().se > cur) {
				cnt++;
				great += b.back().fi - a[cur];
			}
			b.pop_back();
		}
		ANS[p] = great - pref;
		pref += ANS[p];
	}	
	for1(i, n) cout << ANS[i] << endl;	
#ifdef RICARDO
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=3e5+5;
int n,s[N];
long long ans;

void init()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=2*n;++i) scanf("%d",&s[i]);
	sort(s+1,s+2*n+1);
}

void work()
{
	int i;
	for(i=1;i<=2*n;++i) ans+=1LL*(i-1)*s[i];
	printf("%.12lf\n",1.0*ans/(2*n-1));
}

int main()
{
	init();
	work();
	return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let v = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = 0;
    let mut temp = 0;
    for ch in v {
        if ch == 'I' {
            temp += 1;
        } else {
            temp -= 1;
        }
        ans = max(ans, temp);
    }
    println!("{}", ans);
}

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()
}

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

struct edge{int to;int cap;int rev;};
struct Dinic{
private:
  int n;
  vector<vector<edge>> v;
  vector<int> dist,iter;
public:
  Dinic(int sz):n(sz),v(sz),dist(sz),iter(sz){}
    
  void addedge(int from,int to,int cap){
    int x=v[to].size(),y=v[from].size();
    v[from].push_back({to,cap,x});
    v[to].push_back({from,0,y});
  }
    
  void bfs(int s){
    fill(dist.begin(),dist.end(),-1);
    queue<int> q;
    dist[s]=0;
    q.push(s);
    while(q.size()){
      int x=q.front();q.pop();
      rep(i,v[x].size()){
        edge &e=v[x][i];
        if(e.cap>0&&dist[e.to]<0){
          dist[e.to]=dist[x]+1;
          q.push(e.to);
        }
      }
    }
  }
    
  int dfs(int x,int t,int f){
    if(x==t)return f;
    for(int& i=iter[x];i<(int)v[x].size();++i){
      edge& e=v[x][i];
      if(e.cap>0&&dist[x]<dist[e.to]){
        int d=dfs(e.to,t,min(f,e.cap));
        if(d>0){
          e.cap-=d;
          v[e.to][e.rev].cap+=d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s,int t){
    int flow=0;
    while(1){
      bfs(s);
      if(dist[t]<0)return flow;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,(1LL<<31)-1))>0)flow+=f;
    }
  }
};

int main(){
  int n;
  cin >> n;
  Dinic dn(n+n+2);
  vector<int> a(n),b(n),c(n),d(n);
  rep(i,n){ cin >> a[i] >> b[i]; dn.addedge(n+n, i, 1);}
  rep(i,n){ 
    cin >> c[i] >> d[i]; 
    dn.addedge(n+i, n+n+1, 1);
    rep(j,n)if(a[j]<c[i]&&b[j]<d[i]){
      dn.addedge(j, n+i, 1);
    }
  }

  int ans=dn.max_flow(n+n, n+n+1);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long LL;
const int N = 1e5 + 5;

int n, ans;
LL a[N], c[N], cb[N], id[N], _tmp[N];
int prime[N], Index, vis[N];
unordered_map <LL, LL> M; //multiset会保留多个相同的迭代器!! 在本题中不如map实现

void inv_per(LL A[], LL p[]) {
    for(int i = 1; i <= n; i++) _tmp[i] = A[p[i]];
    for(int i = 1; i <= n; i++) A[i] = _tmp[i];
}

void init() {
    scanf("%d", &n);
    for(int i = 1; i < N; i++) cb[i] = 1ll * i * i * i;
    for(int i = 2; i < N; i++) {
        if(vis[i]) continue;
        prime[++Index] = i;
        for(int j = i + i; j < N; j += i) vis[j] = true;
    }
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        c[i] = 1;
        LL x = a[i];
        for(int j = 1; j <= Index; j++) {
            int p = prime[j];
            if(x < cb[p]) break;
            while(x % cb[p] == 0) x /= cb[p], a[i] /= cb[p];
            if(x % p == 0) c[i] *= p;
            while(x % p == 0) x /= p;
        }
        LL y = sqrt(x);
        if(y * y == x) c[i] *= y;
        else c[i] *= x;
    }
    for(int i = 1; i <= n; i++) id[i] = i;
    sort(id + 1, id + n + 1, [](int x, int y){ return c[x] < c[y]; });
    inv_per(a, id), inv_per(c, id);
    c[n + 1] = 0x3f3f3f3f;
    for(int i = 1; i <= n + 1; i++) {
        if(c[i] != c[i - 1]) {
            LL k = c[i - 1] * c[i - 1] * c[i - 1], x, y;
            if(k == 1) ans -= M[1], ans ++ ;
            else {
                for(auto tmp : M) {
                    x = tmp.first;
                    y = k / x;
                    if(x < y) ans -= min(M[x], M[y]);
                }
            }
            M.clear();
        }
        M[a[i]] ++ ;
    }
    ans += n;
    cout << ans << endl;
}

int main() {
    init();
    return 0;
}

Measured memory_bytes: 4608
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function tsort(g::Array{Array{Int,1},1},n,m)
	d = zeros(Int,n)
	v = zeros(Int,n)
	for i in 1:n
		for j in 1:length(g[i])
			d[g[i][j]] += 1
		end
	end
	s = Int[]
	for i in 1:n
		if d[i] == 0
			push!(s,i)
		end
	end
	l = Int[]
	while !isempty(s)
		t = pop!(s)
		push!(l,t)
		for i in 1:length(g[t])
			d[g[t][i]] -= 1
			if d[g[t][i]] == 0
				push!(s,g[t][i])
			end
		end
	end
	if length(l) == n
		false
	else
		l
	end
end

function main()
	n,m = readline() |> split |> parseMap
	e = zeros(Int,2,m)
	g = [Int[] for i in 1:n]
	for i in 1:m
		e[:,i] = readline() |> split |> parseMap
	end
	for i in 1:m
		push!(g[e[1,i]],e[2,i])
	end
	if(tsort(g,n,m))==false
		println(-1)
	else
		f = zeros(Int,n)
		x = n
		y = m
		for i in 1:n
			tmp = g[i]
			g[i] = []
			tmq = length(tmp)
			x -= 1
			y -= tmq
			if tsort(g,n,y)==false
				f[i] = 1
				g[i] = tmp
				x += 1
				y += tmq
			end
		end
		println(sum(f))
		for i in 1:n
			if f[i] == 1
				println(i)
			end
		end
	end
end

main()

Measured memory_bytes: 171260
#include<bits/stdc++.h>
typedef long long int lli;
#define MOD 1000000007
using namespace std;


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    lli n, temp;
    cin >> n;
    int arr[n + 1];
    memset(arr, 0, sizeof(arr));
    for(int i = 0 ; i < n-1 ; i++) {
        cin >> temp;
        arr[temp]++;
    }
    for(int i = 1 ; i <= n ; i++) cout << arr[i] << endl;
    return 0;
}

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


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

int main() {
    int a[4], b[4];
    while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
        cin >> b[0] >> b[1] >> b[2] >> b[3];
        int hit = 0, blow = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (i == j) {
                    hit += (a[i] == b[j]);
                } else {
                    blow += (a[i] == b[j]);
                }
            }
        }
        cout << hit << " " << blow << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
map<int, int> M;

int32_t main(){_
   
   cin>>n;

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

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      if (M.count(i - a[i])){
         ans += M[i - a[i]];
      }
      M[a[i] + i]++;
   }
   
   cout<<ans;
   

   return 0;
}

Measured memory_bytes: 17696
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int n,m;cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)

	N := readInt()
	for n := 1; n <= N; n++ {
		count := 0
		for x := 1; x*x < n; x++ {
			for y := 1; x*x+y*y+x*y < n; y++ {
				for z := 1; x*x+y*y+z*z+x*y+y*z+z*x <= n; z++ {
					if x*x+y*y+z*z+x*y+y*z+z*x == n {
						count++
					}
				}
			}
		}
		fmt.Println(count)
	}
}


Measured memory_bytes: 1856
#include<iostream>
#define ll long long 

using namespace std;

const int N = 2e5 + 10;

ll town[N];
ll rul1[N];
ll rul2[N];
ll vis[N];

int main()
{
	ll cnt1 = 1;
	ll cnt2 = 1;
	long long n,k;
	cin>>n>>k;
	for(int i=1; i<=n; i++)
	{
		scanf("%lld",&town[i]);
	}
	ll ans = 1;
	ll m = k;
	while(m--)
	{		
		ans = town[ans];
		if(vis[ans]>2) break;
		if(vis[ans] == 0) rul1[cnt1++] = ans;
		else if(vis[ans] == 1) rul2[cnt2++] = ans;
		vis[ans]++;		
	}
//	for(int i=1; i<cnt1; i++) cout<<rul1[i]<<' ';
//	for(int i=1; i<cnt2; i++) cout<<rul2[i]<<' ';
	cnt1--;
	cnt2--;
//	cout<<cnt1<<' '<<cnt2<<endl;
	if(k <= cnt1) cout<<rul1[k];
	else if(cnt2 == -1 && k > cnt1)
	{
		int a = k % cnt1;
		if(!a) a = cnt1;
//		cout<<rul1[a];
	}
	else if(cnt2 != -1 && k > cnt1)
	{
//		cout<<cnt1<<' '<<cnt2;
//    	cout<<(k-4)%3<<endl;
		k -= cnt1;
		int a = k % cnt2;
//		cout<<a<<endl;
		if(!a) a = cnt2;
//		cout<<a<<endl;
		cout<<rul2[a];
	}
	return 0;
}



Measured memory_bytes: 8420
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        ta: [u64; n],
    }

    let answer = ta.iter().fold(1, |ans, &t| lcm(ans, t));
    println!("{}", answer);
}

#[inline]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}


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

long long n, ans = 0;

void dfs(long long x, long long a, long long b, long long c){
    if(x > n){
        return ;
    }
    if(a && b && c){
        ans++;
    }
    dfs(x * 10 + 3, 1, b, c);
    dfs(x * 10 + 5, a, 1, c);
    dfs(x * 10 + 7, a, b, 1);
}

signed main(){
    cin >> n;
    dfs(0, 0, 0, 0);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int a, b;
    cin >> a >> b;

    if (a * b % 2 == 0)
    {
        Cout("No");
    }
    else
    {
        Cout("Yes");
    }
    return 0;
}

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

int main() {
    int K, s;
    cin >> K >> s;

    int count = 0;
    for (int i=0; i<=K; ++i){
        for (int j=0; j<=K; ++j) {
            if ((s - (i+j)) <= K && (i+j) <= s) ++count;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

if k == 0:
    ans = n ** 2
else:
    ans = 0
    for x in range(k + 1, n + 1):
        w = x - k
        u = n // x
        ans += w * u
        ans += max(n - (u * x + k - 1), 0)
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll h, w;
  cin >> h >> w;
  rep(i, h) {
    rep(j, w) {
      string s; cin >> s;
      if (s == "snuke") {
        char c = 'A' + j;
        cout << c << i+1 << endl;
        break;
      }
    }
  }
}

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

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string S;
    
    cin >> S;

    rep(si,S.size()) cout << "x";    

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
 
#define For(i, j, k) for(int i = j; i <= k; i++)
 
const int N = 100010;
 
double A[N];
int n, m, pos[N], op[N], C[N], P[N], tmp[N];
long long k;
 
void mul(int *u, int *v){
	For(i, 1, n - 1) tmp[i] = v[u[i]];
	For(i, 1, n - 1) u[i] = tmp[i];
}
 
int main(){
	scanf("%d", &n);
	For(i, 1, n) scanf("%lf", &A[i]), pos[i] = C[i] = i;
	scanf("%d%lld", &m, &k);
	For(i, 1, m) scanf("%d", &op[i]), std::swap(pos[op[i]], pos[op[i] - 1]);
	For(i, 1, n - 1) P[pos[i]] = i;
 
	while(k){
		if(k & 1) mul(C, P);
		mul(P, P);
		k >>= 1;
	}
 
	For(i, 1, n - 1) pos[C[i]] = i;
 
	double now = A[1];
	printf("%.0lf\n", now);
	For(i, 1, n - 1) printf("%.0lf\n", now += A[pos[i] + 1] - A[pos[i]]);
 
	return 0;
}

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

int main() {
  int i, a, b, c;
  cin >> i;
  if(i>=100){
    a=1;i=i-100;
  } else if (i<100){
    a=0;
  }
  if(i>=10){
    b=1;i=i-10;
  } else if (i<10){
    b=0;
  }
  c=i;
  
  cout << a+b+c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define MOD 1000000007
    #define PI 3.1415926535897932384626433832795
    #define INF (int)1e9
    typedef long long int int64;
     
    void print() {
        cout << endl;
    }
     
    void print(string s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    void print(int64 s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(pair<T, T2>& p, bool endline = true) {
        print("(", false);
        print(p.first, false);
        print(", ", false);
        print(p.second, false);
        print(")", false);
     
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(map<T, T2>& m, bool endline = true) {
        print("{");
        for (auto& p : m) {
            print("  ", false);
            print(p);
        }
        print("}");
     
        if (endline) {}
    }
     
    template<typename T>
    void print(vector<T>& v, bool endline = true) {
        print("[", false);
        for (size_t i = 0; i < v.size(); ++i) {
            print(v[i], false);
            if(i != v.size() - 1) print(",", false);
        }
        print("]", false);
     
        if(endline) print();
    }
     
    template <typename T>
    vector<T> operator+(const vector<T> &a, const vector<T> &b)
    {
        vector<T> ret;
        ret.reserve( a.size() + b.size() );                // preallocate memory
        ret.insert( ret.end(), a.begin(), a.end() );        // add A;
        ret.insert( ret.end(), b.begin(), b.end() );        // add B;
     
        return ret;
    }
     
    template <typename T>
    vector<T> &operator+=(vector<T> &a, const vector<T> &b)
    {
        a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
        a.insert( a.end(), b.begin(), b.end() );         // add B;
        return a;
    }

    int main() {
        // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
        int64 n;
        cin >> n;

        vector<int64> nums;

        while(n -- > 0) {
            int64 t;
            cin >> t;
            nums.push_back(t);
        }

        int64 count = 0;
        int64 base = 1;

        for(int64 i = 0; i < 60; ++i) {
            int64 one = 0;
            int64 zero = 0;

            for(auto& c : nums) {
                if (c % 2 == 1) {
                    one++;
                } else {
                    zero++;
                }

                c /= 2;
            }

            // int64 tmp = (zero * one * (1LL << i)) % MOD;
            int64 tmp = zero % MOD;
            tmp *= base;
            tmp %= MOD;

            tmp *= (one % MOD);
            tmp %= MOD;
            
            count += tmp % MOD;
            count %= MOD;

            base *= 2;
            base %= MOD;
        }
        cout << count % MOD << endl;

        return 0;
    }

Measured memory_bytes: 6512
from sys import stdin


def num_of_prime_factorization(n):
    i = 2
    table = []
    while i * i <= n:
        loop_num = 0
        while n % i == 0:
            n //= i
            loop_num += 1
            if n % i != 0:
                table.append(loop_num)
        i += 1
    if n > 1:
        table.append(1)
    return table


def comb(n, r):
    a = 1
    for num in range(n, n - r, -1):
        a *= num

    b = 1
    for num in range(r, 0, -1):
        b *= num

    return a // b


N, M = [int(i) for i in stdin.readline().rstrip().split()]

lst = num_of_prime_factorization(M)
ans = 1

for b in lst:
    ans *= comb(b + N - 1, b)

print(ans % (10**9 + 7))


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

using namespace std;

int main(int argc, const char *argv[]) {
  int h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int dur = (h2 - h1) * 60;
  dur -= m1;
  dur += m2;

  cout << max(0, dur - k) << '\n';
  return 0;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<bool> > VVB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int N, M;

VI as, bs, cs;
VVI dist;

bool check(int a, int b, int c) {
	rep (i, N) {
		rep (j, N) {
			if (dist[i][a] + c + dist[b][j] == dist[i][j])
				return true;
		}
	}
	return false;
}

int solve() {
	dist.resize(N, VI(N, INF));
	rep (i, M) {
		dist[as[i]][bs[i]] = min(dist[as[i]][bs[i]], cs[i]);
		dist[bs[i]][as[i]] = min(dist[bs[i]][as[i]], cs[i]);
	}
	rep (k, N) {
		rep (i, N) {
			rep (j, N) {
				if (i == j) dist[i][j] = 0;
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				dist[j][i] = min(dist[j][i], dist[j][k] + dist[k][i]);
			}
		}
	}
	int ans = M;
	rep (i, M) {
		if (check(as[i], bs[i], cs[i])) ans--;
	}
	return ans;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> N >> M;
	rep (i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		as.pb(a - 1);
		bs.pb(b - 1);
		cs.pb(c);
	}
	cout << solve() << endl;
	return 0;
}



Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
res = -1
total_l = 0
total_r = 0
t = 1

for i in range(N):
  total_l = sum(W[:t])
  total_r = sum(W[t:])
  s = abs(total_l - total_r) 
  if s < res or res < 0:
    res = s
  t += 1
print(res)

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

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

int main(){
  ll n,q;
  cin>>n>>q;
  
  ll ans=(n-2)*(n-2);
  ll h=n,w=n;
  
  vector<int> W(n+1,n),H(n+1,n);
  
  while(q--){
    int c,x;
    scanf("%d%d",&c,&x);
    if(c==1){
      if(x<w){
        ans-=(h-2);
        for(int i=x+1;i<w;i++) W[i]=h;
        w=x;
      }
      else ans-=(W[x]-2);
    }
    else{
      if(x<h){
        ans-=(w-2);
        for(int i=x+1;i<h;i++) H[i]=w;
        h=x;
      }
      else ans-=(H[x]-2);
    }
  }
  cout<<ans<<endl;

  return 0;
}

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

int main() {
    long long a,b,n;
    cin>>a>>b>>n;
    long long ans;
    if(b>n){
        ans=(a*n/b)-a*(n/b);
    }else{
        ans=(a*(b-1))/b;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] array = line.split(" ");

		//A B
		int A = Integer.parseInt(array[0]);
        int B = Integer.parseInt(array[1]);

        if(A <= 8 && B <= 8 ){
        	System.out.println("Yay!");
        }else{
        	System.out.println(":(");
        }

	}

}


Measured memory_bytes: 21332
#include <cstdio>

#define MAX_H 100
#define MAX_W 100

int H, W;
char farm[ MAX_H ][ MAX_W + 1 ];
const int dx[ 4 ] = { 1, 0, -1, 0 }, dy[ 4 ] = { 0, 1, 0, -1 };

void DFS( int x, int y ) {
	char ch = farm[ y ][ x ];
	farm[ y ][ x ] = '.';
	for( int i = 0; i < 4; ++i ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];
		if( 0 <= nx && nx < W && 0 <= ny && ny < H && farm[ ny ][ nx ] == ch ) { DFS( nx, ny ); }
	}
}

int main()
{
	while( scanf( "%d %d", &H, &W ), H || W ) {
		for( int y = 0; y < H; ++y ) { scanf( "%s", farm[ y ] ); }

		int ans = 0;
		for( int y = 0; y < H; ++y ) {
			for( int x = 0; x < W; ++x ) {
				if( farm[ y ][ x ] != '.' ) {
					DFS( x, y );
					++ans;
				}
			}
		}
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1504
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

struct node{
  vector<int> friends;
  int id;
  int ans;
  struct edge* p;
};
int id; //連結成分の番号
struct edge{
  int start;
  int end;
  struct edge* next;
};

void init_node(struct node** n){
  *n = (struct node*)malloc(sizeof(struct node));
  (*n)->p = nullptr;
  (*n)->id = -1;
}

void add_node(struct node* g[],int a, int b){
  struct edge* e = (struct edge*)malloc(sizeof(struct edge));
  e->start = a;
  e->end = b;
  e->next = g[a]->p;
  g[a]->p = e;
}

void DFS(struct node* nodes[],struct node* a,int& cnt){
  a->id = id;
  cnt++;
  while(a->p != nullptr){
    if(nodes[a->p->end]->id == -1) DFS(nodes,nodes[a->p->end],cnt);
    a->p = a->p->next;
  }  
}
void print_node(struct node* nodes[],int n){
  for(int i = 0; i < n-1 ;++i){
    cout << nodes[i]->ans <<" ";
  }
  cout << nodes[n-1]->ans <<endl;
}

int main()
{ 
  int N,M,K;
  int a,b,c,d;
  vector<int> cnts;
  vector<int> c_,d_;
  cin >> N >> M >> K;
  struct node* nodes[N];
  for(int i = 0; i < N;i++){
    init_node(&nodes[i]);
  }
  for(int i = 0; i < M;i++){
    cin >> a >> b; 
    add_node(nodes,a-1,b-1);
    add_node(nodes,b-1,a-1);
    nodes[a-1]->friends.push_back(b-1);
    nodes[b-1]->friends.push_back(a-1);
  }
  for(int i = 0; i < K;i++){
    cin >> c >> d;
    c_.push_back(c-1);
    d_.push_back(d-1); 
  }
  id = 0;
  for(int i = 0; i < N;i++){
    if(nodes[i]->id == -1){
      int cnt = 0;
      DFS(nodes,nodes[i],cnt);
      id++;
      cnts.push_back(cnt);
    }
  }

  for(int i = 0; i < N;i++){
    nodes[i]->ans = cnts[nodes[i]->id] - nodes[i]->friends.size() - 1;
  }
  for(int i = 0; i < K;i++){
    if(nodes[c_[i]]->id == nodes[d_[i]]->id){
      nodes[c_[i]]->ans--;
      nodes[d_[i]]->ans--;
    }
  }
  print_node(nodes,N);
  return 0;
}

Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i,H) cin >> A[i];
    int cnt = 0;
    rep(i,H)rep(j,W){
        if(A[i][j]=='#')cnt++;
    }
    if(cnt==(H+W-1)){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	while (scan.hasNext()) {
	    int count = 0;
	    int n = scan.nextInt();
	    int x = scan.nextInt();
	    if (n == 0 && x == 0) {
		break;
	    }
	    for (int i = 1; i < n - 1; i++) {
		if (i > x) {
		    break;
		}
		for (int j = i + 1; j < n; j++) {
		    if (j + i > x) {
			break;
		    }
		    for (int k = j + 1; k < n + 1; k++) {
			if (j + i + k > x) {
			    break;
			}
			if (j + i + k == x) {
			    count++;
			    break;
			}
		    }
		}
	    }
	    System.out.println(count);
	}
    }
}

Measured memory_bytes: 26812
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();

    let ans = std::cmp::max(std::cmp::max(a + b, a - b), a * b);
    println!("{}", ans);
}


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

const int MXN = 3e2 + 20;

int n, a[3];
long double dp[MXN][MXN][MXN];

void npt() {
	int tmp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		a[--tmp]++;
	}
}

void slv() {
	long double c;
	dp[0][0][0] = 0;
	for (int k = 0; k <= n; k++)
		for (int j = 0; j <= n; j++)
			for (int i = 0; i + j + k <= n; i++) {
				c = (1. * i / n * (i? dp[i - 1][j][k] + 1: 0)) 
					+ (1. * j / n * (j? dp[i + 1][j - 1][k] + 1: 0)) 
					+ (1. * k / n * (k? dp[i][j + 1][k - 1] + 1: 0));
				dp[i][j][k] = (i + j + k? (1. * (n - i - j - k) / n + c) 
					/ (1. * (i + j + k) / n): 0);
			}
}

int main() {
	npt();
	slv();
	cout << fixed << setprecision(12) << dp[a[0]][a[1]][a[2]] << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n;
    ll x;
    cin >> n >> x;;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    ll r = 0;
    ll past = a[0];
    if(past > x) {
        r += past - x;
        past = x;
    }
    for(int i=1; i<n; i++) {
        ll b = a[i];
        ll d = past + b - x;
        if(d > 0) {
            r += d;
            b -= d;
        }
        past = b;
    }
    cout << r << endl;

}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int qq;
  cin >> qq;
  vector<int> cmd(qq), pos(qq);
  vector<char> add(qq);
  int cnt = 0;
  for (int i = 0; i < qq; ++i) {
    cin >> cmd[i];
    cnt += cmd[i] == 1;
    if (cmd[i] == 1) continue;
    cin >> pos[i] >> add[i];
  }
  string t;
  int cur = 0;
  for (int i = qq - 1; ~i; --i) {
    if (cmd[i] == 1) {
      ++cur; continue;
    }
    if (pos[i] + cur & 1) t += add[i];
  }
  if (cnt & 1) reverse(s.begin(), s.end());
  for (char c : s) t += c;
  cur = 0;
  for (int i = 0; i < qq; ++i) {
    if (cmd[i] == 1) {
      ++cur; continue;
    }
    int after = cnt - cur;
    if (!(pos[i] + after & 1)) t += add[i];
  }
  cout << t << '\n';
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std ;
int main()
{
  int a,b,c ;

  1<=b<=a<=20 ;
  1<=c<=20;
  cin>>a>>b>>c ;
  if(a-b<=c)
    {
        cout << c-(a-b) ;
  }

else {cout << 0 ;}



return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 301000
using namespace std;
typedef long long ll;
ll s[maxn],ls[maxn],t[maxn],a[maxn],dpl[maxn],dpr[maxn],f[maxn];
int m,n,sta[maxn],tp;
ll cal(ll*dp,int i,int j){return -1ll*i*j+a[j];}
void pre(ll* dp){
	tp=0;
	sta[++tp]=0;
	for(int i=1;i<=n;++i){
		s[i]=s[i-1]+t[i];
		while(tp>1&&cal(dp,i,sta[tp])<cal(dp,i,sta[tp-1]))tp--;
		dp[i]=max(cal(dp,i,sta[tp])-s[i]+1ll*i*(i+1)/2,dp[i-1]),a[i]=1ll*i*(i-1)/2+s[i]+dp[i];
		while(tp>1&&1ll*(i-sta[tp-1])*(a[sta[tp]]-a[sta[tp-1]])<=1ll*(sta[tp]-sta[tp-1])*(a[i]-a[sta[tp-1]]))tp--;
		sta[++tp]=i;
	}
}
void solve(int l,int r,int ty){
	if(l==r){
		f[l]=max(f[l],dpl[l-1]+dpr[l+1]+1-t[l]);
		return ;
	}
	int mid=l+r-ty>>1,tp=0;
	solve(l,mid,ty),solve(mid+1,r,ty);
	for(int i=l-1;i<=mid;++i){
		a[i]=1ll*i*(i-1)/2+s[i]+dpl[i];
		while(tp>1&&1ll*(i-sta[tp-1])*(a[sta[tp]]-a[sta[tp-1]])<=1ll*(sta[tp]-sta[tp-1])*(a[i]-a[sta[tp-1]]))tp--;
		sta[++tp]=i;
	}
	ll mx=0;
	/*
	int lp=1;
	for(int i=r;i>=mid+1;--i){
		while(lp<tp&&cal(dpl,i,sta[lp])<cal(dpl,i,sta[lp+1]))lp++;
		mx=max(mx,dpr[i+1]+cal(dpl,i,sta[lp])+1ll*i*(i+1)/2-s[i]);
		f[i]=max(f[i],mx);
	}*/
	for(int i=mid+1;i<=r;++i){
		while(tp>1&&cal(dpl,i,sta[tp])<cal(dpl,i,sta[tp-1]))tp--;
		ls[i]=dpr[i+1]+cal(dpl,i,sta[tp])+1ll*i*(i+1)/2-s[i];
	}
	for(int i=r;i>=mid+1;--i){
		if(i!=r)ls[i]=max(ls[i],ls[i+1]);
		f[i]=max(f[i],ls[i]);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld",&t[i]),f[i]=-1ll<<60;
	pre(dpl),reverse(t+1,t+n+1);
	pre(dpr),reverse(t+1,t+n+1),reverse(dpr+1,dpr+n+1);
	for(int i=1;i<=n;++i)s[i]=s[i-1]+t[i];
	solve(1,n,0),reverse(f+1,f+n+1);
	reverse(t+1,t+n+1),reverse(dpl+1,dpl+n+1);
	reverse(dpr+1,dpr+n+1),swap(dpl,dpr);
	for(int i=1;i<=n;++i)s[i]=s[i-1]+t[i];
	solve(1,n,1),reverse(f+1,f+n+1);
	reverse(t+1,t+n+1),reverse(dpl+1,dpl+n+1);
	reverse(dpr+1,dpr+n+1),swap(dpl,dpr);
	scanf("%d",&m);
	for(int i=1,p,nx;i<=m;++i)
		scanf("%d%d",&p,&nx),printf("%lld\n",max(dpl[p-1]+dpr[p+1],f[p]-nx+t[p]));
}

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

typedef long long ll;

void solve(long long H, long long W, long long M, std::vector<long long> h, std::vector<long long> w){
  map<ll,ll> Mh;
  map<ll,ll> Mw;
  using pll = pair<ll,ll>;
  set<pll> S;
  for (ll i = 0; i < M; ++i) {
    Mh[h[i]]++;
    Mw[w[i]]++;
    S.insert({h[i], w[i]});
  }
  const auto cmp = [](pll lhs, pll rhs) {
    return lhs.second < rhs.second;
  };
  auto mh = *max_element(Mh.begin(), Mh.end(), cmp);
  auto mw = *max_element(Mw.begin(), Mw.end(), cmp);

  set<ll> hs;
  for (auto mhi : Mh) {
    if (mhi.second == mh.second) {
      hs.insert(mhi.first);
    }
  }
  set<ll> ws;
  for (auto mwi : Mw) {
    if (mwi.second == mw.second) {
      ws.insert(mwi.first);
    }
  }

  ll rv = mh.second + mw.second - 1;
  for (auto h : hs) {
    for (auto w : ws) {
      if (S.count({h,w}) == 0) {
        rv++;
        goto eos;
      }
    }
  }

eos:
  cout << rv << endl;

}

int main() {
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> h(M);
  std::vector<long long> w(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&h[i]);
    scanf("%lld",&w[i]);
  }
  solve(H, W, M, std::move(h), std::move(w));
  return 0;
}


Measured memory_bytes: 92104