akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
ll permutationMethod(int n, int r)
{
    r = n - r;
    ll sum = 1;
    int i;
    for (i = n; i >= r + 1; i--)
        sum = (sum * i) % MOD;
    return sum;
}
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
long long K;
vector<bool> seen;
vector<int> depthSum(100010);
ll dfs(const Graph &G, int K, int now, int from)
{
    int child_can_color = 0;

    if (from == -1)
    {
        child_can_color = K - 1;
    }
    else
    {
        child_can_color = K - 2;
    }

    ll cnt = 1;
    ll cnt_child = 0;
    // 子供の数を数える
    for (auto next_v : G[now])
    {
        if (next_v == from)
        {
            continue;
        }
        cnt_child++;
    }
    cnt *= permutationMethod(child_can_color,cnt_child);
    cnt %= MOD;
    for (auto next_v : G[now])
    {
        if (next_v == from)
        {
            continue;
        }
        cnt *= dfs(G, K, next_v, now);
        cnt %= MOD;
    }
    return cnt;
}

int main()
{
    long long N;
    scanf("%lld", &N);

    scanf("%lld", &K);
    Graph G(N);
    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(N - 1, false);
    cout << (K * dfs(G, K, 0, -1)) % MOD << endl;
}


Measured memory_bytes: 12032
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

H, W = MAP()
a = ["#"*(W+2)]+["#"+input()+"#" for _ in range(H)] + ["#"*(W+2)]

dx = [1, 0]
dy = [0, 1]

comb = [[0]*(W+2) for _ in range(H+2)]
comb[1][1] = 1
q = deque()
q.append((1, 1))
while q:
    i, j = q.popleft()
    for k in range(2):
        y = i+dy[k]
        x = j+dx[k]
        if a[y][x] != "#":
            if comb[y][x] == 0:
                q.append((y, x))
            comb[y][x] = (comb[y][x] + comb[i][j])%mod

print(comb[H][W])


Measured memory_bytes: 84056
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){
    n+= n<0?((-n)/MOD1+1)*MOD1:0;
    return n%=MOD1;
}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod) 繰り返し二乗法*/
ll modpow(ll a, ll n, ll mod){
    ll s[digits(n,2)],ans=1;
    rep(i,0,digits(n,2)){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;
    }
    return n?ans:1;
}
ll inv[200005],finv[200005];
void makeinv(ll n){
    inv[1]=1;finv[0]=finv[1]=1;
    rep(i,2,n+1){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        finv[i] = finv[i - 1] * inv[i] % MOD1;
    }
}
ll modfac(ll n, ll mod){
    ll x=1;
    rep(i,2,n+1){x*=i%mod;x%=mod;}
    return x;
}

