akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int n; cin >>n;
  vector<Pi> a(n); rep(i, n) cin >>a[i].first >>a[i].second;
  sort(allR(a));
  cout <<a[0].first + a[0].second <<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    map<char,ll> cnt;
    vector<char> comb{'M','A','R','C','H'};
    REP(i,N){
        string s;
        cin >> s;
        cnt[s[0]]++;
    }
    ll ans = 0;
    for(int bit=0; bit<(1<<5); bit++){
        vint idx;
        for(int i=0; i<5; i++){
            if(bit & (1<<i))idx.pb(i);
        }
        if(idx.size()!=3)continue;
        ans += 1LL*cnt[comb[idx[0]]]*cnt[comb[idx[1]]]*cnt[comb[idx[2]]];
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3568
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;

long long mod = 1e9 + 7; 

long long res[3010][3010];



int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	res[1][1] = 1;
	
	for(int i = 2; i <= n; i++){
//		if(i == 1) continue;
		
		char c = s[i-2];
//		cout<<"char:   "<<c<<endl;
		
		if(c == '<'){
			for(int j = 1; j < i+1; j++){
				res[i][j] = res[i-1][j-1] + res[i][j-1];
				res[i][j] %= mod;
			}
		} 
		else{
			for(int j = i; j > 0; j--){
				res[i][j] = res[i][j+1] + res[i-1][j];
				res[i][j] %= mod;
			}
		}		
	}
	
	long long ans = 0;
	
	for(int i = 1; i<=n; i++){
		ans += res[n][i];
		ans %= mod;
	}
	
//	for(int i = 1; i<=4; i++){
//		for(int j = 0; j<5; j++){
//			cout<<res[i][j]<<" ";
//		}
//		cout<<endl;
//	}	
	
	cout<<ans;
}















Measured memory_bytes: 69120
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	$ls[$_]?$sum_l[$s[$_]+1]++:$sum_s[$s[$_]]++for 0..$n-1;
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(@sa){
			$sa[$buf[$s[$_-1]]++]=$_-1if$_>=1&&!$ls[$_-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms=grep!$ls[$_-1]&&$ls[$_],1..$n-1;
	my@lms_map=(-1)x($n+1);
	my$m=@lms;
	for(0..$m-1){
		$lms_map[$lms[$_]]=$_;
	}
	@sa=$induce->(@lms);
	if($m){
		my@sorted_lms=grep$lms_map[$_]!=-1,@sa;
		my@rec_s;
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms[$lms_map[$l]+1]//$n;
			my$end_r=$lms[$lms_map[$r]+1]//$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 251964
import math
N = int(input())
T,A = 1,1
for _ in range(N):
    t,a = map(int,input().split())
    k1 = T//t
    if T%t>0:
        k1 += 1
    k2 = A//a
    if A%a>0:
        k2 += 1
    k = max(k1,k2)
    T = k*t
    A = k*a
print(T+A)

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    int maxi = A.at(0), mini = maxi;
    for (int i=1; i<N; i++) {
        maxi = max(maxi, A.at(i));
        mini = min(mini, A.at(i));
    }
    cout << maxi - mini << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, L;
int a[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int pos = -1;
  for (int i = 0; i + 1 < N; i++) {
    if (a[i] + a[i + 1] >= L) pos = i;
  }
  if (pos < 0) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  vector<int> v(1, pos + 1);
  for (int i = pos - 1; i >= 0; i--) {
    v.emplace_back(i + 1);
  }
  for (int i = pos + 1; i < N - 1; i++) {
    v.emplace_back(i + 1);
  }
  reverse(v.begin(), v.end());
  for (int vv : v) {
    cout << vv << endl;
  }

  return 0;
}

Measured memory_bytes: 1784
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      int p = 0;
      for (int ii = 1; ii <= n; ii++) {
        if (isPrime(ii)) {
          p++;
        }
      }
      out += p + "\n";
    }
    System.out.print(out);
  }

  private static boolean isPrime (int n) {
    if (n == 1) {
      return false;
    }
    if (n == 2) {
      return true;
    }
    if (n % 2 == 0) {
      return false;
    }
    for (int ii = 3; ii * ii <= n; ii += 2) {
      if (n % ii == 0) {
        return false;
      }
    }
    return true;
  }
}

Measured memory_bytes: 19548
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n,a,b=L()
s=S()
passed=0
rankbyb=0
for i in range(n):
    if s[i]=='b':
        rankbyb+=1
        
    if s[i]=='a' and passed<a+b:
        print('Yes')
        passed+=1
    elif s[i]=='b' and passed<a+b and rankbyb<=b:
        print('Yes')
        passed+=1
    else:
        print('No')

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<class T> struct Zip{
    vector<T> val;
    unordered_map<T, int> idx;

    void add(const T v){ val.emplace_back(v); }

    void zip(){
        sort(val.begin(), val.end());
        val.erase(unique(val.begin(), val.end()), val.end());
        for(int i = 0;i < val.size();i++) idx[val[i]] = i;
    }

    int operator[] (const T v) { return idx[v]; }
    T operator() (const int i) { return val[i]; }
    int size() { return val.size(); }
};


