akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
vector<ll> C(26);
vector<vector<ll>> S;

ll change_evaluation(vector<set<ll>>& contest_data, ll t, ll day, ll old) {
  t -= 1;
  day -= 1;
  old -= 1;
  contest_data.at(old).erase(day);
  ll next_t, last_t, next_old, last_old;
  auto itr_t = contest_data.at(t).lower_bound(day);
  next_t = *itr_t;
  itr_t--;
  last_t = *(itr_t);
  auto itr_old = contest_data.at(old).lower_bound(day);
  next_old = *itr_old;
  itr_old--;
  last_old = *(itr_old);

  ll score = S.at(day).at(t) - S.at(day).at(old);
  score += (next_t - day) * (day - last_t) * C.at(t);
  score -= (next_old - day) * (day - last_old) * C.at(old);
  contest_data.at(t).insert(day);
  return score;
}

ll evaluation(vector<ll>& T) {
  ll D = T.size();
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
  }
  return score;
}

int main() {
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> T(D);
  S = vector<vector<ll>>(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  vector<set<ll>> contest_data(26, {-1, D});
  for (ll i = 0; i < D; ++i) {
    cin >> T.at(i);
    contest_data.at(T.at(i) - 1).insert(i);
  }
  //--------------------------------------
  // vector<ll> last(26, 0);
  // for (ll day = 0; day < D; ++day) {
  //   ll max_contest = 0;
  //   ll max_score = -INF;
  //   for (ll contest = 0; contest < 26; ++contest) {
  //     ll temp_score = evaluation(contest, day, last);
  //     if (temp_score > max_score) {
  //       max_score = temp_score;
  //       max_contest = contest + 1;
  //     }
  //   }
  //   last.at(max_contest - 1) = day;
  //   T.at(day) = max_contest;
  // }

  // for (ll i = 0; i < D; ++i) {
  //   cout << T.at(i) << "\n";
  // }

  ll score = evaluation(T);
  // cout << score << "\n";
  ll M;
  cin >> M;
  for (ll i = 0; i < M; ++i) {
    ll d, q;
    cin >> d >> q;
    score += change_evaluation(contest_data, q, d, T.at(d - 1));
    T.at(d - 1) = q;
    cout << score << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


Measured memory_bytes: 3696
import java.util.Scanner;

class Data{
	String name;
	int time;
	Data next;
	
	Data(String s,int t){
		name=s;
		time=t;
		next=null;
	}
}

public class Main {
	static Data first=new Data("",0);
	static Data attention=first;
	
	static Data dequeue(){
		Data tmp=first.next;
		if(attention==tmp){
			attention=first;
		}
		first.next=tmp.next;
		return tmp;
	}
	
	static void enqueue(String s,int t){
		attention.next=new Data(s,t);
		attention=attention.next;
	}

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();//プロセス数。
		int q=scan.nextInt();//クォンタム
		int finish=0;
		String s;
		int t;
		for(int i=0;i<n;i++){
			s=scan.next();
			t=scan.nextInt();
			enqueue(s,t);
		}

		while(first.next!=null){
			Data tmp=dequeue();
			s=tmp.name;
			t=tmp.time;
			finish+=q;
			if(t-q<=0){//プロセスが終了する場合
				finish=finish+(t-q);
				System.out.printf("%s %d\n",s,finish);
			}else{//プロセスがまだ終了しない場合
				enqueue(s,t-q);
			}
		}
		
		
		scan.close();
		
	}

}

Measured memory_bytes: 92644
//AGC 006-A
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	int N, MeatNum = 0;
	vector<int> L(200);
	cin >> N;

	for (int i = 0; i < 2 * N; i++) cin >> L[i];

	sort(L.begin(), L.begin()+2*N);

	for (int i = 0; i < N; i++)	{
		MeatNum += L[2 * i];
	}

	cout << MeatNum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/** AtCoder Beginner Contest 140 - A **/
public class Main {

    private Main() {}

    private void execute() throws Exception {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        System.out.println((int)(Math.pow(Integer.parseInt(n), 3)));
    }

    public static void main(String[] args) {
        try {
            new Main().execute();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

Measured memory_bytes: 23636
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class APassword {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      cout << n*n*n << endl;
    }
};

signed main() {
  APassword solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
import sys
import collections

left = 'qwertasdfgzxcvb'

for line in sys.stdin:
    line = line.strip()
    if line == '#':
        break
    state = 0 if line[0] in left else 1
    count = 0
    for c in line:
        next = 0 if c in left else 1
        if state != next:
            count += 1
        state = next
    print count

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string s;
    cin>>s;
    ll n=s.size();

    //全部WWW...BBBにできる
    //編集距離を求める
    //片方を右に寄せることだけを考えればもう一方は自然と他方による

    ll b=0,w=0;
    rep(i,n){
        if(s[i]=='B')   b++;
        else            w++;
    }
    ll m=0,ans=0;
    for(ll i=0;i<w;i++){
        while(s[m]=='B'){
            m++;
        }
        ans+=abs(m-i);
        m++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
const int MAX=1e3+5;
const int INF=1e9+5;
const double M=4e18;
using namespace std;
const int MOD=1e9+7;
typedef pair<int,int> pii;
const double eps=0.000000001;
int cnt[MAX];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        cnt[x]++;++cnt[y];
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",cnt[i]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <queue>
#define FL(i,j,k) for(int i=j;i<k;++i)
#define eat(a) int a;scanf("%d",&a)

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll > ii;
priority_queue<int,vector<int>,greater<int>> pq;

ll A[100010]={0};
ii B[100010];
int main(void)
{
    eat(a);
    FL(i, 1, a+1){
        eat(b);
        B[i-1]=ii(b,i-1);
    }
    sort(B, B+a, [=](ii a,ii b){return b<a;});
    //int f=B[0].second;pq.push(B[0].second);
    //A[f]+=B[0].first-B[1].first;
    FL(i, 0, a){
        pq.push(B[i].second);
        if(B[i].first>B[i+1].first){
            A[pq.top()]+=(B[i].first-B[i+1].first)*(i+1);
        }
    }
    FL(i, 0, a)printf("%lld\n",A[i]);
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string s;
    cin >> s;
    if(s[2]!=s[3]||s[4]!=s[5]){
        c("No");
    }else
        c("Yes");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static ArrayList<String> s = new ArrayList<String>();
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int a= in.nextInt();
		int b= in.nextInt();
		int c= in.nextInt();
		int d= in.nextInt();
		int [] on= new int[110];
		for (int i = a; i < b; i++) {
			on[i]++;
		}
		for (int i = c; i < d; i++) {
			on[i]++;
		}
		int res=0;
		for (int i = 0; i < on.length; i++) {
			if(on[i]==2) res++;
		}
		System.out.println(res);
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}



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

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long

#define for(i,a,b) for (i=a; i<b; i++)
#define forb(i,a,b) for (i=a; i>b; i--)
#define all(S) S.begin(),S.end()
#define sort(S) sort(all(S))

const int inf = 1e9+7;
const ll INF = 1e18;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m,i,x,y;
    cin >> n >> m;
    vector <vector <int> > V(n);
    for (i,0,m)
    {
        cin >> x >> y;
        x--;
        y--;
        V[x].pb(y);
        V[y].pb(x);
    }
    vector <int> Ans(n);
    bool used[100000];
    for (i,1,n)
        used[i]=false;
    queue <int> Q;
    Q.push(0);
    used[0]=true;
    while (!Q.empty())
    {
        x=Q.front();
        Q.pop();
        for (i,0,V[x].size())
            if (!used[V[x][i]])
        {
            used[V[x][i]]=true;
            Q.push(V[x][i]);
            Ans[V[x][i]]=x;
        }
    }
    for (i,0,n)
        if (!used[i])
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for (i,1,n)
        cout << Ans[i]+1 << endl;
    return 0;
}


Measured memory_bytes: 10252
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int V;
	vvp g;
	vvi cost;
	vi DIJ(int s){
		priority_queue<P> que;
		vi d(V,inf);
		d[s]=0;
		que.push({0,s});
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(int i=0;i<g[v].size();i++){
				int F=g[v][i].first,S=g[v][i].second;
				if(d[F]>d[v]+S){
					d[F]=d[v]+S;
					que.push({-d[F],F});
				}
			}
		}
		return d;
	}
	public:
	Graph(int v){
		V=v;
		g=vvp(v);
		cost=vvi(V);
	}
	void add_edge(int s,int t,int d,int c){
		g[s].push_back({t,d});
		g[t].push_back({s,d});
		cost[s].push_back(c);
		cost[t].push_back(c);
	}
	int solve(){
		vi d=DIJ(0);
		int res=0;
		for(int i=1;i<V;i++){
			int tmp=inf;
			for(int j=0;j<g[i].size();j++){
				P p=g[i][j];
				if(d[p.first]+p.second==d[i]) tmp=min(tmp,cost[i][j]);
			}
			res+=tmp;
		}
		return res;
	}
};

int n,m;

int main(){
	while(1){
		cin>>n>>m;
		if(!n) break;
		Graph g(n);
		for(int i=0;i<m;i++){
			int s,t,d,c;
			cin>>s>>t>>d>>c;
			g.add_edge(s-1,t-1,d,c);
		}
		cout<<g.solve()<<endl;
	}
}

Measured memory_bytes: 4428
#include<iostream>
#include<numeric>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main() {
   string N;
 
    cin>>N;
    if(N[0]==N[2]){
    cout<<"Yes"<<endl;
    }
    else if(N[0]==N[1]==N[2]){
    cout<<"Yes"<<endl;
    }else{
    cout<<"No"<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 256
/* 
   AOJ 1241
   Lagrange's Four-Square Theorem

*/
#include<stdio.h>
#include<math.h>


int ans_n;

int dfs_search(int depth, int n, int x)
{
  /* printf("(%d, %d, %d)\n", depth, n, x); */
  if(x == 0)
    {
      ans_n++;
      return 1;
    }
  if(depth >= 4)
    {
      return 0;
    }
  if(x < 0)
    {
      return 0;
    }
  int new_x = x - n * n;
  dfs_search(depth + 1, n, new_x);

    if(n != 1)
      {
	dfs_search(depth, n - 1, x);  
      }

  return 0;
}

void ans(int x)
{
  int max_sq = (int)sqrt((double)x);
 
  dfs_search(0, max_sq, x);
 
}

int main(void)
{
  int x;
  while(1)
    {
      ans_n = 0;
      scanf("%d", &x);
      if(x == 0)
	{
	  break;
	}
      ans(x);
      printf("%d\n", ans_n);
    }

  return 0;
}

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

int main() {
	string S, T;
	cin >> S >> T;
	map<char, vector<int>> CharMap;
	for (int i = 0; i < S.length(); i++) CharMap[S[i]].push_back(i);
	long long ans = 0, now = 0;
	for (char c : T) {
		if (CharMap.find(c) == CharMap.end()) {
			cout << -1 << endl;
			return 0;
		}
		auto itr = lower_bound(CharMap[c].begin(), CharMap[c].end(), now);
		if (itr == CharMap[c].end()) {
			ans += S.length();
			itr = lower_bound(CharMap[c].begin(), CharMap[c].end(), 0);
		}
		now = (long long)*itr + 1;
	}
	ans += now;
	cout << ans << endl;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int x, a, b;
int main()
{
	while(scanf("%d %d %d", &x, &a, &b) != EOF)
	{
		if(a >= b) printf("delicious\n");
		else
		{
			if(b - a <= x) printf("safe\n");
			else printf("dangerous\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
/* 
   AOJ 1144
   Curling 2.0

*/

#include<stdio.h>
#define MAXW 20
#define MAXH 20
#define MAX_DEPTH 10

int w, h;
int ans = 11;
int map[MAXH][MAXW];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int in(int x, int y)
{
  return 0 <= x && x < w && 0 <= y && y < h;
}


void search(int x, int y, int cnt)
{
  int i, nx, ny;
  if(cnt > MAX_DEPTH)return;

  for(i = 0; i < 4; i++)
    {
      nx = x + dx[i];
      ny = y + dy[i];

      if(!in(nx, ny) || map[ny][nx] == 1)
	continue;

      while(in(nx, ny) && map[ny][nx] == 0 || map[ny][nx] == 2)
	nx += dx[i], ny += dy[i];

      if(!in(nx, ny))
	continue;
	
      if(map[ny][nx] == 3)
	{
	  if(cnt + 1 < ans)
	    ans = cnt + 1;
	  return;
	}

      if(map[ny][nx] == 1)
	{
	  map[ny][nx] = 0;
	  search(nx - dx[i], ny - dy[i], cnt + 1);
	  map[ny][nx] = 1;
	}
    }
}

int main(void)
{
  int i, j, sx, sy;

  while(scanf("%d %d", &w, &h), (w && h))
    {
      for(i = 0; i < h; i++)
	for(j = 0; j < w; j++)
	  {
	    scanf("%d", &map[i][j]);
	    if(map[i][j] == 2)
	      sx = j, sy = i;
	  }
      search(sx, sy, 0);
      printf("%d\n", (ans == 11) ? -1 : ans);
      ans = 11;
    }

  return 0; 
}

Measured memory_bytes: 600
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	ll n;
	cin>>n;
	string res="zabcdefghijklmnopqrstuvwxy";
	string ans;
	while(n)
	{
		ans.pb(res[n%26]);
		n=ceil(n/26.0)-1;
	}
	reverse(all(ans));
cout<<ans;
}
int main()
{
//code
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


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

int main(){
    int i, zerocnt;
    string S;
    cin >> S;
    int cnt = 0;
    for (i = 0; i < S.size(); i++){
       if(S[i] == '1'){
         cnt += 1;
       }
    }
    zerocnt = S.size() - cnt;
    cout << 2 * min(cnt, zerocnt) << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1416
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    double r,sum;
    cin>>r;
    sum=2*pi*r;
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3800
import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
# from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
# dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = wi()

value = [] # ノードの値を持つ配列
N = 0 # 葉の数

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

def update(i, x):
    # i番目の葉の値をxに変える
    i += N - 1  # i番目の葉のノード番号
    value[i] = x
    while i > 0:
        i = (i - 1) / 2  # ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1], value[i * 2 + 2])  # 左右の子の min を計算しなおす


#define INF 2147483647 // 2^31-1
INF = float("INF")
def query(a, b, k, l, r) :
    # [a, b) の区間に対するクエリについて
    # ノード k （区間 [l, r) 担当）が答える
    if r <= a or b <= l:
        # 区間が被らない場合は INF を返す
        return 0
    if a <= l and r <= b:
        # ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
        return value[k]
    else:
        # 一部だけ範囲が被る場合は左右の子に委託する
        c1 = query(a, b, 2 * k + 1, l, (l + r) // 2)  # 左の子に値を聞く
        c2 = query(a, b, 2 * k + 2, (l + r) // 2, r)  # 右の子に値を聞く
        # 左右の子の値の min を取る
        return gcd(c1, c2)



value = [] # ノードの値を持つ配列
N = 0  # 葉の数

#if __name__ == '__main__':
N = 1
while N < n:
    N *= 2  # 葉の数を計算（n以上の最小の2冪数）

value = [0] * (2 * N - 1)
for i in reversed(range(2 * N - 1)):
    if N - 1 <= i < 2 * N - 1:
        if N - 1 <= i < N - 1 + n:
            value[i] = a[i - (N - 1)]
        else:
            value[i] = 0
    else:
        value[i] = gcd(value[2 * i + 1], value[2 * i + 2])

for i in range(n):#query(,,0,0,N)
    if i == 0:
        ansli.append(query(1, n, 0, 0, N))
    elif i == n - 1:
        ansli.append(query(0, n - 1, 0, 0, N))
    else:
        ansli.append(gcd(query(0, i, 0, 0, N), query(i + 1, n, 0, 0, N)))
print(max(ansli))

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	int n,m;
	int t;

	cin >> n >> m;
	PQ<int> q;

	REP(i,n) {
		cin >> t;
		q.push(t);
	}

	int a;
	REP(i,m) {
		a = q.top(); q.pop();
		q.push(a/2);
	}

	ll sum = 0;
	while(!q.empty()) {
		sum += q.top();
		q.pop();
	}
	cout << sum << endl;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;


signed main(){
	map<ll,ll> mp;
	rep(i,0,6){
		ll a; cin>>a;
		mp[a]++;
	}
	bool ok=true;
	rep(i,1,5){
		if(mp[i]>=3)ok=0;
	}
	cout<<(ok ? "YES":"NO")<<endl;

	return 0;
}


Measured memory_bytes: 3528
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <ctype.h>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
int n,m,x,y;
vector<int> a,b;
int main(){
    cin >> n >> m >> x >> y;
    int tmp;
    for(int i=1; i<=n; i++){
        cin >> tmp;
        a.push_back(tmp);
    }

    for (int i = 1; i <= m; i++)
    {
        cin >> tmp;
        b.push_back(tmp);
    }

    sort(a.begin(),a.end());
    sort(b.begin(), b.end());

    for(int z = x+1; z <=y ; z++){
        if(a[n-1] < z && z <= b[0]){
            cout << "No War";
            return 0;
        }
    }

    cout << "War";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int N,X;

int main(int argc, char const *argv[])
{
    cin>>N>>X;
    vector<int> m(N);
    int sum_gram=0;
for(int i=0;i<m.size();i++){
    cin>>m[i];
    sum_gram+=m[i];
}

int min = *std::min_element(m.begin(), m.end());
cout<<N+(X-sum_gram)/min<<endl;

return 0;
}


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

int main(){
  int N , K;
  cin >> N >> K;
  
  int S = 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if( K-x >= x){
      S += 2*x;
    }
    else{
      S += (K-x)*2;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
i=0
s=0
while i<n:
  if a[i]%2==1:
    b[i]=0
  elif a[i]%2==0 and a[i]%3==0:
    b[i]=0
  elif a[i]%2==0 and a[i]%5==0:
    b[i]=0
  else:
    b[i]=1
  s=s+b[i]
  i=i+1
if s==0:
  print("APPROVED")
else:
  print("DENIED")

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

int main()
{
	int n, sum[2] = { 0,0 }, buffer;
	cin >> n;
	vector<int> w(n);
	vector<int>::iterator pf,pe;
	for (int i = 0; i < n; i++) cin >> w[i];
	while (w.size()!=0)
	{
		if (sum[0] <= sum[1])
		{
			pf = w.begin();
			sum[0] += *pf;
			w.erase(pf);
		}
		else
		{
			pe = w.end()-1;
			sum[1] += *pe;
			w.erase(pe);
		}
	}
	cout << abs(sum[0] - sum[1]);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define MAX 80

int main() {
    int n;
    long long s, m = 1000;
    vector<int> a(MAX+10);

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

    int mini = 300;
    for (int i = 0; i < n; i++) {
        mini = min(a[i], mini);
        if (a[i] > mini) {
            s = m / mini;
            m += (a[i] - mini) * s;
            mini = a[i];
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
from itertools import permutations, combinations
from fractions import gcd
from collections import Counter
from math import sqrt
import sys
input = sys.stdin.readline
def lcm(x, y):
    return (x*y//gcd(x, y))
def small_letters():
    return [chr(i) for i in range(97, 97+26)]
def capital_letters():
    return [chr(i) for i in range(65, 65+26)]
def continual_letters(list_x):
    """example"""
    """[2,2,2,2,4,4,5,5,5,8,8,8,8,8] => [4,2,3,5]"""
    i,j = 0,0
    result = []
    k = len(list_x) - 1
    while(True):
        A = list_x[i]
        while(True):
            print(j)
            if list_x[j] != A:
                break
            if j >= k:
                break
            j += 1
        result.append(j-i)
        if i >= k:
            break
        i = j
    result[-1] += 1
    return result


def main():
    """ここに書いてね"""
    N,K = map(int,input().split())
    HPs = list(map(int,input().split()))
    HPs.sort()
    if K >= N:
        print(0)
    else:
        print(sum(HPs[:N-K]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 27756
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    string s;
    ll sub = 0;

    cin >> n >> s;

    ll r = 0, g = 0, b = 0;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            r++;
        }
        else if (s[i] == 'G')
        {
            g++;
        }
        else
        {
            b++;
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (s[i] == s[j])
            {
                continue;
            }

            int k = 2 * j - i;

            if (k >= n || s[i] == s[k] || s[j] == s[k])
            {
                continue;
            }

            sub++;
        }
    }

    cout << r * g * b - sub << endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:

    int choose(int n)
    {
        if (n == 0)
        {
            return 0;
        }
        else if (n == 1)
        {
            return 0;
        }
        else if (n == 2)
        {
            return 1;
        }
        else
        {
            return (n * (n - 1)) / 2;
        }
    }

    void solve(std::istream& in, std::ostream& out) {
        int n, m;
        in >> n;
        in >> m;

        out << choose(n) + choose(m);
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn = 1e5+5;
const int ff = 0x3f3f3f3f;
 
int n,m,r;
int e[50];
int dis[202][202];
 
int main()
{
	cin>>n>>m>>r;
	for(int i = 1;i<= r;i++)
		cin>>e[i];
	mem(dis,ff);
	for(int i = 1;i<= m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		dis[a][b] = c;
		dis[b][a] = c;
	}
	for(int k = 1;k<= n;k++)
		for(int i = 1;i<= n;i++)
			for(int j = 1;j<= n;j++)
				dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
	
	vector<int> p;
	for(int i = 1;i<= r;i++)
		p.push_back(i);
	
	int ans = ff;
	do
	{
		int tmp = 0;
		for(int i = 1;i< r;i++)
			tmp+= dis[e[p[i]]][e[p[i-1]]];
		if(tmp< ans)
			ans = tmp;
	} while(next_permutation(p.begin(),p.end()));
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define max_time 550
int main()
{   
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> diff_arr(n+2 , 0);
    int temp;
    for(int i= 0 ; i < q ; i++)
    {   
        cin>>temp;
        diff_arr[temp] += 1;
        diff_arr[0] -=1;
        diff_arr[temp+1] -= 1;
    }
    for(int i = 1 ; i < diff_arr.size() ; i++)
    {
        diff_arr[i] += diff_arr[i-1];
    }
    for(int i = 1 ; i <= n ;i++)
    {
        (k + diff_arr[i])<= 0?cout<<"No"<<endl:cout<<"Yes"<<endl;
    }
   
    
    return  0;
}


Measured memory_bytes: 1024
import heapq

T = int(input())
for t in range(T):
    N,A,B,C,D = map(int,input().split())
    q = [(0,N)]
    heapq.heapify(q)
    seen = set()
    while q:
        cost, n = heapq.heappop(q)
        if n in seen:
            continue
        seen.add(n)
        if n == 0:
            print(cost)
            break

        heapq.heappush(q, (cost + n * D, 0))
        if n % 2 ==0:
            heapq.heappush(q, (cost + A, n // 2))
        else: # odd number
            heapq.heappush(q, (cost + D + A, (n + 1) // 2))
            heapq.heappush(q, (cost + D + A, (n - 1) // 2))
        if n % 3 ==0:
            heapq.heappush(q, (cost + B, n // 3))
        else:
            rest = n % 3
            heapq.heappush(q, (cost + rest * D + B, (n - rest) // 3))
            heapq.heappush(q, (cost + (3-rest) * D + B, (n - rest + 3) // 3))

        if n % 5 ==0:
            heapq.heappush(q, (cost + C, n // 5))
        else:
            rest = n % 5
            heapq.heappush(q, (cost + rest * D + C, (n - rest) // 5))
            heapq.heappush(q, (cost + (5-rest) * D + C, (n - rest + 5) // 5))




Measured memory_bytes: 12868
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long ll;
const ll mod=1e9+7;
const ll MAXN=1e5+10;

int main()//所有的循环已改正 
{
	char a[MAXN];
	cin>>a;
	int len=strlen(a);
	for(int i=0;i<len;i+=2){
		printf("%c",a[i]);
	} 
	return 0;
}	 


Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: u32, m: u32
    }
    let a = n - m;
    let ans = (a * 100 + 1900 * m) as u64 * (2u64.pow(m));
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int Z = min(X, Y);
  int ans = 0;
  if (Z * (A + B) > Z * 2 * C) {
    ans += (Z * 2 * C);
  }
  else {
    ans += (Z * (A + B));
  }
  if (X < Y) {
    if ((Y - X) * B < (Y - X) * 2 * C) {
      ans += ((Y - X) * B);
    }
    else {
      ans += ((Y - X) * 2 * C);
    }
  }
  else {
    if ((X - Z) * A < (X - Z) * 2 * C) {
      ans += ((X - Z) * A);
    }
    else {
      ans += ((X - Z) * 2 * C);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int a[100][100];

int main(){
  const int n = getInt();
  int ans = -1000000000;
  REP(i,n) REP(j,n){
    a[i][j] = getInt();
    if(i > 0) a[i][j] += a[i - 1][j];
    if(j > 0) a[i][j] += a[i][j - 1];
    if(i > 0 && j > 0) a[i][j] -= a[i - 1][j - 1];

    REP(ii,i + 1) REP(jj,j + 1){
      int t = a[i][j];
      if(ii > 0) t -= a[ii - 1][j];
      if(jj > 0) t -= a[i][jj - 1];
      if(ii > 0 && jj > 0) t += a[ii - 1][jj - 1];
      ans = max(ans, t);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1064
import java.util.*;

public class Main {
	int[][] map = new int[12][12];
	
	public void func(){
		int count = 0;
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(map[i][j]==1){
					loop(i, j);
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	public void loop(int y, int x){
		map[y][x]--;
		if(x!=0 && map[y][x-1]==1)loop(y, x-1);
		if(x!=11 && map[y][x+1]==1)loop(y, x+1);
		if(y!=0 && map[y-1][x]==1)loop(y-1, x);
		if(y!=11 && map[y+1][x]==1)loop(y+1, x);
	}
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			Main A = new Main();
			String t = "";
			
			for(int i=0;i<12;i++){
				t = sc.next();
				for(int j=0;j<12;j++){
					if(t.codePointAt(j)==49)A.map[i][j]=1;
				}
			}
			A.func();
			
		}
	
	}	
}

Measured memory_bytes: 17164
#include<queue>
#include<cctype>
#include<cstdio>
 
#define mp          make_pair
#define rep(i,n)    for(int i=0;i<n;i++)
 
using namespace std;
 
typedef pair<int,int> pii;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
int h,w;
char grid[1000][1001];
 
int shortestDistance(int sx,int sy,int gx,int gy){
    static bool visited[1000][1000];
    rep(i,h)rep(j,w)    visited[i][j]=false;
    visited[sy][sx]=true;
 
    queue< pair<int,pii> > qu;  qu.push(mp(0,mp(sy,sx)));
    while(1){
        pair<int,pii> a=qu.front();   qu.pop();
        int d=a.first,x=a.second.second,y=a.second.first;
        if(x==gx && y==gy)  return d;
 
        rep(i,4){
            int xx=x+dx[i],yy=y+dy[i];
            if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='X' && !visited[yy][xx]){
                visited[yy][xx]=true;
                qu.push(mp(d+1,mp(yy,xx)));
            }
        }
    }
}
 
int main(){
    int n;  scanf("%d%d%d",&h,&w,&n);
    int cx[10],cy[10];
    rep(i,h){
        scanf("%s",grid[i]);
        rep(j,w){
            if(grid[i][j]=='S')     cx[0]=j,cy[0]=i;
            if(isdigit(grid[i][j])) cx[grid[i][j]-'0']=j,cy[grid[i][j]-'0']=i;
        }
    }
 
    int cost=0;
    rep(i,n)    cost+=shortestDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
    printf("%d\n",cost);
 
    return 0;
}

Measured memory_bytes: 3004
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

const ll INF = -1145141919810;//負の大きい数　更新式でより大きいものを求めるため、未計算のものをすべて大きな(正？負？)数にすればよい

int N, W;
ll dp[101][100001];//dp[a][b] := a番目(1-idx)まで取捨選択をして、重みがbの時での最大の価値 1-idxで実装してることに注意！
int weight[101], value[101];//1-idxで実装してることに注意！

ll memo(int a, int w) {

	if (dp[a][w] != INF)return dp[a][w];

	if (a == 1) {
		if (w == weight[a]) {
			return dp[a][w] = value[a];
		}
		else if (w == 0) {
			return dp[a][w] = 0;
		}
		return INF;
	}
	else {
		ll best = 0;
		best = memo(a - 1, w);
		if (w - weight[a] >= 0) {
			best = max(best, memo(a - 1, w - weight[a]) + value[a]);
		}
		return dp[a][w] = best;
	}
}

int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> weight[i] >> value[i];
	}

	//最初はすべて未計算なので、大きな(正？負？)数で初期化する
	for (int i = 1; i <= N; i++)
		for (int j = 0; j <= W; j++)dp[i][j] = INF;

	for (int i = 0; i <= W; i++) {
		memo(N, i);
	}

	//答えは、最後の品物まで取捨選択し終えた後に、それぞれの0~Wの質量の中での最大の価値である。
	ll ans = 0;
	for (int i = 0; i <= W; i++) {
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;

	return 0;
}

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

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

    long long A[N];
    for (long long i = 1; i <= N; i++)
    {
        cin >> A[i - 1];
        A[i - 1] -= i;
    }
    sort(A, A + N);

    long long b;
    if (N % 2 == 0)
    {
        b = (A[N / 2 - 1] + A[N / 2]) / 2;
    }
    else
    {
        b = A[N / 2];
    }
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += abs(A[i] - b);
    }
    cout << ans << endl;
}


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



int main() {
	int n, l;
	cin >> n >> l;
	int num = 10000;
	int index;
	int sum = 0;
	for(int i=0; i<n; i++){
		int ret = l + i;
		if(abs(ret) < num){
			index = i;
			num = abs(ret);
		}
		sum += l+i;
	}
	cout << sum - (l+index) << endl;
}


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

const int N = 100 * 1000 + 5;
int main() {
	int n, ans = 0;
	cin >> n;
	int x = 0;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		if (a == i) {
			x++;
		}
		else {
			ans += x - x / 2;
			x = 0;
		}
	}
	ans += x - x / 2;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef pair<ll,ll>             pairll;
typedef map<ll,ll>              mapll ;
typedef map<char,ll>            mapch;
typedef map<string,ll>          mapstr;

#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld",&a)
#define sii(a,b) scanf("%d %d", &a,&b)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pt(a) printf("%d",a)
#define pll(a) printf("%lld",a)
#define ps printf(" ")
#define nln printf("\n")
#define pi acos(-1)
#define spc " "
#define nl "\n"
#define rep(i,W) for(int i = 0; i < W; i++)
#define rep1(i,W) for(int i = 1; i <= W; i++)

ll w;
string s;
vector <char> arr;

void input(){
    getline(cin,s);
    cin >> w;
}

void solve(){
    for(ll i = 0; i < s.size(); i+= w)
    {
        if(i%w==0){
            char c = s[i];
            arr.pb(c);
        }
    }
    for(int i = 0; i < arr.size(); i++){
        printf("%c",arr[i]);
    }
    printf("\n");
}

int main(){
    input();
    solve();
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
    std::string str;
    std::string res = "";
    std::cin >> str;

    std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < (int)str.size(); ++i) {
        char s = str[i];
        for (int j = 0; j < (int)alphabet.size(); j++) {
            if (s == alphabet[j]) {
                int size = (int)alphabet.size();
                res += alphabet[(size + j - 3) % size];
                break;
            }
        }
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a, b; cin>>a>>b;
    printf("%.0f\n", ceil((a + b) / 2.0));
    return 0;
}

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

struct students{
    int num;
    int index;
    bool operator<(const students &another) const{
        return num < another.num;//年齢を比較
    };
};

int main(){
    int N;
    cin >> N;
    vector<students> A(N);
    rep(i,N){
        cin >> A[i].num;
        A[i].index = i+1;
    }

    sort(A.begin(), A.end());

    rep(i,N)
        cout << A[i].index << ' ';
    cout << endl;
    
    return 0;
}

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


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

    string S;
    cin >> S;
    int ans=S.size();
    for(int i=0;i<S.size()-1;i++){
        if(S.at(i)==S.at(i+1)) {
            ans--;
            i+=2;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 720
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ll x;
  int k;
  cin >> x >> k;
  VL r(k + 1, 0);
  REP(i, 0, k) {
    cin >> r[i + 1];
  }
  VL el(k + 1), em(k + 1), en(k + 1);
  VL curdir(k + 1);
  el[0] = 0;
  em[0] = x;
  en[0] = 0; // max(0, min(x, a + 0))
  ll dir = -1;
  curdir[0] = -1;
  REP(i, 0, k) {
    ll pass = r[i + 1] - r[i];
    en[i + 1] = en[i] + dir * pass;
    el[i + 1] = max(0LL, min(x, el[i] + dir * pass));
    em[i + 1] = max(0LL, min(x, em[i] + dir * pass));
    dir *= -1;
    curdir[i + 1] = dir;
  }
  int q;
  cin >> q;
  REP(puella, 0, q) {
    ll t, a;
    cin >> t >> a;
    int idx = upper_bound(r.begin(), r.end(), t) - r.begin() - 1;
    ll diff = t - r[idx];
    ll base = max(el[idx], min(em[idx], a + en[idx]));
    ll ans = max(0LL, min(x, base + curdir[idx] * diff));
    cout << ans << endl;
  }
}


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

int main(){
    int n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    string a[100010];
    cin >> n;

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

    for (int i = 0; i < n; i++){
        if (a[i] == "AC"){
            ac++;
        } else if (a[i] == "WA")
        {
            wa++;
        } else if (a[i] == "TLE")
        {
            tle++;
        } else {
            re++;
        }
    }

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

Measured memory_bytes: 6760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n;

int main(void)
{
	while(cin >> n && n)
	{
		int dp[33] = {0};
		dp[0] = dp[1] = dp[2] = 1;
		for (int d = 0; d < n; d++)
		{
			for (int i = 0; i < 3; i++)
			{
				dp[d + i + 1] += dp[d];
			}
		}
		cout << (dp[n - 1] - 1) / 10 / 365 + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
int main(){
    std::string s,t,t2;
    std::cin >> s >> t;
    std::sort(s.begin(),s.end());
    std::sort(t.begin(),t.end(),std::greater<char>());
    if(s<t){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const static long long INF = 1LL << 55LL;
#define int long long
struct edge {
  int to, cost;
  edge(int to, int cost):to(to), cost(cost){};
};
struct state {
  int now;
  long long cost;
  int bitsIn, bitsOut;
  bool operator<(const state& s) const {
    return(cost > s.cost);
  }
  state(int n, long long c, int i, int o):now(n), cost(c), bitsIn(i), bitsOut(o){};
};

int n, m, k, p;
vector< edge > Graph[1000];
long long v[1000][1 << 6][1 << 6];
int Idx[1000];

long long Dijkstra()
{
  priority_queue< state > Que;
  fill_n((long long *)v, 1000 * (1 << 6) * (1 << 6), INF);
  Que.push(state(p, 0, 0, 0));
  v[p][0][0] = 0;

  while(!Que.empty()) {
    const state p = Que.top(); Que.pop();
    if(p.cost > v[p.now][p.bitsIn][p.bitsOut]) continue;
    if(p.bitsOut == (1 << k) - 1) return(p.cost);
    for(int i = 0; i < Graph[p.now].size(); i++) {
      const edge& e = Graph[p.now][i];
      int nextIn = p.bitsIn, nextOut = p.bitsOut;
      if(Idx[e.to] > 0) {
        nextIn |= (1 << (Idx[e.to] - 1));
      } else if(Idx[e.to] < 0) {
        nextOut |= ((nextIn >> (-Idx[e.to] - 1)) & 1) << (-Idx[e.to] - 1);
      }
      if(p.cost + e.cost >= v[e.to][nextIn][nextOut]) continue;
      v[e.to][nextIn][nextOut] = p.cost + e.cost;
      Que.push(state(e.to, p.cost + e.cost, nextIn, nextOut));
    }
  }
  return(-1);
}


signed main()
{
  cin >> n >> m >> k >> p;
  --p;
  for(int i = 0; i < m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    --x, --y;
    Graph[x].push_back(edge(y, w));
    Graph[y].push_back(edge(x, w));
  }
  for(int i = 1; i <= k; i++) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    Idx[s] = i;
    Idx[t] = -i;
  }
  int cost = Dijkstra();
  if(cost == -1) puts("Cannot deliver");
  else cout << cost << endl;
  return(0);
}

Measured memory_bytes: 38304