akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){

  int n;
  cin >> n;

  string t, h;
  int pt = 0, ph = 0;
  for (int i = 0; i < n; i++) {
    cin >> t >> h;
    if ( t == h ) {
      pt++;
      ph++;
    } else if ( t > h) {
      pt += 3;
    } else {
      ph += 3;
    }
  }

  cout << pt << ' ' << ph << endl;
  
  return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;


// 深さ優先探索
vector<bool> seen;
vector<long long int> dist;
void dfs(const Graph &G, int v, long long Dist) {
    //cout << "dfs:" << v << '\n';
    seen[v] = true; // v を訪問済にする
    dist[v] = Dist;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v.first]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v.first, Dist + next_v.second); // 再帰的に探索
    }
}

int main() {
    long long int n, a, b, c;
    cin >> n;
    Graph G(n+1);
    for(int i = 0; i < n-1; ++i) {
        cin >> a >> b >> c;
        edge e = {b, c};
        G[a].push_back(e);
        e = {a, c};
        G[b].push_back(e);
    }
    long long int q, k, x, y;
    cin >> q >> k;
    seen.assign(n+1, false);
    dist.assign(n+1, 0);
    dfs(G, k, 0);
    for(int i = 0; i < q; ++i) {
        cin >> x >> y;
        cout << (dist[x] + dist[y]) << '\n';
    }

    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b=0;cin>>a;
  rep(i,a+1){
    if(i%3!=0&&i%5!=0)b+=i;
  }
  cout<<b;
}


Measured memory_bytes: 3636
n = int(input())
S = list(input())
dp = [0 for i in range(n)]
dp[0] = S[1:].count("E")

for i in range(n-1):
    if S[i] == S[i+1] == "E":
        dp[i+1] = dp[i]-1
    elif S[i] == S[i+1] == "W":
        dp[i+1] = dp[i]+ 1
    else:
        dp[i+1] = dp[i]

print(min(dp))


Measured memory_bytes: 17600
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vs s(N); REP(i, N) cin >> s[i];
    int M; cin >> M;
    vs t(M); REP(i, M) cin >> t[i];

    map<string, int> blue, red;

    REP(i, N) blue[s[i]]++;
    
    REP(i, M) red[t[i]]++;

    int ans = 0;
    for (string i : s) {
        ans = max(ans, blue[i] - red[i]);
    }
  
    cout << ans << endl;

    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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;
};

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

  int d, n, m;
  while (cin >> d, d) {
    cin >> n >> m;

    vector<int> dis(n, 0);
    vector<int> (n+1, 0);
    rep(i, 1, n) {
      cin >> dis[i];
    }
    dis[n] = d;

    sort(All(dis));

    int k;
    int ans = 0;
    rep(i, 0, m) {
      cin >> k;
      int idx = lbidx(dis, k);
      int pre_idx;
      if (idx == 0) {
        pre_idx = n;
      } else {
        pre_idx = idx-1;
      }

      ans += min(abs(dis[idx] - k), abs(dis[pre_idx] - k));
    }

    cout << ans << endl;
  }


  return 0;
};



Measured memory_bytes: 3600
n = int(input())
monster = list(map(int, input().split()))
brave = list(map(int, input().split()))

cnt = 0

for i in range(n):
    kill1 = min(monster[i], brave[i])
    monster[i] -= kill1
    brave[i] -= kill1

    kill2 = min(monster[i+1], brave[i])
    monster[i+1] -= kill2
    brave[i] -= kill2

    cnt += (kill1+kill2)

print(cnt)