template <class Monoid> struct SegmentTree{
	using Func = function<Monoid(Monoid, Monoid)>;

	int size;
	vector<Monoid> seg;
	const Func merge;
	const Monoid def;

	SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
		for(size = 1; size <= n; size <<= 1);
		seg.assign(size*2, def);
	}

	Monoid& operator[] (int i) { return seg[i+size]; };
	void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); }

	void update(int i, Monoid val){
		seg[i += size] = val;
		while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
	}

	void add(int i, Monoid val){ update(i, val+seg[i+size]); }

	Monoid get(int a, int b){
		Monoid l = def, r = def;
		for(a += size, b += size; a < b; a >>= 1, b >>= 1){
			if(a & 1) l = merge(l, seg[a++]);
			if(b & 1) r = merge(seg[--b], r);
		}
		return merge(l, r);
	}
};

int a[200010];
int ans[200010];
vector<int> tree[200010];
Zip<int> zip;

SegmentTree<int> seg(300000, 0, [](int a, int b){
	return max(a, b);
});

void dfs(int idx, int par){
	int old = seg[zip[a[idx]]];
	int num = seg.get(0, zip[a[idx]])+1;
	seg.update(zip[a[idx]], max(old, num));
	ans[idx] = seg.get(0, zip.size());
	
	for(auto e: tree[idx]){
		if(e == par) continue;
		dfs(e, idx);
	}
	seg.update(zip[a[idx]], old);
	return;
}