int main(void){
    // char ;
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    ll pat[k];
    rrep(i,k,1){
        ll plus=modpow(k/i,n,MOD1);
        rep(j,2,k+1){
            if(i*j>k) break;
            plus-=pat[i*j-1];
        }
        plus=mod(plus);
        // if(plus<0){
        //     plus+=ABS(plus)/MOD1*MOD1;
        // }
        // while(plus<0) plus+=MOD1;
        pat[i-1]=plus;
        ans+=i*plus;
        ans%=MOD1;
        // printf("%lld ",ans);
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2480
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define ll long long
#define     f           first
#define     s           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)

vector<ll> adj[N];
bool visited[N];
const int MAX = 1000001;

// array to store prime factors
int factor[MAX] = { 0 };

// function to generate all prime factors
// of numbers from 1 to 10^6
void generatePrimeFactors()
{
    factor[1] = 1;

    // Initializes all the positions with their value.
    for (int i = 2; i < MAX; i++)
        factor[i] = i;

    // Initializes all multiples of 2 with 2
    for (int i = 4; i < MAX; i += 2)
        factor[i] = 2;

    // A modified version of Sieve of Eratosthenes to
    // store the smallest prime factor that divides
    // every number.
    for (int i = 3; i * i < MAX; i++) {
        // check if it has no prime factor.
        if (factor[i] == i) {
            // Initializes of j starting from i*i
            for (int j = i * i; j < MAX; j += i) {
                // if it has no prime factor before, then
                // stores the smallest prime divisor
                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

// function to calculate number of factors
int calculateNoOFactors(int n)
{
    if (n == 1)
        return 1;

    int ans = 1;

    // stores the smallest prime number
    // that divides n
    int dup = factor[n];

    // stores the count of number of times
    // a prime number divides n.
    int c = 1;

    // reduces to the next number after prime
    // factorization of n
    int j = n / factor[n];

    // false when prime factorization is done
    while (j != 1) {
        // if the same prime number is dividing n,
        // then we increase the count
        if (factor[j] == dup)
            c += 1;

        /* if its a new prime factor that is factorizing n,
           then we again set c=1 and change dup to the new
           prime factor, and apply the formula explained
           above. */
        else {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }

        // prime factorizes a number
        j = j / factor[j];
    }

    // for the last prime factor
    ans = ans * (c + 1);
    return ans;
}
int main()
{

    ll n;
    cin>>n;
    generatePrimeFactors();
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        int k=n-i;
        ans+=calculateNoOFactors(k);
    }
    cout<<ans<<endl;
// getch();
    return 0;
}

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

#define ff              first
#define ss              second
//#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mci             map<char,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
//template <typename T> 

  

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
//       #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif 
//we can create an array of list of size v. Each key will store what neighbour it has
int n;
cin>>n;
int k = n%10;
if(k==2 || k==4 || k==5 || k==7 ||k==9)
cout<<"hon"<<endl;
else if(k==0 || k==1 || k==6 || k==8)
cout<<"pon"<<endl;
else if(k==3)
cout<<"bon"<<endl;
 cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}

Measured memory_bytes: 3808
//ITP 1_4_B
#include <iostream>
#include <iomanip> //これでsetprecisionが使える

using namespace std;

const double pi=3.141592653589; //consistantly
int main(){
double r;
cin >> r;
cout <<fixed << setprecision(6) << r*r*pi << " " << fixed << setprecision(6) << 2.000000 * r * pi << endl;
return 0;
}



Measured memory_bytes: 3276
#include <iostream>
    #include <algorithm>
     
    int main() {
    int n, m;
    std :: cin >> n >> m;
     
    int arr[n];
    for(int i = 0 ; i < n ; i++) std :: cin >> arr[i];
     
    std :: sort(arr , arr + n);
     
    long long sum = 0;
     
    for(int i = 0 ; i < m ; i++) sum += arr[i];
    std :: cout << sum << '\n';
    }

Measured memory_bytes: 3164
#include <math.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  char temp;

  vector<vector<int>> s(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      cin >> temp;
      if (temp == '.') {
        s.at(i).at(k) = 1e6;
      } else {
        s.at(i).at(k) = -10;
      }
    }
  }
  vector<int> x = {1, 0, -1, 0};
  vector<int> y = {0, 1, 0, -1};
  queue<P> que;
  int count = 0;
  que.emplace(ch, cw);
  int th, tw;

  vector<int> wx = {2, 1, 0, -1, -2};
  vector<int> wy = {2, 1, 0, -1, -2};
  queue<P> wq;
  bool check;
  int vx, vy;

  while (!que.empty() || !wq.empty()) {
    while (!que.empty()) {
      th = que.front().first;
      tw = que.front().second;
      check = false;

      for (int i = 0; i < 4; i++) {
        vy = y.at(i);
        vx = x.at(i);

        if (vy + th >= h || vx + tw >= w || vy + th < 0 || vx + tw < 0) {
          continue;
        }
        if (s.at(vy + th).at(vx + tw) == -10) {
          check = true;
        }
        if (s.at(vy + th).at(vx + tw) > count) {
          s.at(vy + th).at(vx + tw) = count;
          que.emplace(vy + th, vx + tw);
        }
      }
      if (check) {
        wq.emplace(th, tw);
      }
      que.pop();
    }

    count++;
    while (!wq.empty()) {
      th = wq.front().first;
      tw = wq.front().second;
      for (int i = 0; i < 5; i++) {
        for (int k = 0; k < 5; k++) {
          vy = wy.at(i);
          vx = wx.at(k);

          if (vy + th >= h || vx + tw >= w || vy + th < 0 || vx + tw < 0) {
            continue;
          }
          if (s.at(vy + th).at(vx + tw) > count) {
            s.at(vy + th).at(vx + tw) = count;
            que.emplace(vy + th, vx + tw);
            // wq.emplace(i + th, i + tw);
          }
        }
      }
      wq.pop();
    }
  }

  if (s.at(dh).at(dw) == 1e6) {
    cout << -1 << endl;
  } else {
    cout << s.at(dh).at(dw) << endl;
  }
  /*
    for (int i = 0; i < h; i++) {
      for (int k = 0; k < w; k++) {
        cout << s.at(i).at(k) << ' ';
      }
      cout << endl;

    }
    */

  return 0;
}

Measured memory_bytes: 7148
#include <vector>
#include <iostream>
#include <valarray>
#include <string>
#include <algorithm>
#include <set>
#include <complex>
#include <cmath>
#include <cstdio>
#define fst first
#define snd second
#define rep(i,n) for(ull i = 0;i<(n);i++)
#define rep1(i,n) for(ull i = 1;i<=(n);i++)
#define revrep(i,n) for(ull i = (n-1);i>=0;i--)
#define all(n) (n).begin(),(n).end()
#define show(x) cout << "debug " << #x << ":" << x << endl;
#define showvec(x) cout << endl << "debug " << #x << ";" << endl; \
    for(ull __i = 0;__i < x.size();__i++){ \
        for(ull __j = 0;__j<x[0].size();__j++){ \
            cout << x[__i][__j] << " "; \
        } \
        cout << endl; \
    } \
    cout << endl;
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b){
	return (conj(a)*b).real();
}

double cross_product(xy_t a, xy_t b){
	return (conj(a)*b).imag();
}

xy_t P[110];

int main(){
	int N = 0;
	double x,y;
	while(~scanf("%lf,%lf",&x,&y)){
		P[N++] = xy_t(x,y);	
	}
	double sum = 0.0;
	for(int i = 0; i+2 < N; i++){
		xy_t a=P[0], b=P[(i+1)%N], c=P[(i+2)%N];
		sum += abs(cross_product(a-b,a-c));
	}
	printf("%.6f\n",abs(sum)/2);
	return 0;
}

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

int main() {
    int n, k, RL = 0, hasi = 0, ans = 0;
    string s;
    cin >> n >> k >> s;
    if(s[0] == 'L' && s[n-1] == 'R') {
        hasi = 2;
    } else if(s[0] == s[n-1]) {
        hasi = 1;
    }
    for(int i = 0; i < n-1; ++i) {
        if(s[i] == 'R' && s[i+1] == 'L') RL++;
        else if(s[i] == s[i+1]) ans++;
    }
    if(k < RL) {
        ans += 2*k;
    } else {
        ans += 2*RL + min(hasi, k - RL);
    }
    cout << min(ans, n-1) << '\n';
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int main()
{
    int h, w;
    while (std::cin >> h >> w) {
        if (h == 0 && w == 0) {
            break;
        }

        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (i == 0 || i == (h-1)) {
                    std::cout << "#";
                } else if (j == 0 || j == (w-1)) {
                    std::cout << "#";
                } else {
                    std::cout << ".";
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;

    }

    return 0;
}


Measured memory_bytes: 3000
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int n,a[100005];
int main()
{
    int shu=0,shu1=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0) shu++;
        if(a[i]%2==0&&a[i]%4!=0)  shu1++;

    }
    if(shu>=n/2)
        cout<<"Yes"<<endl;
    else if(n-shu*2-shu1<=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;
int main(void){
  int x, y, sum1, sum2;
  cin >> x >> y;
  sum1 = 2 * x;
  sum2 = 4 * x;
  if(sum1 > y || sum2 < y || y % 2 == 1){
    cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b,c,d[110],i,e=0,f=0,g=0,x;
	scanf("%d %d %d",&a,&b,&c);
	FOR(i,0,a){
		scanf("%d",&d[i]);
		if(d[i]<=b){
			e++;
		}else if(d[i]<=c){
			f++;
		}else{
			g++;
		}
	}
	x=min(e,f);
	x=min(x,g);
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

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

  ll sum = 0;
  ll ma;
  cin >> ma;
  rep(i, n-1){
    ll a;
    cin >> a;
    chmax(ma, a);
    sum += ma - a;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int main ()
{
    ll n; cin >> n;
    vector < ll > a(n);
    REP(i,n) cin >> a[i];

    ll ans = 0;
    REP(i,n) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i, a, b) for(int i = (a), i##end = (b); i <= i##end; ++ i)
#define CLR(i, a) memset(i, a, sizeof(i))
#define REPD(i, a, b) for(int i = (a), i##end = (b); i >= i##end; -- i)
#define REPG(i, x) for(int i = head[x], v; i; i = edge[i].next)

typedef long long LL;
typedef double DB;
 
#define pc putchar
#define gc getchar
#define endl '\n'
inline LL rd() {	
	char ch = gc(); LL ret = 0, sgn = 1;
	while(ch < '0' || ch >'9') {
		if(ch == '-') sgn = -1;
		ch = gc();
	}
	while(ch >= '0' && ch <= '9')
		ret = ret * 10 + ch - '0', ch = gc();
	return ret * sgn;
}
 
inline void out(LL x) {
	static int buf[50], btp;
	if(x < 0) x = -x, pc('-');
	if(!x) pc('0');
	else {
		btp = 0;
		for(; x; x /= 10) buf[++ btp] = x % 10;
		while(btp) pc('0' + buf[btp --]);
	}
}
 
DB _BEGIN;
#define LOG(x) cerr << #x << ":" << x << endl
#define DBG(...) fprintf(stderr, __VA_ARGS__)
#define OK DBG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
#define _TIME (int((clock() - _BEGIN) / (DB)CLOCKS_PER_SEC * 1000))

/**************************************/

const int N = 250 + 3;

int head[N], cnt;
struct qwq { int v, next; } edge[(210 * 210) << 1];
inline void add(int x, int y) {
	edge[++ cnt] = (qwq) { y, head[x] }, head[x] = cnt;
}
int lft[N], rt[N], lsz, rsz;
const int M = 1e7 + 2;
bool isnotp[M + 1];
int tot, p[700000], vis[N], tim, opn[N], n, a[N];
inline void Sieve() {
	isnotp[1] = 1;
	REP(i, 2, M) {
		if(!isnotp[i]) p[++ tot] = i;
		REP(j, 1, tot) {
			if((LL)i * p[j] > M) break;
			isnotp[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
}

int Aug(int x) {
	// LOG(x);
	REPG(i, x) if(vis[(v = edge[i].v)] != tim) { 
		vis[v] = tim;
		if(!opn[v] || Aug(opn[v])) {
			opn[x] = v, opn[v] = x;
			return 1;
		}
	}
	return 0;
}

int main() {
#ifdef LOCAL
	freopen("light_example_3.in", "r", stdin);
#endif
	Sieve();
	// for(int T = rd(); T; -- T) {
		// cout<<T<<endl;
		n = rd();
		cnt = 0;
		
		lsz = rsz = 0;
		REP(i, 1, n) a[i] = rd();
		
		if(a[1] & 1) rt[++ rsz] = a[1];
		else lft[++ lsz] = a[1];
		REP(i, 2, n) {
			if(a[i - 1] != a[i] - 1) {
				if(a[i] & 1) rt[++ rsz] = a[i];
				else lft[++ lsz] = a[i];
			} 
			if(a[i - 1] + 1 != a[i]) {
				if((a[i - 1] + 1) & 1) rt[++ rsz] = a[i - 1] + 1;
				else lft[++ lsz] = a[i - 1] + 1;
			}
		}
		if((a[n] + 1) & 1) rt[++ rsz] = a[n] + 1;
		else lft[++ lsz] = a[n] + 1;

		REP(i, 1, lsz) {
			REP(j, 1, rsz) {
				int x = lft[i], y = rt[j];
				if(isnotp[abs(x - y)]) continue;
				if(abs(x - y) & 1) add(i, lsz + j), add(lsz + j, i);
			}
		}

		fill(vis + 1, vis + lsz + rsz + 1, 0);
		fill(opn + 1, opn + lsz + rsz + 1, 0);
		tim = 0;
		int ret = 0;
		REP(i, 1, lsz) if(!opn[i]) {
			++ tim;
			ret += Aug(i);
		}

		int ans = ret;
		ans += ((lsz - ret) / 2 + (rsz - ret) / 2) * 2;
		ans += ((rsz - ret) % 2) * 3;
		out(ans), pc(endl);
		// fflush(stdout);

		fill(head + 1, head + lsz + rsz + 1, 0);
	// }

#ifdef LOCAL
	LOG(_TIME);
#endif	
	return 0;
}

Measured memory_bytes: 12800
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n,m;cin>>n>>m;
  int p[m];
  int y[m];
  vector<vector<int>> x(n);
  rep(i, m){
    cin>>p[i]>>y[i];
    x[p[i]-1].pb(y[i]);
  }
  rep(i, n) sort(all(x[i]));

  dump_1d(p, m);
  dump_1d(y, m);
  dump(x[0]);
  dump(x[1]);

  rep(i, m){
    auto num = lower_bound(all(x[p[i]-1]), y[i]) - x[p[i]-1].begin() + 1;
    printf("%06d%06d\n", p[i], num);
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N, ans;
    cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    string X;
    rep(i, N) cin >> s[i] >> t[i];
    cin >> X;
    rep(i, N) {
        ans += t[i];
        if (s[i] == X) ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
require 'pp'

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

s_list = gets_nsp_list
s = []

s_list.each do |c|
  if c == "B"
    s.pop
  else
    s.push(c)
  end
end

puts s.join


Measured memory_bytes: 2300
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll dp[405][405],arr[405];
const ll INF=1e18;

int main()
{jizz
	ll n;
	cin >> n;
	for(int i=1;i<=n;++i)
		cin >> arr[i],arr[i]+=arr[i-1];
	for(int i=1;i<n;++i)
		for(int j=1;j+i<=n;++j)
		{
			dp[j][j+i]=INF;
			for(int k=j;k<j+i;++k)
				dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+arr[j+i]-arr[j-1]);
		}
	cout << dp[1][n] << "\n";
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);

	for (auto &x : A) {
		cin >> x;
	}

	vector<int> x(N), y(N);

	x[0] = A[0];
	for (int i = 1; i < N; ++i) {
		x[i] = gcd(x[i - 1], A[i]);
	}

	y[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; --i) {
		y[i] = gcd(y[i + 1], A[i]);
	}

	int ans = 1;
	for (int i = 0; i < N; ++i) {
		int tmp;
		if (i == 0) {
			tmp = y[1];
		}
		else if (i == N - 1) {
			tmp = x[N - 2];
		}
		else {
			tmp = gcd(x[i - 1], y[i + 1]);
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}


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

using namespace std;

int main () {
	int n, m;
	cin >> n >> m;
	int kol = 0;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			char x;
			cin >> x;
			kol += (x == '#');
		}
	}   
	if (kol != n + m - 1) cout << "Impossible";
	else cout << "Possible";
	return 0;
}

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

int main() {
  char Z;
  cin >> Z;
  string S = "abcdefghijklmnopqrstuvwxyz";
  for (int i = 0; i < 25; i++) {
    if(Z == S.at(i))
    cout << S.at(i + 1) << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int div_ceil(int a, int b){
    return (a + (b - 1)) / b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  int a;
  int idx;
  REP(i,n){
      cin >> a;
  }
  cout << div_ceil(n-1,k-1) << endl;
}


Measured memory_bytes: 256
n, k = [ int(i) for i in input().split()]

x_list = [ int(i) for i in input().split()]

x_plus = sorted([x for x in x_list if x > 0 ])
x_minus = sorted([x for x in x_list if x < 0 ], reverse=True)
zero_x = [x for x in x_list if x == 0 ]

if len(x_plus) == 0 and len(x_minus) == 0:
    print(0)
elif len(x_plus) == 0:
    print(abs(x_minus[k-1-len(zero_x)]))
elif len(x_minus) == 0:
    print(abs(x_plus[k-1-len(zero_x)]))
else:
    max_x = max(x_plus)
    min_x = min(x_minus)

    cost_list = []
    for i in range(len(x_plus)):
        cost = 0
        cnt = i+1 + len(zero_x)
        if len(x_minus)+cnt < k or cnt > k:
            continue
        if cnt == k:
            cost += abs(x_plus[i])
        else:
            cost+=abs(x_minus[k-cnt-1])*2
            cost+=abs(x_plus[i])
        cost_list.append(cost)

    for i in range(len(x_minus)):
        cost = 0
        cnt = i+1 + len(zero_x)
        if len(x_plus)+cnt < k or cnt > k:
            continue
        if cnt == k:
            cost += abs(x_minus[i])
        else:
            cost+=abs(x_plus[k-cnt-1])*2
            cost+=abs(x_minus[i])
        cost_list.append(cost)


    print(min(cost_list))

Measured memory_bytes: 14252
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

# print(sc)

a = ["0" for _ in range(n)]

for i in range(m):
    s, c = sc[i]
    if n == 3 and s == 1 and c == 0:
        print(-1)
        exit()
    if n == 2 and s == 1 and c == 0:
        print(-1)
        exit()
    s -= 1
    c = str(c)
    if a[s] != "0" and a[s] != c:
        print(-1)
        exit()
    a[s] = c

# print(a)
if n == 1 and a[0] == "0":
    pass
elif a[0] == "0":
    a[0] = "1"
ans = int("".join(a))
print(ans)


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

#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000

#define float long double
#define pi acos(-1)

const int modu= (1e9)+7;

void testCase(int ti){
    cout<<"Case "<<ti<<": ";
}

int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}

int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}

void debug(string pr,vector<int> var,bool out=true){
    #ifdef OFFLINE
        ofstream fl;
        fl.open("debug.txt");
        fl<<pr;
        for(int i=0;i<var.size();i++) fl<<" "<<var[i];
        fl<<endl;
        fl.close();
    if(out){
        cout<<pr;
        for(int i=0;i<var.size();i++) cout<<" "<<var[i];
        cout<<endl;
    }
    #endif
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}

void defInit(){
    faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
}

int add(int x,int y){
    int z =(x%modu + y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

int mul(int x,int y){
    int z = (x%modu * y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

//starts here
const int MaxSize=1;


int32_t main(){
    defInit();
    //Now I will start writing codes and start preparation to get errors
    string a,b;
    cin>>a>>b;
    vector<vector<int>> dp(a.size()+1,vector<int>(b.size()+1,0));
    for(int i=0;i<=a.size();i++){
        for(int j=0;j<=b.size();j++){
            if(i==0 || j==0) dp[i][j]=0;
            else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int lcs=dp[a.size()][b.size()];
    int i=a.size(),j=b.size();
    string ans;
    while(i>0 && j>0){
        if(a[i-1]==b[j-1]) ans.push_back(a[i-1]),i--,j--;
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--; 
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 70784
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  std::map<std::string, int> m = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };

  std::string S; std::cin >> S;
  std::cout << m[S] << std::endl;
}


Measured memory_bytes: 384
def sitazan(n,A):
    zan =0 
    for j in range(N-n):
         zan += A[1][j+n]
    return zan

N=input()
A=[]
for i in range(2):
    A.append(map(int, raw_input().split()))
points = []
uepoint = 0
for i in range(N):
    uepoint += A[0][i]
    points.append(uepoint + sitazan(i,A))
print max(points)

Measured memory_bytes: 28524
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    char tmp;
    while(cin>>tmp){
        if(tmp=='1'){
            cout << 9;
        }else{
            cout << 1;
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

ll MOD=1000000007;

signed main(){
	llin(n);
	llin(m);
	if(n>=m){
		sal(0);
		return 0;
	}
	vll x(m);
	FOR(i,0,m-1){
		cin >>x[i];
	}
	SORT(x);
	vll d(m-1);
	FOR(i,0,m-2){
		d[i]=x[i+1]-x[i];
	}
	rSORT(d);
	ll a=x[m-1]-x[0];
	FOR(i,0,n-2){
		a-=d[i];
	}
	sal(a);
}


Measured memory_bytes: 1792
from collections import deque
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
check=[[0,-1],[0,1],[-1,0],[1,0]]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            d = deque()
            d.append([i,j])
            a = [[-1] * w for _ in range(h)]
            a[i][j]=0
            while d:
                v = d.popleft()
                ii=v[0]
                jj=v[1]
                for c in check:
                    x=c[0]
                    y=c[1]
                    if ii+x in range(h) and jj+y in range(w):
                        if a[ii+x][jj+y]==-1:
                            if s[ii+x][jj+y]==".":
                                a[ii+x][jj+y]=a[ii][jj]+1
                                d.append([ii+x,jj+y])
                            else:
                                a[ii+x][jj+y]=0
            ans2=sorted(sum(a,[]),reverse=True)[0]
            if ans<ans2:
                ans=ans2
print(ans)

Measured memory_bytes: 9300
from collections import deque

n = int(input())
a = list(map(int, input().strip().split()))
b = deque()

for i in range(n):
    if i % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
else:
    if i % 2 == 0:
        b.reverse()

print(" ".join(list(map(str, b))))

Measured memory_bytes: 29124
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
#define PP pair<P, ll>
ll s[110000][4], n, m;
vector<ll> g[110000];
queue<PP> q;


int main() {
	cin >> n >> m;
	REP(i, 110000)REP(j, 3)s[i][j] = INF;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
	}
	ll ss, tt;
	cin >> ss >> tt;
	ss--;
	tt--;
	q.push(PP(P(ss, 0), 0));
	while(!q.empty()) {
		ll a = q.front().first.first, b = q.front().first.second, c = q.front().second;
		q.pop();
		//cout << a << b << c << endl;
		REP(i, g[a].size()) {
			if (s[g[a][i]][(b + 1) % 3] > c + 1) {
				q.push(PP(P(g[a][i], (b + 1) % 3), c + 1));
				s[g[a][i]][(b + 1) % 3] = c + 1;
			}
		}
	}
	if (s[tt][0] == INF)cout << -1 << endl;
	else cout << s[tt][0] / 3 << endl;
}


Measured memory_bytes: 9464
using System;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        long k = long.Parse(Console.ReadLine());

        int one = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '1') one++;
            else break;
        }

        if (one == 0) Console.WriteLine(s[0]);
        else if (k <= one) Console.WriteLine('1');
        else Console.WriteLine(s[one]);
    }
}

Measured memory_bytes: 11092
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
#define INF (1<<29)
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;

  int ans=0;
  ans = max(ans,min(B,D)-max(A,C));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n;
double table[100001];

void solve() {
	memset(table, 0, sizeof(double) * 100001);
	table[1] = 1.0;
	repa(i,2,100000) {
		double p = 1.0;
		double win = 0.5;
		for(int k=1; k<i; k++) {
			double lose = p * (1.0 - win);
			table[i] += lose * (k + table[max(0, i-k-1)]);
			p *= win;
			win *= 0.5;
			if(p < 1.0e-13) break;
		}
		table[i] += i * p;
	}
}

int main() {
	solve();

	while(cin>>n, n) {
		printf("%.8f\n", table[n]);
	}
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, l, sum = 0;
	cin >> n >> l;
	for(int i=l; i<n+l; i++) {
		sum += i;
	}
	if(l > 0)
		sum -= l;
	else if(n + l - 1 < 0)
		sum -= (n+l-1);
	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    int a[200010] = {}, index[200010] = {}, l[200010] = {}, r[200010] = {};
    int ans = 0;
    set<int> st;
    rep(i,0,n) {
        cin >> a[i];
        index[ a[i] - 1 ] = i;
    }
    rep(i,0,n) {
        // 小さい数字からインデックスを入れていく
        st.insert(index[i]);
        auto it = st.find(index[i]);
        auto iit = it;
        auto itt = it;

        // 他の要素は、自分よりも小さい要素しかない
        // 隣のイテレータは自分と隣の要素のインデックス
        iit--;
        itt++;

        if(it == st.begin()) l[index[i]] = 0;
        else l[index[i]] = (*iit) + 1;

        if(itt == st.end()) r[index[i]] = n-1;
        else r[index[i]] = (*itt) - 1;
    }
    rep(i,0,n) ans += a[i] * (i - l[i] + 1) * (r[i] - i + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  vector<int> A;
  A.push_back(0);
  int tot = 0;
  for(int i=0; i<N; ++i){
    int v;
    cin >> v;
    tot += abs(v-A.back());
    A.push_back(v);
  }
  tot += abs(0-A.back());
  A.push_back(0);

  // cout << tot << endl;
  for(int i=1; i<N+1; ++i){
    int v = tot;
    v += abs(A[i+1]-A[i-1]) - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]);
    // cout << abs(A[i+1]-A[i-1]) << " " << abs(A[i]-A[i-1]) << endl;
    cout << v << endl;
  }

}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[200000];

int L[200000],R[200000];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];

    stack<int>S;
    rep(i,N){
        while(S.size()&&A[S.top()]>A[i])S.pop();
        if(S.size())L[i]=S.top();
        else L[i]=-1;
        S.push(i);
    }

    S=stack<int>();
    for(int i=N-1;i>=0;i--){
        while(S.size()&&A[S.top()]>A[i])S.pop();
        if(S.size())R[i]=S.top();
        else R[i]=N;
        S.push(i);
    }

    int ans=0;
    rep(i,N){
        int tmp=A[i];
        tmp*=i-L[i];
        tmp*=R[i]-i;
        ans+=tmp;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>

int max(int a,int b){
	return (a > b) ? a : b;
}

int data[1001][1001];

int main(){
	int W,N,i,j,cnt,ans,ansp;
	int *v,*w;

	cnt = 0;
	while(1){
		cnt++;
		scanf("%d",&W);
		if(W == 0){
			break;
		}

		scanf("%d",&N);

		v = (int *)malloc(sizeof(int)*N);
		w = (int *)malloc(sizeof(int)*N);
		
		for(i = 0;i < N;i++){
			scanf("%d,%d",&v[i],&w[i]);
		}

		for(i = 0;i <= W;i++){
			data[0][i];
		}
		for(i = 0;i <= N;i++){
			data[i][0];
		}

		for(i = 1;i <= N;i++){
			for(j = 1;j <= W;j++){
				if(w[i-1] <= j){
					data[i][j] = max(data[i-1][j-w[i-1]]+v[i-1],data[i-1][j]);
				}else{
					data[i][j] = data[i-1][j];
				}
			}
		}

		ans = 0;
		ansp = 0;
		for(i = 0;i <= W;i++){
			if(ans < data[N][i]){
				ans = data[N][i];
				ansp = i;
			}
		}

		printf("Case %d:\n",cnt);
		printf("%d\n%d\n",ans,ansp);
	}

	return 0;
}

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

bool is_prime(int i, vector<int64_t> &prime_map) {
    if (prime_map[i] == 1) {
        return true;
    }

    return false;
}

int main() {
    // エラトステネスのふるいを使って、素数かどうかの表を作る1埋めしたものに素数じゃないものは0にしていく
    // 表を使って、累積和で素数の総数の表を作っていく

    vector<int64_t>prime_map(100001,1);
    prime_map[0]=0,prime_map[1]=0;
    for (int i=2; i < 100001; i++) {
        if (prime_map[i] == 0) {
            continue;
        }

        for (int j=i*2; j < 100001; j+=i) {
            prime_map[j] = 0;
        }
    }

    vector<int64_t>nitakazu_map(100001,0);
    int64_t sum = 0;
    for (int i=3; i < 100001; i+=2) {
        if (prime_map[i] == 1 && prime_map[(i + 1)/2] == 1) {
            sum += 1;
        }

        nitakazu_map[i] = sum;

    }

    int64_t Q;
    cin >> Q;

    for (int i=0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        if (l > 1) {
            l = l - 2;
        }
        int64_t sum = nitakazu_map[r] - nitakazu_map[l];
        cout << sum << endl;
    }

}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=53,INF=1<<20;
int H,W,Q,t=1;
int costuse[MAX][MAX],coston[MAX][MAX],costoff[MAX][MAX];
vector<int> when[MAX][MAX];
bool room[MAX][MAX];

vector<int> dh={0,1,0,-1},dw={1,0,-1,0};

bool DFS(pair<int,int> u,pair<int,int> p,pair<int,int> g){
    if(u==g){
        return 1;
    }
    for(int k=0;k<4;k++){
        int toh=u.first+dh[k],tow=u.second+dw[k];
        
        if(!room[toh][tow]) continue;
        if(toh==p.first&&tow==p.second) continue;
        
        if(DFS({toh,tow},u,g)){
            when[u.first][u.second].push_back(t);
            t++;
            
            return 1;
        }
    }
    
    return 0;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W>>Q;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;cin>>c;
            if(c=='.') room[i+1][j+1]=1;
        }
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>costuse[i+1][j+1];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>coston[i+1][j+1];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>costoff[i+1][j+1];
        }
    }
    
    vector<int> h(Q),w(Q);
    
    for(int i=0;i<Q;i++){
        cin>>h[i]>>w[i];
        h[i]++;
        w[i]++;
    }
    
    when[h[0]][w[0]].push_back(0);
    
    for(int i=1;i<Q;i++){
        DFS({h[i],w[i]},{-1,-1},{h[i-1],w[i-1]});
    }
    
    ll ans=0;
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(when[i][j].size()==0) continue;
            ans+=coston[i][j]+costoff[i][j];
            for(int k=1;k<when[i][j].size();k++){
                ans+=min(ll((when[i][j][k]-when[i][j][k-1]))*costuse[i][j],ll(coston[i][j]+costoff[i][j]));
            }
        }
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 8364
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<int,int>
#define st first
#define nd second
using namespace std;
const int N=2e5+4;
int n,cnt,res;
int id[N];
struct ss
{
    int u,v,c;
};
ss b[N*2],a[N];
bool cmp(ss u,ss v)
{
    return (u.u<v.u);
}
bool cmp1( ss u,ss v)
{
    return (u.v<v.v);
}
bool cmp2(ss u,ss v)
{
    return u.c<v.c;
}
int root(int u)
{
    return (id[u]<0) ? u:id[u]=root(id[u]);
}
void noi(int u,int v)
{
    if ((u=root(u))==(v=root(v))) return;
    if (id[u]>id[v]) swap(u,v);
    id[u]+=id[v];
    id[v]=u;
}
main()
{
    //freopen("D.inp","r",stdin);
    memset(id,-1,sizeof id);
    cin >> n;
    forinc(i,1,n)
    {
        cin >> a[i].u >> a[i].v;
        a[i].c=i;
    }
    sort(a+1,a+1+n,cmp);
    forinc(i,1,n-1)
    {
        ss x=a[i],y=a[i+1];
        b[++cnt]={x.c,y.c,min(abs(x.u-y.u),abs(x.v-y.v))};
    }
    sort(a+1,a+1+n,cmp1);
    forinc(i,1,n-1)
    {
        ss x=a[i],y=a[i+1];
        b[++cnt]={x.c,y.c,min(abs(x.u-y.u),abs(x.v-y.v))};
    }
    sort(b+1,b+1+cnt,cmp2);
    forinc(i,1,cnt)
    {
        int u=b[i].u,v=b[i].v,c=b[i].c;
        if (root(u)!=root(v))
        {
            noi(u,v);
            res+=c;
        }
    }
    cout << res;
}


Measured memory_bytes: 6272