Measured memory_bytes: 18624
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    print(0,flush = True)
    s = S()
    if s == "Vacant":
        return
    x = s
    ok = 0
    ng = n
    while 1:
        mid = (ok + ng) // 2
        print(mid, flush=True)
        s = S()
        if s == "Vacant":
            return
        if mid & 1 == ok & 1:
            if s == x:
                ok = mid
            else:
                ng = mid
        else:
            if s == x:
                ng = mid
            else:
                ok = mid
                x = s

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 5536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int n;
    cin>>n;
    if(n<=111) cout<<"111"<<endl;
    else if((n>111) && (n<=222)) cout<<"222"<<endl;
    else if((n>222) && (n<=333)) cout<<"333"<<endl;
    else if((n>333) && (n<=444)) cout<<"444"<<endl;
    else if((n>444) && (n<=555)) cout<<"555"<<endl;
    else if((n>555) && (n<=666)) cout<<"666"<<endl;
    else if((n>666) && (n<=777)) cout<<"777"<<endl;
    else if((n>777) && (n<=888)) cout<<"888"<<endl;
    else if(n>888 && n<=999) cout<<"999"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int H, N, A, total;
    total = 0;
    cin >> H >> N;
    for(int i=0;i<N;++i){
        cin >> A;
        total += A;
    }
    if(total >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  cin >> a;
  if(a.at(2) == a.at(3) && a.at(4) == a.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
ps = na()

cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + ps[i]

mx = 0
for i in range(n-k+1):
    mx = max(mx, cum[i+k] - cum[i])
print("{:.14f}".format((mx + k) / 2))

Measured memory_bytes: 67824
# 配列数Nの入力
N = int(input())
# 配列の入力
in_list = list(map(int,input().split()))
odd_flg = False
cnt = 0

while(not(odd_flg)):
  for n in range(N):
    if (in_list[n]%2) != 0:
      odd_flg = True
      break
    else:
      in_list[n] = int(in_list[n]/2)
  cnt += 1

print(cnt-1)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() { return Long.parseLong(next());  }
    }

    public static void main(String[] args) {
        FastReader sn = new FastReader();
        char []c = sn.next().toCharArray();
        if(c[0] >= 'A' && c[0] <= 'Z'){
            System.out.println("A");
        }else
            System.out.println("a");
    }
}