signed main(){
	int n;
	cin >> n;

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

	int u, v;
	for(int i = 0;i < n-1;i++){
		cin >> u >> v;
		u--; v--;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}

	dfs(0, -1);

	for(int i = 0;i < n;i++){
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 70024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e15;


int main(){
    ll n,q;
    cin >> n >> q;
    vector<ll> s(n),t(n),x(n);
    map<ll,multiset<ll>> u;
    multiset<ll> w;
    rep(i,n){
        cin >> s[i] >> t[i] >> x[i];
        s[i]-=x[i];
        t[i]-=x[i];
        u[s[i]].insert(x[i]);
        u[t[i]].insert(-x[i]);
        
    }
    rep(i,q){
        ll d;
        cin >> d;
        u[d].insert(INF);
    }
    vector<ll> ans;
    for(auto [a,b] :u){
        for(auto p:b){
            if(p<0){
                w.erase(w.find(abs(p)));
            }
            else if(p>0 && p!=INF){
                w.insert(p);
            }
            else if(p==INF){
                if(w.size()==0){
                    ans.push_back(-1);
                    continue;
                }
                auto it=w.begin();
                ans.push_back(*it);
            }
        }
    }
    rep(i,q){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 103528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,m;
    int cnt = 0;
    cin >> n;
    vector<ll> d(n);
    rep(i, n)cin >> d[i];
    cin >> m;
    vector<ll> t(m);
    rep(i, m)cin >> t[i];
    if (n < m) {
        NO;
        return 0;
    }
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());
    rep(i, m){
        if (n < cnt) {
            NO;
            return 0;
        }
        nfor(j, cnt, n){
            if (t[i] == d[j]) {
                cnt = j + 1;
                goto loopend;
            }
        }
        NO;
        return 0;
    loopend:;
    }
    YES;
    return 0;
}


Measured memory_bytes: 3328
a,b=map(int,input().split())
if a==b:
  print(0)
if a>b>0 or 0>a>b:
  print(2+a-b)
if a>0 and b==0:
  print(1+a)
if a>0 and b<0:
  print(1+abs(a+b))
if a==0 and b<0:
  print(-b+1)
if a<b<=0 or 0<=a<b:
  print(b-a)
if a<0 and b>0:
  print(1+abs(a+b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
ll N, K;
ll R, S, P;
string T;

signed main()
{
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    ll res = 0;
    string str = "";
    rep(i, N)
    {
        if (T[i] == 'r') { // P
            str += "p";
        } else if (T[i] == 's') { // R
            str += "r";
        } else { // S
            str += "s";
        }
    }
    for (int i = K; i < N; ++i) {
        if (str[i - K] == str[i]) {
            str[i] = '*';
        }
    }
    rep(i, N)
    {
        if (str[i] == 'p') {
            res += P;
        } else if (str[i] == 'r') {
            res += R;
        } else if (str[i] == 's') {
            res += S;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int d[2][100000];
vector<int>G[100000];
bool used[100000];
void dfs(int s,int i){
    memset(used,0,sizeof(used));
    d[i][s] = 0;
    used[s] = true;
    stack<int>S;
    S.push(s);
    while(!S.empty()){
        int k = S.top();
        S.pop();
        for(auto x: G[k]){
            if(!used[x]){
                S.push(x);
                d[i][x] = d[i][k]+1;
                used[x] = true;
            }
        }
    }
}
int main(){
    int n;
    cin >> n;
    int a, b;
    rep(i,n-1){
        cin >> a >> b;
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    dfs(0,0);
    dfs(n-1,1);
    a = b = 0;
    rep(i,n){
        if(d[0][i] <= d[1][i]){
            a++;
        }else b++;
    }
    cout << (a>b? "Fennec":"Snuke") << endl;
}

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

int main() {
  int N; cin >> N;
  int H[N + 1]; for (int i = 0; i < N; ++i) cin >> H[i];
  int res = 0;
  H[N] = 0;
  for (int i = 0; i < N; ++i) {
    if (H[i] > H[i + 1]) res = res + H[i] - H[i + 1];
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
//#define N 1000000007

using namespace std;

int main(){
    lli n,a,sum=0,x=0,y,ans;
    vector<lli> v;
    lli i;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        v.push_back(a);
        sum+=a;
    }
    x=v[0];
    y=sum-x;
    ans=abs(x-y);
    sum-=a;
    rep(i,1,n-1){
        x+=v[i];
        y=a+sum-x;
        ans=min(ans,abs(x-y));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2420
/*
Problem :
Algorithm :
Status :
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG printf("Passing Line %d in Function [%s].\n",__LINE__,__FUNCTION__);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const string S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const int L = 128;

int n;
vector<string> vec;

int Query(string s){
    cout << "? " << s << endl;
    int res;
    cin >> res;
    return res;
}

string Merge(int l,int r){
    if(l == r)
        return vec[l];
    int mid = (l + r) >> 1;
    string sl = Merge(l,mid),sr = Merge(mid + 1,r);
    string s = "";
    int lenl = sl.length(),lenr = sr.length();
    for(int i = 0,j = 0,k = n - lenl;i <= lenl;i++){
        if(i == lenl){
            while(j < lenr){
                s += sr[j];
                j++;
            }
            break;
        }
        while(j < lenr && Query(s + sr[j] + sl.substr(i)) == k - 1){
            s += sr[j];
            j++;
            k--;
        }
        s += sl[i];
    }
    return s;
}

int main(){
    // freopen("data.in","r",stdin);
    // freopen("data.out","w",stdout);
    for(char c : S){
        string s(L,c);
        int num = L - Query(s);
        if(num)
            vec.push_back(s.substr(0,num));
        n += num;
    }
    string ans = Merge(0,vec.size() - 1);
    cout << "! " << ans << endl;
    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define NEXTP(x) next_permutation(x.begin(),x.end())
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n , k;
	cin >> n >> k;
	ll ans=0;
	FOR(i,1,min(k+1,n+1)){
		ll a = i;
		ll b = (a+n)/k-(2*a)/k;
		if((2*a)%k==0)b++;
		//cout<<a<<" "<<b<<endl;
		if(2*i%k==0)ans+=b*b*b;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
	
	static class Pair{
		public final int first;
		public final int second;
		
		public Pair(int first,int second)
		{
			this.first = first;
			this.second = second;
		}
	}
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//存取数据的
		Stack<Integer> so = new Stack<Integer>();
		Stack<Pair> ps = new Stack<Pair>();
		
		char[] chars = null;
		int sum=0;
		//
		if(sc.hasNextLine())
		{
			String line = sc.nextLine();
			chars = line.toCharArray();
		}
		
		for(int i=0;i<chars.length;i++)
		{
			if(chars[i]=='\\') //第一个是反义
			{
				so.push(i);
			}
			else if(chars[i]=='/'&&so.size()>0)
			{
				//表面有一个水坑
				int j = so.peek();//取出一个
				so.pop();
				sum += i-j;
				int a = i-j;
				while(ps.size()>0&&ps.peek().first>j)
				{
					a += ps.peek().second;
					ps.pop();
				}
				
				ps.push(new Pair(j, a));
			}
		}

		Stack<Integer> s = new Stack<Integer>();
		while(ps.size()>0)
		{
			s.push(ps.peek().second);
			ps.pop();
		}
		
		System.out.println(sum);
		System.out.print(s.size());
		while(s.size()>0)
		{
			System.out.print(" "+s.peek());
			s.pop();
		}
		System.out.println();
	}
}



Measured memory_bytes: 29728
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int A=0;
  for (int i=0; cin >> ch; i++) {
    if (ch=='\\') {
      S1.push(i);
    } else if (ch=='/' && S1.size()>0) {
      int j=S1.top();
      S1.pop();
      A+=i-j;
      int a=i-j;
      while (S2.size()>0 && S2.top().first>j) {
        a+=S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> L;
  while (S2.size()>0) {
    L.push_back(S2.top().second);
    S2.pop();
  }
  reverse(L.begin(),L.end());
  printf("%d\n",A);
  printf("%d",L.size());
  for (int k=0; k<L.size(); k++) {
    printf(" %d",L[k]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 3272
#include<stdio.h>
int main(void){
  int n,x,count=0,inf;
  int a,b,c; //??????a<b<c?????????????????????????????°?????????????????§?????????
  for(inf=0;inf==0;inf*=0){
  scanf("%d %d",&n,&x);
  count = 0;
    if(n==0&&x==0){
      break;
    }else{
      for(a=1;a<=n-2;a++){ //a<b<c??????????????????????????¶????°????????????????
        for(b=2;b<=n-1;b++){
          for(c=3;c<=n;c++){
            if(a<b&&b<c){ //a<b<c?????????????????????????????§??????
              if(a+b+c==x){
                count++;
              }
            }
          }
        }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

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

int main() {
  int A , B , C ;
  cin >> A >> B >> C ;
  
  if (A==5 && B==5 && C==7) {
    cout << "YES" << endl;
}
   else if (A==5 && B==7 && C==5) {
    cout << "YES" << endl;
}
   else if (A==7 && B==5 && C==5) {
    cout << "YES" << endl;
}
  else {
    cout << "NO" << endl;
}

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Program {

        public static void Main(string[] args) {

            var x = 0;

            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var xList = new List<int>();
            xList.Add(0);

            for(int i = 0; i < n; i++) {

                if(s[i] == 'I') {

                    x++;

                } else if(s[i] == 'D') {

                    x--;

                }

                xList.Add(x);

            }

            Console.WriteLine(xList.Max());

        }

    }

Measured memory_bytes: 13268
import sys
input = sys.stdin.readline
def main():
    N,M = map(int,input().split())
    A= list(map(int,input().split()))
    A = sorted(A)

    BC=[list(map(int,input().split())) for i in range(M)]
    BC = sorted(BC, key=lambda x: x[1],reverse=True)
    index=0
    max_index=len(A)
    
    for B,C in BC:
        temp = [C]*B
        for t in temp:
            if max_index>index and  t>A[index]:
                A[index] = t
            else:
                return A
            index+=1
    return A
    
if __name__ == '__main__':
    A=main()
    print(sum(A))


Measured memory_bytes: 33688
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author varun on 7/1/2018
 * @project CompetitiveProgramming
 */
public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; ++i) arr[i] = scanner.nextInt();
        Arrays.sort(arr);
        System.out.println(arr[N-1] - arr[0]);
    }
}


Measured memory_bytes: 23124
#include<stdio.h>

int main(){
  int n,k,ans=0,who;
  int i,j;
  scanf("%d %d",&n,&k);
  int d,a[n+1];

  for(i=0;i<n+1;i++)
    a[i]=0;

  for(i=0;i<k;i++){
    scanf("%d",&d);
    for(j=0;j<d;j++){
      scanf("%d",&who);
      a[who]++;
    }
  }
  for(i=1;i<=n;i++){
    //printf("%d:%d\n",i,a[i]);
    if(a[i]==0)
      ans++;
  }
  printf("%d",ans);
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC098C - Attention
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  map<int, int> left; // i番目の人がリーダーの時に、東に向いた人数
  map<int, int> right; // i番目の人がリーダーの時に、西に向いた人数

  rep(i, N) {
    // i がリーダー
    int ln = 0, rn = 0;
    if (i > 0) {
      left[i] = left[i-1] + (S[i-1] == 'E' ? 0 : 1);
    } else {
      left[i] = 0;
    }
    // N-iがリーダー
    if (N-1-i < N-1) {
      right[N-1-i] = right[N-i] + (S[N-i] == 'W' ? 0 : 1);
    } else {
      right[N-1-i] = 0;
    }
    //cout << "i=" << i << ",left[i]=" << left[i] << ",N-i=" << N-i << ",right[N-i-1]=" << right[N-i-1] << endl;
  }
  int minNum = INT_MAX, sum;
  rep(i, N) {
    sum = left[i] + right[i];
    if (minNum > sum) {
      minNum = sum;
    }
  }

  cout << minNum << endl;
  return 0;
}



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

int gcd(int a, int b) {
	if(a > b)
		return gcd(b,a);
	if(b % a == 0)
		return a;
	return gcd(a, b-a);
}

int main() {
	int n, m;
	cin >> n >> m;
	string s1, s2;
	cin >> s1 >> s2;
	int x = gcd(n,m);
	long long lcm = ((long long)n*m)/x;
	if(s1[0] != s2[0]) {
		cout << -1 << '\n';
		return 0;
	}
	if(x == 1) {
		cout << lcm << '\n';
		return 0;
	}
	vector<char> good(lcm, '0');
	for(int i=0; i<n; i++) {
		long long id = i*(lcm/n);
		good[id] = s1[i];
	}
	for(int i=0; i<m; i++) {
		long long id = i*(lcm/m);
		if(good[id] != '0' && good[id] != s2[i]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << lcm << '\n';
}



Measured memory_bytes: 23552
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;


int main(){
    int p,q;
    while(cin>>p>>q){
        
        
        bool amari[1000000]={0};
        
        string s;

        bool flag = false;
        
        queue<int> qu;
        while(1){
            p=p%q*10;
            if(p==0)break;
            //cout<<p<<endl;
            if(amari[p/10]){
                flag=true;
                break;
            }
            amari[p/10]=true;
            qu.push(p/10);
            
            s+=p/q+'0';
        }
        cout<<s<<endl;
        if(flag){
            flag=true;
            while(!qu.empty()){
                if(qu.front()==p/10)flag=false;
                if(flag)cout<<" ";
                else cout<<"^";
                qu.pop();
            }
            cout<<endl;
        }
    }
       
}

Measured memory_bytes: 2184
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char *argv[])
{
	int n;
	LL C;
	cin >> n >> C;
	vector<LLLL> cd, dc;
	vector<LL> b1(n+1), b2(n+1);
	for (int i = 0; i < n; ++i) {
		LL x, v;
		cin >> x >> v;
		cd.push_back(LLLL(x, v));
	}
	sort(cd.begin(), cd.end());
	dc = cd;
	for (int i = 0; i < n; ++i) {
		dc[i].first = C - cd[i].first;
	}
	sort(dc.begin(), dc.end());

	LL ans = 0, tot = 0;
	for (int i = 0; i < n; ++i) {
		tot += cd[i].second;
		ans = max(ans, tot - cd[i].first);
		b1[i+1] = ans;
	}
	ans = 0;
	tot = 0;
	for (int i = 0; i < n; ++i) {
		tot += dc[i].second;
		ans = max(ans, tot - dc[i].first);
		b2[i+1] = ans;
	}

	tot = 0;
	for (int i = 0; i < n; ++i) {
		LL r = max(0LL, b2[n - (i + 1)] - cd[i].first);
		tot += cd[i].second;
		ans = max(ans, tot - cd[i].first + r);
	}
	tot = 0;
	for (int i = 0; i < n; ++i) {
		LL r = max(0LL, b1[n - (i + 1)] - dc[i].first);
		tot += dc[i].second;
		ans = max(ans, tot - dc[i].first + r);
	}

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


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

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

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && b==c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

/*
int digits(int n) {
    return n.to!string.map!(c => c - '0').sum;
}
*/

int digits(int n) {
    if (n == 0) return 0;

    int x = 0;
    while (n > 0) {
        x += n % 10;
        n /= 10;
    }
    return x;
}

int calc(int n) {
    int ans = int.max;
    for (int a = 1; a < n; a++) {
        int b = n - a;
        ans = min(ans, digits(a) + digits(b));
    }
    return ans;
}

void main() {
    int n = readint;
    auto ans = calc(n);
    writeln(ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


bool string_is_parindrome(const std::string& S) {
  for (int i = 0, N = S.size(); i < N / 2; i ++)
    if (S[i] != S[N - 1 - i])
      return false;

  return true;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  int N = S.size();

  if (string_is_parindrome(S) &&
      string_is_parindrome(S.substr(0, (N - 1) / 2)) &&
      string_is_parindrome(S.substr((N + 3) / 2 - 1))) {

    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		long takahashi = sc.nextLong();
		long aoki = sc.nextLong();
		long count = sc.nextLong();

		if(count <= takahashi){
			takahashi = takahashi - count;
		}else if((count > takahashi) && (count < (takahashi + aoki))){
			aoki = aoki - (count - takahashi);
			takahashi = 0;
		}else{
			takahashi = 0;
			aoki = 0;
		}
		System.out.println(takahashi + " " + aoki);
	}
}

Measured memory_bytes: 21716
#include <iostream>

using namespace std;
int main()
{
	int H, R;

	cin >> H;
	cin >> R;

	if (H >= 0)
	{
		cout << 1 << endl;
	}
	else if(H + R == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))


if N == 2:
    print(A[-1], A[0])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[-1], A[0])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)


Measured memory_bytes: 14052
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

class UF
{
	private:
		vector<int> parent;

	public:
		UF(int n)
		{
			parent = vector<int>(n, -1);
		}

		int getparent(int n)
		{
			if(parent[n] == -1) return n;
			return parent[n] = getparent(parent[n]);
		}

		void connect(int x, int y)
		{
			x = getparent(x);
			y = getparent(y);
			if(x == y) return;
			if(x > y) swap(x, y);
			parent[y] = x;
		}

};

int main()
{
	int n, m;
	cin >> n >> m;
	UF uf(n);
	for(int i = 0; i < m; i++){
		int x, y, z;
		cin >> x >> y >> z;
		x--;
		y--;
		uf.connect(x, y);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(uf.getparent(i) == i) ans++;
	}
	cout << ans << endl;
}

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

N, M = map(int, input().split())
S = list(input().rstrip())

def cost(S):
    minCost = [-1]*(N+1)
    minCost[0] = 0
    ind = 1
    for i,s in enumerate(S):
        if s == "1":
            continue
        while i < ind <= min(i+M, N):
            if S[ind] == "0":
                minCost[ind] = minCost[i] + 1
            ind += 1
    return minCost

M1 = cost(S)
M2 = cost(S[::-1])[::-1]
if M1[-1] == -1:
    print(-1)
else:
    C = M1[-1]
    Inds = [10**14]*(C+1)
    for i, (m1, m2) in enumerate(zip(M1, M2)):
        if m1 + m2 == C:
            Inds[m1] = min(Inds[m1], i)
    ans = []
    for i1, i2 in zip(Inds, Inds[1:]):
        ans.append(i2-i1)
    print(*ans)


Measured memory_bytes: 23920
#include<bits/stdc++.h>
using namespace std;
int w,b,mp[200][200];
int main(){
	scanf("%d%d",&w,&b);
	if (w==1&&b==1){
		printf("%d %d\n",100,100);
		for (int i=1; i<=100; ++i){
		for (int j=1; j<=100; ++j) j<=50?putchar('.'):putchar('#');
			puts("");
		}
		return 0;
	}
	--w; --b;
	int i,j;
	if (w)
	for (i=2; i<100; i+=3)
	for (j=2; j<100; j+=3){
		--w;
		mp[i][j]=1;
		mp[i-1][j-1]=mp[i-1][j]=mp[i-1][j+1]=mp[i][j-1]=mp[i][j+1]=mp[i+1][j-1]=mp[i+1][j]=mp[i+1][j+1]=2;
		if (w==0) goto g;
	}
	g:;
	if (b)	
	for (i=53; i<100; i+=3)
	for (j=2; j<100; j+=3)
	if (!mp[i][j]){
		--b;
		mp[i][j]=2;
		mp[i-1][j-1]=mp[i-1][j]=mp[i-1][j+1]=mp[i][j-1]=mp[i][j+1]=mp[i+1][j-1]=mp[i+1][j]=mp[i+1][j+1]=1;
		if (b==0) goto gg;
	}
	gg:;
	printf("%d %d\n",100,100);
	for (int i=1; i<=100; ++i){
		for (int j=1; j<=100; ++j) mp[i][j]==1?putchar('.'):(mp[i][j]==2?putchar('#'):(i<52?putchar('#'):putchar('.')));
		puts("");
	}
}

Measured memory_bytes: 384
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "abc164_d.cpp"

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

  string s;
  cin >> s;
  int n = s.length();

  ll count[2019] = {};

  ll cur = 0;
  ll ten = 1;
  ll ans = 0;
  count[0] = 1;

  for (int i = n - 1; i >= 0; i--) {
    cur = (cur + (s[i] - '0') * ten) % 2019;
    ten = (ten * 10) % 2019;
    ans += count[cur];
    count[cur]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3772
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 100100100;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n == 0) break;

		int d[10][10];
		for(int i=0; i<10; i++)
			for(int j=0; j<10; j++){
				if(i == j) d[i][j] = 0;
				else d[i][j] = INF;
			}
		for(int i=0; i<n; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			d[a][b] = c;
			d[b][a] = c;
		}

		for(int k=0; k<10; k++){
			for(int i=0; i<10; i++){
				for(int j=0; j<10; j++){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		int s[10] = {};
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(d[i][j] != INF){
					s[i] += d[i][j];
				}
			}
		}
		
		int num, ans = INF;
		for(int i=0; i<10; i++){
			if(s[i] != 0 && s[i] < ans){
				num = i;
				ans = s[i];
			}
		}
		printf("%d %d\n", num, ans);
	}
	return 0;
}

Measured memory_bytes: 2688
import Control.Applicative
import Control.Monad
import qualified Data.Array.Unboxed as A
import Data.Array.Unboxed ((!), (//))
import Data.List (foldl', unfoldr)
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy.Char8 as BLC

type Field = A.Array Loc Bool
type Loc = (Int, Int)
size :: Int
size = 8

bombArea :: Loc -> [Loc]
bombArea (x,y) = [
        (xi, y) | xi <- [max 0 (x-3) .. min (x+3) (size-1)], xi /= x
        ] ++ [(x, yi) | yi <- [max 0 (y-3) .. min (y+3) (size-1)]]

bomb :: Field -> Loc -> Field
bomb f l = let
    chain = filter (f !) . bombArea $ l
    burnt = f // zip chain (repeat False)
    in
        foldl' bomb burnt chain

readField :: [String] -> Field
readField = A.listArray ((0,0), (size-1,size-1))
    . map (toEnum . read . return) . concat
    
showField :: Field -> BLC.ByteString
showField = BLC.unlines . map BLC.concat
    . (takeWhile (not . null) . unfoldr (Just. splitAt size))
    . map (BLC.pack . show . (fromEnum :: Bool -> Int)) . A.elems

main = do
    n <- readLn
    answers <- replicateM n (do {_ <- getLine; solve})
    forM_ (zip answers [1..]) $ \(a,i) -> do
        putStrLn $ "Data " ++ show i ++ ":"
        BLC.putStr a

solve :: IO BLC.ByteString
solve = do
    field <- readField <$> replicateM size getLine
    y <- readLn
    x <- readLn
    return . showField . bomb field $ (x-1,y-1)

Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; string s; cin>>N>>s;
  int ans=1;
  char last = s[0];
  for (int i=1; i<N; i++) {
    if (last == s[i]) continue;
    ans++; last = s[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
struct NODE{
int to , dist , cost , used;
NODE(int a,int b,int c,int d){
to = a , dist = b , cost = c , used = d;
}
};
bool operator < (const NODE &a,const NODE &b){
return a.dist != b.dist ? a.dist > b.dist : a.cost > b.cost;
}
int main(){
int n,m;
while(cin >> n >> m && (n||m) ){
vector< vector<NODE> > g(n);
bool done[10000] = {0};
int ans = 0;
rep(i,m){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--,b--;
g[a].push_back(NODE(b,c,d,i));
g[b].push_back(NODE(a,c,d,i));
}
priority_queue <NODE> Q;
Q.push(NODE(0,0,0,m));
while(Q.size()){
NODE q = Q.top(); Q.pop();
if(done[q.to])continue;
else done[q.to] = true , ans += q.cost;
rep(i,g[q.to].size()) Q.push(NODE(g[q.to][i].to,q.dist+g[q.to][i].dist,g[q.to][i].cost,g[q.to][i].used));
}
cout << ans << endl;		
}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
int n;
int color[2][1000][1000];
int db[2<<17];
int dx[]={1,1,-1,-1},dy[]={1,-1,1,-1};
void dfs(int x,int y,int d,int col,int c)
{
	color[c][x][y]=col;
	for(int i=0;i*i<=d;i++)
	{
		if(db[d-i*i]<0)continue;
		int j=db[d-i*i];
		for(int r=0;r<4;r++)
		{
			int tx=x+dx[r]*i,ty=y+dy[r]*j;
			if(tx<0||ty<0||tx>=2*n||ty>=2*n||color[c][tx][ty])continue;
			dfs(tx,ty,d,col==1?2:1,c);
		}
	}
}
main()
{
	cin>>n;
	for(int i=0;i<2<<17;i++)db[i]=-1;
	for(int i=0;i*i<2<<17;i++)db[i*i]=i;
	for(int i=0;i<2;i++)
	{
		int d;cin>>d;
		for(int x=0;x<2*n;x++)for(int y=0;y<2*n;y++)if(!color[i][x][y])dfs(x,y,d,1,i);
	}
	vector<pair<int,int> >a;
	for(int x=0;x<2*n;x++)
	{
		for(int y=0;y<2*n;y++)
		{
			if(color[0][x][y]==1&&color[1][x][y]==1)a.push_back(make_pair(x,y));
		}
	}
	for(int i=0;i<n*n;i++)cout<<a[i].first<<" "<<a[i].second<<endl;
}


Measured memory_bytes: 38772
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

int main(int argc, char const *argv[]){
	int pa,pz;
	char str[200007];
	scanf("%s",str);
	for (pa = 0; pa < strlen(str); ++pa)
	{
		if(str[pa] == 'A')	break;
	}
	for (pz = strlen(str) - 1; pz >= 0; pz--)
	{
		if(str[pz] == 'Z')	break;
	}
	printf("%d\n", pz - pa + 1);	
	return 0;
}


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

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/



signed main() {
	ll n;
	cin >> n;
	vector<ll> a(n,0);
	rep(i,n)cin>>a[i];
	ll ans=a[0];
	repeq(i,n-1)ans=gcd(ans,a[i]);
	p(ans);

		

	return 0;
}



Measured memory_bytes: 1024
#include <cstdio>

const int N(45), Mod(1e9 + 7);
int n, X, Y, Z, ans = 1, f[N][1 << 17];

int main()
{
	scanf("%d%d%d%d", &n, &X, &Y, &Z); int S = (1 << (X + Y + Z)) - 1;
	int H = (1 << (Z - 1)) | (1 << (Y + Z - 1)) | (1 << (X + Y + Z - 1));
	for (int i = 1; i <= n; i++) ans = 10ll * ans % Mod;
	for (int i = (f[0][0] = 1, 0); i < n; i++)
		for (int T = 0; T <= S; T++) if (f[i][T])
			for (int j = 1, s; j <= 10; j++)
				if (((s = ((T << j) | (1 << (j - 1))) & S) & H) != H)
					f[i + 1][s] = (f[i + 1][s] + f[i][T]) % Mod;
	for (int i = 0; i <= S; i++) ans = (ans - f[n][i] + Mod) % Mod;
	printf("%d\n", ans);
	return 0;
}


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

vector<pair<int,int> > ed;
int l[100];

int fi(int nw)
{
	if(l[nw]==nw)return nw;
	return l[nw]=fi(l[nw]);
}

void uni(int a,int b)
{
	l[a]=b;
}

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		ed.push_back(make_pair(a,b));
	}
	int ans=0;
	for(int i=0;i<m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			l[j]=j;
		}
		for(int j=0;j<m;j++)
		{
			if(i==j)
				continue;
			if(fi(ed[j].first)!=fi(ed[j].second))
			{
				uni(fi(ed[j].first),fi(ed[j].second));
			}
		}
		if(fi(ed[i].first)!=fi(ed[i].second))
			ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int mp[5][5];

int main(){
	int n;
	cin>>n;
	rep(k,n){
		rep(i,5){
			rep(j,5){
				cin>>mp[i][j];
			}
		}
		int cnt=0;
		for(int i=1;i<6;i++){
			for(int j=1;j<6;j++){
				for(int p=0;p+i<6;p++){
					for(int q=0;q+j<6;q++){
						int check=0;
						for(int r=0;r<i;r++){
							for(int s=0;s<j;s++){
								if(mp[p+r][q+s]==1)check++;
							}
						}
						if(check==i*j){
							cnt=max(cnt,i*j);
						}
					}
				}
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

ans = [[None]*W for _ in range(H)]
y = x = 0
for i,a in enumerate(A):
    for j in range(a):
        ans[y][x] = str(i+1)
        if y%2:
            if x==0:
                y += 1
            else:
                x -= 1
        else:
            if x==W-1:
                y += 1
            else:
                x += 1
for row in ans:
    print(*row)

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

int N, M, L;
vector<double> P, T, V;
double F[51];
double C[51][51];
double pTable[101][51];

int main(){
    cout.precision(16);
    cout.setf(ios::fixed);
    
    F[0] = 1;
    for(int i=1; i<51; i++)
        F[i] = F[i-1] * i;
    for(int i=0; i<51; i++)
        for(int j=0; j<=i; j++)
            C[i][j] = F[i] / F[i-j] / F[j];
    
    cin >> N >> M >> L;
    P.resize(N); T.resize(N); V.resize(N);
    for(int i=0; i<N; i++)
        cin >> P[i] >> T[i] >> V[i];
    
    double tmp1[51], tmp2[51];
    for(int i=0; i<N; i++){
        tmp1[0] = tmp2[0] = 1;
        for(int j=1; j<=M; j++){
            tmp1[j] = tmp1[j-1] * P[i]/100;
            tmp2[j] = tmp2[j-1] * (1 - P[i]/100);
        }
        
        for(int j=0; j<=M; j++){
            pTable[i][j] = tmp1[j] * tmp2[M-j] * C[M][j];
        }
    }
    
    for(int i=0; i<N; i++){
        double ans = 0;
        for(int k=0; k<=M; k++){ //????????????i????????????????????????
            double ti = L / V[i] + T[i]*k;
            double ttans = 1;
            for(int j=0; j<N; j++) if(i != j){
                double tans = 0;
                for(int l=0; l<=M; l++){ //????????????j????????????????????????
                    double tj = L / V[j] + T[j]*l;
                    if(ti < tj){
                        tans += pTable[j][l];
                    }
                }
                ttans *= tans;
            }
            ans += ttans * pTable[i][k];
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3340
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;

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

	unordered_map<string, int> c;
	int n;
	for (cin >> n; n--;) {
		string s;
		cin >> s;
		sort(begin(s), end(s));
		c[s]++;
	}
	long long r = 0;
	for (auto const& x : c) {
		r += (long long) x.second * (x.second - 1) / 2;
	}
	cout << r << '\n';
	return 0;
}


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

int main (void){
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632