Measured memory_bytes: 25276
def f(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
def has_duplicates(seq):
    return len(seq) != len(set(seq))
s=int(input())
a=list()
a.append(s)
i=0
while True:
    a.append(f(a[i]))
    double=has_duplicates(a)
    if double==True:
        print(i+2)
        break
    i+=1

Measured memory_bytes: 9236
#include <iostream>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    long long a[N],b[N];
    long long c[M],d[M];
    
    for(int i = 0; i < N ;i++){
        cin >> a[i]>>b[i];
        //cout << a[i]<<b[i]<<endl;
        
    }
    
    for(int i = 0; i < M ;i++){
        cin >> c[i]>>d[i];
        //cout <<c[i]<<d[i]<<endl;
    }
    int ans;

    long long minp;
    for(int i = 0; i < N;i++){
        
        
        for(int j = 0; j < M ; j++){
        
            if(j == 0){
                minp = abs(a[i]-c[j])+abs(b[i]-d[j]);
                ans = 1;
            }
            
            
            // cout << a[i]<<""<<c[j]<<endl;
            // cout <<b[i]<<""<<d[j]<<endl;
            // cout << abs(a[i]-c[j])<<""<<b[i]-c[j] <<endl;
            //cout <<"WWW"<< minp << " "<<abs(a[i]-c[j])+abs(b[i]-d[j])<<endl;
            if(minp>abs(a[i]-c[j])+abs(b[i]-d[j])){
                minp = abs(a[i]-c[j])+abs(b[i]-d[j]);
                ans = j + 1;
            }
        }
        
        cout << ans << endl;
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 256
import bisect

n,m = map(int,input().split())

li = [[] for _ in range(n+1)]
num = []

for _ in range(m):
    p,y = map(int,input().split())
    li[p].append(y)
    num.append((p,y))

for i in range(n+1):
    li[i].sort()

for i,j in num:
    print(str(i).zfill(6)+str(bisect.bisect_left(li[i],j)+1).zfill(6))

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
long long dp[51][51][3000] ={0};
int x[50];

int main(void){
    int n, a;
    long long ans = 0;
    scanf("%d %d", &n, &a);
    for (int i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= i; j++){
            for (int k = 0; k < 2501; k++){
                dp[i][j-1][k] += dp[i-1][j-1][k];
                if (k-x[i-1] >= 0){
                    dp[i][j][k] += dp[i-1][j-1][k-x[i-1]];
                }
            }
        }
    }

    for (int j = 1; j <= n; j++){
                ans += dp[n][j][j*a];
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 59136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int mod = 2019;
int main()
{
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  int pre = 0;
  int_fast16_t k = 1;
  map<ll, ll> mp;
  rep(i, s.size())
  {
    pre += (k * (int)(s[i] - '0'));
    pre %= mod;
    mp[pre]++;
    k *= 10;
    k %= mod;
  }
  ll ans = 0;
  rep(i, 2019)
  {
    if(i==0)
      ans += mp[i];
    ans += mp[i] * (mp[i] - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3764
#include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i,j,c,d,max,to,taihi,rui,k,pai;
	long long mx,sum;
	vector<int> jo;
	while(1) {
		cin >> n;
		if(n==0) break;
		sum=0;
		for(i=0;i<n;i++) {
			cin >> pai;
			sum+=pai;
		}
		jo.resize(n-1);
		for(i=0;i<n-1;i++) cin >> jo[i];
		sort(jo.begin(),jo.end(),greater<int>());
		mx=sum*n;
		taihi=n;
		for(i=0;i<n-1;i++) {
			if(mx<(sum+jo[i])*(taihi-1)) {
				sum+=jo[i];
				taihi-=1;
				mx=sum*(taihi);
			}
		}
		cout << mx << endl;
	}
	exit(0);
}
		

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int n;
string s;
bool f[MN];

int main() {
	cin >> s;
	n = s.size();
	rep(i, n) f[i + 1] = (s[i] == '1');

	if (f[n] || !f[1]) {
		puts("-1");
		return 0;
	}

	vi vec;

	for (int i = 1; i < n; ++i) {
		if (f[i] != f[n-i]) {
			puts("-1");
			return 0;
		}
		if (f[i]) {
			vec.pb(i);
		}
	}

	reverse(ALL(vec));

	int cur = n;

	vector<pii> es;
	int now = 0;

	rep(i, vec.size()) {
		int num = cur - vec[i] - 1;
		int nn = now + 1;
		rep(tt, num) {
			es.eb(now, nn++);
		}
		es.eb(now, nn);
		now = nn;
		cur = vec[i];
	}

	rep(i, n-1) {
		printf("%d %d\n", es[i].fi + 1, es[i].se + 1);
	}

	return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


ll N, K;
ll a[MAX*2], f[MAX*2];

ll C(ll X) {
  ll s=0;
  for(ll i=0; i<N; i++) {
    s+=max(0LL, a[i]-X/f[i]);
  }
  
  return s<=K;
}


int main(void) {
  cin >> N >> K;
  ll i;
  
  for(i=0; i<N; i++) cin >> a[i];
  for(i=0; i<N; i++) cin >> f[i];
  sort(a, a+N);
  sort(f, f+N);
  reverse(f, f+N);
  
  
  
  ll l=-1, r=INF;
  while(l+1<r) {
    ll mid=(l+r)/2;
    
    if(C(mid)) r=mid;
    else l=mid;
  }
  
  pt(r);
}


Measured memory_bytes: 3456
N = int(input())
S = list(input())

def my_index(LIST, VALUE,START):
    if VALUE in LIST[START:]:
        return LIST.index(VALUE,START)
    else:
        return float("inf")

answer = 0
# 暗証番号がiとなるか判定
for i in range(1000):
    PIN = str(i).rjust(3,"0")
    if PIN[0] in S:
        one_digit = S.index(PIN[0])
    else:
        continue
    if PIN[1] in S:
        two_digit = my_index(S,PIN[1],one_digit+1)
        if two_digit == float("inf"):
            continue
    else:
        continue
    if PIN[2] in S:
        three_digit = my_index(S,PIN[2],two_digit+1)
        if three_digit == float("inf"):
            continue
    else:
        continue
    answer += 1

print(answer)

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <utility>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

void solve(){

	string strs[] = { "SAFE", "SUSPICIOUS" };

	int h, w;
	cin >> h >> w;

	vector< string > screen( h );
	vector< bool > flg( 26, false );

	for( int i = 0; i < h; i++ )
		cin >> screen[ i ];
	
	bool fig = true;

	while( fig ) {

		fig = false;

		for( int x = 0; x < w; x++ ) {
			for( int y = 0; y < h; y++ ) {
				char ch = screen[ y ][ x ];
				if( ch == '.' || ch == '*' ) continue;
				int stx = w, sty = h, edx = -1, edy = -1;
				for( int tx = 0; tx < w; tx ++ ) {
					for( int ty = 0; ty < h; ty ++ ) {
						if( screen[ty][tx] == ch ) {
							stx = min( stx, tx );
							sty = min( sty, ty );
							edx = max( edx, tx );
							edy = max( edy, ty );
						}
					}
				}
				//長方形判定
				bool fillflg = true;
				for( int tx = stx; tx <= edx && fillflg; tx ++ ) {
					for( int ty = sty; ty <= edy && fillflg; ty ++ ) {
						fillflg &= ( screen[ ty ][ tx ] == ch || screen[ ty ][ tx ] == '*' );
					}
				}
				fig |= fillflg;
				if( fillflg ) {
					flg[ ch - 'A' ] = false;
					for( int tx = stx; tx <= edx && fillflg; tx ++ ) {
						for( int ty = sty; ty <= edy && fillflg; ty ++ ) {
							screen[ ty ][ tx ] = '*';
						}
					}
				}

			}
		}

		
		
	}

	bool b = false;
	for( int x = 0; x < w; x++ ) {
		for( int y = 0; y < h; y++ ) {
			b |= ( screen[ y ][ x ] != '.' && screen[ y ][ x ] != '*' );
		}
	}
	cout << strs[ b ] << endl;


}

int main( void ) {


	int n;
	cin >> n;

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

	return 0;

}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[])
{
  int N;

  scanf("%d", &N);

  bool flag = false;
  int i = 0;
  while (i < N) {
    char c;
    scanf(" %c", &c);
    if (flag == true && c == 'x') {
      break;
    } else if (flag == false && c == 'x') {
      flag = true;
    } else {
      flag = false;
    }
    i++;
  }

  printf("%d\n", i);
  
  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>

int selectionSort(int A[], int N) {
    int i, j, t, sw = 0, minj;
    for ( i = 0; i < N - 1; i++) {
        minj = i;
        for ( j = i; j < N; j++ ){
            if ( A[j] < A[minj] ) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if (i != minj) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;
    
    scanf("%d", &N);
    for( i = 0; i < N; i++ ) scanf("%d", &A[i]);
    
    sw = selectionSort(A,N);
    
    for (i = 0; i < N; i++){
        if ( i > 0 ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n",sw);
    
    return 0;
}


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll w, a, b;
  cin >> w >> a >> b;
  if (a > b) swap(a, b);
  cout << max(0LL, b - (a + w)) << endl;
  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if (a + b < 24){
        cout << a + b << endl;
    }
    else{
        cout << a + b - 24 << endl;
    }
    
}

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int l; 
	cin >> l;
	int m = 0;
	vector<tuple<int, int, int>> v;
	for(int i= 2; i<= 19; i++){
		v.push_back(make_tuple(i, i+1, 0));
		v.push_back(make_tuple(i, i+1, 1<<(19-i)));
		m+=2;
	}
	int mi = 0; 
	for(int sh = 0; mi<l; sh++){
		if(l &(1<< sh)){
			v.push_back(make_tuple(1, 20-min(sh,18), mi));
			mi+=(1<<min(sh,18));
			m++;
		}
	}
	cout << "20 " << v.size() << endl;
	REP(i, v.size()){
		cout << get<0>(v[i]) << " " << get<1>(v[i]) << " " << get<2>(v[i]);
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

int main(){
  
  string s;cin>>s;
  vb c(26,true);
  rep(i,0,s.size()){
    c[s[i]-'a']=false;
  }
  rep(i,0,26){
    if(c[i]){
      s+=('a'+i);
      cout<<s<<endl;return 0;
    }
  }
  drep(i,s.size()-1,0){
    c[s[i]-'a']=true;
    rep(j,s[i]-'a'+1,26){
      if(c[j]){
        string t=s.substr(0,i);
        t+=('a'+j);
        cout<<t<<endl;return 0;
      }
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;
const int MAX_N = 55555;

vector<bool> isp(MAX_N+1, true);
void sieve(){
  isp[0]=false; isp[1]=false;
  for (int i=2; i*i<=MAX_N; i++) {
    if (isp[i]) for (int j=2; i*j<=MAX_N; j++) isp[i*j]=false;
  }
}

int main() {
  int N; cin >> N;
  sieve();
  vector<int> p_1; rep(i,MAX_N+1) if (isp[i]&&i%5==1) p_1.push_back(i);
  rep(i, N) {
    if (i!=0) cout << " ";
    cout << p_1[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int s;
int m;
int h;

int main(){

    cin>>s;
 while(s>=60){
    m++;
    s-=60;

    while(m>=60){
        h++;
        m-=60;

    }
 }


cout<<h<<":"<<m<<":"<<s<<endl;

    return 0;
}



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

int main() {
 int a,b,k;
  cin >> a >> b>> k;
  for(int i=1;i<k+1;i++){
    if(i%2==1){
      if(a%2==1){
        a=a-1;
      }
        a=a/2;
        b=b+a;
    }
      
    
    if(i%2==0){
      if(b%2==1){
        b=b-1;
      }
        b=b/2;
        a=a+b;
    }
     
    
  }
  cout << a <<" " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,n) for(ll i=a; i<n; i++)

using namespace std;

void solve(){
    ll n, cnt1=0, cnt2=0, cnt3=0, cnt4=0;
    cin>>n;
    string s;
    fo(i,n){
        cin>>s;
        if(s == "AC") cnt1++;
        if(s == "WA") cnt2++;
        if(s == "TLE") cnt3++;
        if(s == "RE") cnt4++;
    }
    cout<<"AC x "<<cnt1<<endl<<"WA x "<<cnt2<<endl<<"TLE x "<<cnt3<<endl<<"RE x "<<cnt4<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
 //   cin >> t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3656
S = input()
flag = True
C = 0
l = len(S)
if not (S[0] == 'A' and 'a' <= S[1] <= 'z' and 'a' <= S[l-1] <= 'z' ):
    flag = False
i = 2
while i < l-1:
    if not 'a' <= S[i] <= 'z':
        if S[i] == 'C':
            C += 1
        else:
            flag = False
    i += 1
if flag and C == 1:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3064
#include<cmath>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int d, n, ans;

	cin >> d >> n;
	if (n != 100) {
		ans = pow(100, d)*n;
	}
	else if (n == 100) {
		ans = pow(100, d) * 101;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;

void Fast_Read_Out()
{
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
}

void Random()
{
	unsigned int seed;
	asm("rdtsc" : "=A" (seed));
	srand(seed);        
}

unsigned int Time()
{
	 unsigned int time = clock() / 1000.00;
	 return time;
}

const int inf = int(1e9) + 123;

vector <long long> v;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif 
	Random();
	Fast_Read_Out();
	int n;
	cin >> n;
	long long k = 1;
	while(k * k <= inf)
	{
		v.pb(k * k);
		k++;
	}
	for(int i = sz(v) - 1; i >= 0; i--)
	{
		if(n >= v[i]) cout << v[i], exit(0);
	}	
	#ifdef JUDGE
//		cout << Time() << endl;
	#endif
}
// Easy Peasy Lemon Squeezy

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
    string s;
    getline(cin,s);
    if(s=="SUN")
        cout<<7;
    else if(s=="MON")
        cout<<6;
    else if(s=="TUE")
        cout<<5;
    else if(s=="WED")
        cout<<4;
    else if(s=="THU")
        cout<<3;
    else if(s=="FRI")
        cout<<2;
    else
        cout<<1;
    return 0;
}


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

#define DIAGONAL 1
#define TOP 0

struct Item {
    int value;
    int weight;
};

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

    int v, w; 
    vector<Item> items;
    for (int i = 0; i < N; i++) {
        cin >> v >> w;
        items.push_back({v, w});
    }

    int T[N + 1][W + 1];
    int S[N + 1][W + 1];

    for (int i = 0; i <= W; i++) T[0][i] = 0;
    for (int i = 0; i <= N; i++) T[i][0] = 0;
    for (int n = 1; n <= N; n++) {
        for (int w = 1; w <= W; w++) {
            if (items[n - 1].weight <= w) {
                if (T[n - 1][w] < T[n-1][w - items[n-1].weight] + items[n - 1].value) {
                    T[n][w] = T[n-1][w - items[n-1].weight] + items[n - 1].value;
                    S[n][w] = DIAGONAL;
                } else {
                    T[n][w] = T[n-1][w];
                    S[n][w] = TOP;
                }
            } else {
                T[n][w] = T[n-1][w];
                S[n][w] = TOP;
            }
        }
    }

    cout << T[N][W] << endl;

    return 0;
}


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

int main(void){
    int h,w;
    cin >> h >> w;
    char s,c[h*2][w];
    for(int i = 0;i < h*2;i += 2){
        for(int j = 0;j < w;j++){
            cin >> s;
            c[i][j] = s;
            c[i+1][j] = s;
        }
    }
    
    for(int i = 0;i < h*2;i++){
        for(int j = 0;j < w;j++){
            cout << c[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
a,b,c = gets.split(" ").map(&:to_i)
ary = []
count = 0

if a===7
  count += 1
  ary.push(b)
  ary.push(c)
end
if b===7
  count += 1
  ary.push(a)
  ary.push(c)
end

if c===7
  count += 1
  ary.push(a)
  ary.push(b)
end

if count === 1 && ary[0] === 5 && ary[1] === 5
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	int a[]=new int[1000],i,j,n,sum,k,m;
    Scanner b =new Scanner(System.in);
    n= b.nextInt();
    for(i=0;i<n-1;i++)
    {
    	a[i]=b.nextInt();
    }
    sum=a[0];
    for(i=0;i<n-2;i++)
    {
    	if(a[i]>=a[i+1])
    	{
    		sum=sum+a[i+1];
    	}
    	else if(a[i+1]>a[i])
    	{
    		sum=sum+a[i];
    	}
    }
    sum=sum+a[n-2];
    System.out.println(""+sum);
	}

}


Measured memory_bytes: 23124
#coding: utf-8

S = list(input())
even = ['L','U','D']
odd = ['R','U','D']

ans_e, ans_o= [],[]

for i in range(1,len(S),2):
    if S[i] in even:
        ans_e.append(1)
    else:
        ans_e.append(0)

for i in range(0,len(S),2):
    if S[i] in odd:
        ans_o.append(1)
    else:
        ans_o.append(0)

if all(ans_o) and all(ans_e):
    print('Yes')
else:
    print('No')

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

inline int solve( int x, int y ) {
    if( x <= y )
        return y - x;
    else
        return numeric_limits<int> :: max() / 2;
}

int main( void ) {
    
    int x, y;
    cin >> x >> y;
    
    if( x == y )
        cout << 0;
    else
        cout << min( min( solve(  x, y ) + 0, solve( -x, -y ) + 2 ),
                     min( solve( -x, y ) + 1, solve(  x, -y ) + 1 ) );
    
    return 0;
}

Measured memory_bytes: 256
X,Y = map(int,input().split())
if 4*X-Y >= 0 and Y-2*X >=0:
  a = 4*X-Y
  b = Y-2*X
  if a % 2 == 0 and b %2 == 0:
    print('Yes')
  else:
    print('No')
else:
  print('No')


Measured memory_bytes: 9168
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(a * b + " " + 2 * (a + b));
	}
}


Measured memory_bytes: 26208
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, maxi = 0, ans = 0;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	for (int i = 0; i < n; i++){
		if (maxi <= h[i]) ans++;
		maxi = max(maxi, h[i]);
	}
	cout << ans << endl;
 	return 0;
}



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

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rf(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define rb(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int N = 1e5 + 1;
const int INF = 2e9;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int tot = 0;
    vi a(n + 1);
    rf(i, 1, n) {
        cin >> a[i];
        tot += a[i];
    }
    int ans = 0;
    rf(i, 1, n) {
        if (a[i] * 4 * m >= tot){
            ans++;
        }
    }

    if (ans >= m)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

# 先にk番目を抜かない場合を求めておく
ans = 0
for n in c.values():
    ans += n*(n-1)//2

# k番目を抜く場合の差分を加える
for k in range(N):
    m = c[A[k]]
    print(ans - (m-1))  # -m*(m-1)//2 + (m-1)*(m-2)//2


Measured memory_bytes: 26780
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
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 ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll h, n; cin >> h >> n;
    vector<int> at(n), mp(n);
    REP(i, n) cin >> at[i] >> mp[i];
    ll dp[n+1][h+1];
    REP(i, n+1)REP(j, h+1) dp[i][j] = INF;
    dp[0][0] = 0;
    for(ll i=0; i<n; i++){
        for(ll j=0; j<=h; j++){
            chmin(dp[i+1][j], dp[i][j]);
            //chmin(dp[i+1][min(h, j+at[i])], dp[i+1][j] + mp[i]);
            chmin(dp[i+1][j], dp[i+1][max(j-at[i], 0LL)] + mp[i]);

        }
    }
    cout << dp[n][h] << endl;
}

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

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

using namespace std;

int main() {
  int W, a, b;
  cin >> W >> a >> b;

  if (a + W < b) {
    cout << b - (a + W) << "\n";
  } else if (b + W < a) {
    cout << a - (b + W) << "\n";
  } else {
    cout << 0 << "\n";
  }
  return 0;
}


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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define scan(n)         scanf("%d",&n)
#define pb              push_back
#define vi              vector<int>
#define ii              pair<int,int>

using namespace std;

int main(){
    ll n;cin>>n;
    vector<ll> v1(n),v2(n);
    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        ll x;cin>>x;
        v1[i]=((i+1)+x);
        v2[i]=((i+1)-x);
        if(mp.find(v1[i])==mp.end()){
            mp[v1[i]]=0;
        }
        mp[v2[i]]++;
    }
//    cout<<"v1: ";for(auto it:v1)cout<<it<<" ";cout<<endl;
//    cout<<"v2: ";for(auto it:v2)cout<<it<<" ";cout<<endl;
    ll cnt=0;
    for(auto it:v1){
        cnt+=mp[it];
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 29052
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> L >> R;
	if (L%N == 0) {
		cout << "OK\n";
		return 0;
	}
	if (L / N != R / N) {
		cout << "OK\n";
	}
	else {
		cout << "NG\n";
	}
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int k, s;
	cin >> k >> s;
	int counter = 0;
	for (int x = 0; x <= k; ++x) {
		for (int y = 0; y <= k; ++y) {
			int z = s - x - y;
			if (0 <= z && z <= k) counter++;
 		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

string s;
string t;

string solve() {
  int k = 0;
  string res = "~";
  rep(i, s.length() - t.length() + 1) {
    string cs = s.substr(i, t.length());
    string v = ""; rep(k, s.length()) v.pb(s[k]);
    bool f = true;
    rep(j, t.length()) {
      if (t[j] == cs[j] || cs[j] == '?') v[i + j] = t[j];
      else { f = false; break; };
    }
    if (!f) continue;
    rep(j, v.length()) {
      if (v[j] == '?') v[j] = 'a';
    }
    res = min(res, v);
  }
  if (res == "~")
    return "UNRESTORABLE";
  return res;
}

int main() {
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
 
N = int(input())
S = []
for i in range(N):
    S.append(input())
S.sort()

c = Counter(S).most_common()

m = c[0][1]
c.sort()
for i in range(len(c)):
    if c[i][1] == m:
        print(c[i][0])

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

int main(){
    int len = 4;
    string s; cin >> s;

    for (int i=0;i<len-1;i++) {
        if (s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
    return 0;
}

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

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

#define MOD 1000000007

template<int64_t mod> struct Combination{
    vector<int64_t> f, rf;
 
    Combination(int max_n): f(max_n+1), rf(max_n+1){
        f[0] = 1;
        for(int i = 1;i <= max_n;i++) f[i] = f[i-1] * i % mod;
		int64_t a = f[max_n], inv = 1;
		for(int64_t b = mod-2;b > 0;b>>=1){
			if(b & 1) inv = inv*a % mod;
			a = a * a % mod;
		}
		for(int i = max_n;i >= 0;i--) inv = (rf[i] = inv) * i % mod;
    }
 
    int64_t operator()(int n, int r){
        return (r < 0 || n < r) ? 0 : f[n] * rf[r] % mod * rf[n-r] % mod;
    }
};


int mk[500010];
int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

int npr(int n, int r){
	return mk[n] * pow_mod(mk[n-r], MOD-2) % MOD; 
}

signed main(){
	int n, m;
	cin >> n >> m;
	
	Combination<MOD> ncr(n+m);

	mk[0] = 1;
	for(int i = 1;i <= m;i++) mk[i] = mk[i-1]*i % MOD;

	int ans = 0;
	for(int i = 0;i <= n;i++){
		int tmp = npr(m-i, n-i)*npr(m-i, n-i) % MOD * ncr(n, i) % MOD * npr(m, i) % MOD;
		if(i % 2 == 0){
			ans = (ans + tmp) % MOD;
		}else{
			ans = (MOD + ans-tmp) % MOD;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 22700
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, L;
        cin >> N >> L;
        ll sum = 0;
        for (int i = 0; i < N; ++i) {
            sum += L + i;
        }

        ll ans = sum;
        if (L == 0) {
            ans = sum;
        } else if (L < 0 && L + N - 1 >= 0) {
            ans = sum;
        } else if (L + N - 1 <= 0) {
            ans -= L + N - 1;
        } else {
            ans -= L;
        }

        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : String = get_one();
    let t : String = get_one();

    let ss : Vec<char> = s.chars().collect();
    let tt : Vec<char> = t.chars().collect();

    let mut ans = String::new();
    for i in 0..(ss.len()) {
        ans.push(ss[i]);
        if i < tt.len() {
            ans.push(tt[i]);
        }
    }
    println!("{}", ans);
}


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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int logest = 0;
  int sum = 0;
  for (int j = 0; j < s.length(); j++) {
    if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
      sum++;
    } else {
      logest = max(logest, sum);
      sum = 0;
    }
  }
  logest = max(logest, sum);
  cout << logest << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
v = [0] * (N + 1)

for a in list(map(int, input().split())):
    v[int(a)] += 1

v = sorted(v, reverse=True)
if 0 in v:
    v = v[:v.index(0)]
v = list(reversed(v))

ans = 0
for i in range(len(v)):
    if len(v) - i <= K:
        break
    ans += v[i]

print(ans)


Measured memory_bytes: 26660
from sys import stdin,setrecursionlimit

n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

jw = li[0][0]
omosa = [[] for _ in range(4)]

for i in li:
    omosa[i[0]-jw].append(i[1])

for i in range(len(omosa)):
    omosa[i].sort(reverse = True)

saidai = n
ma = 0

for i in range(len(omosa[0])+1):
    for j in range(len(omosa[1])+1):
        for k in range(len(omosa[2])+1):
            for l in range(len(omosa[3])+1):
                to_ka = omosa[0][:i]+omosa[1][:j]+omosa[2][:k]+omosa[3][:l]
                if i*jw+j*(jw+1)+k*(jw+2)+l*(jw+3) > w:
                    continue
                ma = max(ma,sum(to_ka))

print(ma)

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    string s, t;
    cin >> s >> t;
    t.pop_back();

    cout << (s == t? "Yes" : "No") << endl;
}

Measured memory_bytes: 3652
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int h,w;cin>>h>>w;
    while(h&&w){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++)cout<<'#';cout<<endl;
        }
        cin>>h>>w;
        cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s;
    int q;
    cin >> s >> q;
    string t;
    for(int i = 0;i < q;i++){
        int T;
        cin >> T;
        if(T == 1){
            swap(s,t);
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1) t.push_back(c);
            else s.push_back(c);
        }
    }
    reverse(t.begin(),t.end());
    s = t + s;
    cout << s << endl;
}

Measured memory_bytes: 1116
S = input()
ans = 0
for s in range(len(S)):
    for e in range(s + 1, len(S) + 1):
        ss = S[s:e]
        for c in ss:
            if not c in "ACGT":
                break
        else:
            ans = max(ans, len(ss))
print(ans)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s, t;
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> s;
    n = int(s.length());
    t = string(n, 'g');
    for (int i = 1; i < n; i += 2) {
        t[i] = 'p';
    }
    //cerr << t << endl;
    int ans = 0;
    forn(i, n) {
        if (s[i] == 'p' && t[i] == 'g') {
            --ans;
        } else if (s[i] == 'g' && t[i] == 'p') {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512