akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int h,w;
char s[425][425];
bool used[425][425];

int d[] = {1,0,-1,0,1};
pii dfs(int i, int j){
  used[i][j] = true;
  pii P = pii(0,0);
  if(s[i][j]=='.')P.first++;
  else P.second++;
  REP(dd,4){
    int ni = i+d[dd], nj = j+d[dd+1];
    if(ni<0 || nj<0 || ni>=h || nj>=w)continue;
    if(used[ni][nj])continue;
    if(s[ni][nj] == s[i][j])continue;
    pii Q = dfs(ni,nj);
    P.first += Q.first;
    P.second += Q.second;
  }
  return P;
}

int main(){
  scanf("%d%d",&h,&w);
  REP(i,h)scanf("%s",s[i]);
  ll ans = 0;
  REP(i,h)REP(j,w)if(!used[i][j]){
    pii P = dfs(i,j);
    ans += (ll)P.first * P.second;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 13056
#include <stdio.h>
int main(){
int n;
int a, b, c, d;
int count;
while(scanf("%d", &n) != EOF){
count = 0;
for(a = 0; a < 10; a++){
for(b = 0; b < 10; b++){
for(c = 0; c < 10; c++){
for(d = 0; d < 10; d++){
if(a + b + c + d == n){
count++;
break;
}
}
}
}
}
printf("%d\n", count);
}
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;


#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);

	int t=1;
	//cin>>t;
	while(t--){
		long long r,c;
		cin>>r>>c;
		double x = r*c;
		if(c==1 || r==1)
			cout<<1<<'\n';
		else
			cout<<(long long )ceil(x/2);
	}



return 0;
}

Measured memory_bytes: 256
from fractions import gcd
str_1_len, str_2_len = map(int, input().split())
string_1 = input()
string_2 = input()

gr_com_div = gcd(str_1_len, str_2_len)
low_com_multpl = int(str_1_len * str_2_len / gr_com_div)
flg = True

for i in range(gr_com_div):
    if string_1[i*str_1_len//gr_com_div] == string_2[i*str_2_len//gr_com_div]:
        continue
    else:
        flg = False
if flg:
    print(low_com_multpl)
else:
    print(-1)


Measured memory_bytes: 5432
#include <stdio.h>
int main(){
  int i,j,n,cards[256][14];
  int mark[4]={'S','H','C','D'};
  
  for(i=0;i<256;i++){
      for(j=0;j<14;j++){
          cards[i][j]=0;
      }
  }
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
      char c=0;
      int num=0;
      scanf("%c %d\n",&c,&num);
      cards[c][num]=1;
  }
  for(j=0;j<4;j++){
      for(i=1;i<14;i++){
          if(cards[mark[j]][i]==0){
              printf("%c %d\n",mark[j],i);
          }
      }
  }
  return 0;  
}


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

int main() {

    int N, M;
    cin >> N >> M;

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

    int days4homework = 0;
    for (int i = 0; i < M; i++) {
        days4homework += A[i];
    }
    cout << max(-1, N - days4homework) << endl;

    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int Prime[55556];   //Prime[i]が1だったらiは素数。0だったら素数でない

void Eratosthenes(int m) {  //m未満の素数を求める

    rep(i, m) {
        Prime[i] = 1;
    }

    Prime[0] = 0;  Prime[1] = 0;
    for(int i = 2; i*i < m; i++) {
        if(Prime[i]) {
            for(int j = 0; i*(j + 2) < m; j++) {
                Prime[i*(j+2)] = 0;
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    int a[n];
    int j = 0;    

    Eratosthenes(55556);

    for(int i = 11; i <= 55555; i += 5) {
        if(Prime[i]) {
            a[j] = i;
            j++;
        }
        if(j >= n) {
            break;
        }
    }

    rep(i, n-1) {
        cout << a[i] << " ";
    }
    cout << a[n-1];

    cout << endl;
    return 0;
}

Measured memory_bytes: 512
N, K, L = map(int, input().split())
u1 = [i for i in range(N)]
u2 = [i for i in range(N)]

def root(u, n):
    if u[n] == n:
        return n
    else:
        t = root(u, u[n])
        u[n] = t
        return t

def update(u, r, n):
    u[root(u, n)] = root(u, r)

for i in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    update(u1, p, q)

for i in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    update(u2, r, s)

p = [(root(u1, i), root(u2, i)) for i in range(N)]
ans = {}
for x in p:
    if x not in ans:
        ans[x] = 1
    else:
        ans[x] += 1
print(' '.join(map(str, [ans[x] for x in p])))

Measured memory_bytes: 129272
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	int mx = -1e6, mn = 1e6;
	rep(i, n)
	{
		mx = max(mx, a[i]);
		mn = min(mn, a[i]);
	}
	if (0 <= mn)
	{
		cout << n - 1 << endl;
		rep(i, n - 1)
		{
			cout << i + 1 << " " << i + 2 << endl;
		}
	}
	else if (mx < 0)
	{
		cout << n - 1 << endl;
		rrep(i, n - 1)
		{
			cout << i + 2 << " " << i + 1 << endl;
		}
	}
	else
	{
		cout << 2 * (n - 1) << endl;
		if (abs(mn) <= mx)
		{
			int mxindex = 0;
			rep(i, n)if (a[i] == mx)mxindex = i;
			rep(i, n)
			{
				if (i == mxindex)continue;
				cout << mxindex + 1 << " " << i + 1 << endl;
			}
			rep(i, n - 1)cout << i + 1 << " " << i + 2 << endl;
		}
		else
		{
			int mnindex = 0;
			rep(i, n)if (a[i] == mn)mnindex = i;
			rep(i, n)
			{
				if (i == mnindex)continue;
				cout << mnindex + 1 << " " << i + 1 << endl;
			}
			rrep(i, n - 1)cout << i + 2 << " " << i + 1 << endl;
		}
	}
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    ll n, a, b;
    cin >> n >> a >> b;
    cout << n / (a + b) * a + min(a, n % (a + b));
}


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

int main() {
  int n,d,x;cin>>n>>d>>x;
  int cnt=x;
  d--;
  rep(i,n){
    int a;cin>>a;
    
    cnt+=d/a+1;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3620
#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define F first
#define S second 
#define pb push_back
#define endl "\n"

#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

#ifdef DEBUG
    #define dbg(s) {s;}
#endif

#ifndef DEBUG
    #define dbg(s)
#endif

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, x-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}

#define int ll
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 

#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;

int getInt () {
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}


ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 

const ll mod = 1e9 + 7;

ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int maxn = 1e6 + 7;

const ll inf = 1e9 + 7;


i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);

    IOS;

    int n;
    cin>>n;

    int arr[n+100];
    for(int i=1;i<=n;i++)
        cin>>arr[i];

    int ans = 0;
    sort(arr+1,arr+n+1);

    int maxi;
    int l,r;
    for(int i= 3;i<=n;i++)
    {
        l = 1;
        r = i-1;
        maxi = arr[i];
        
        while(r>l)
        {
            while(l<r && arr[l]+arr[r]<=maxi)
                l++;
            
            ans+=r-l;
            r--;
        }

    }

    cout<<ans<<endl;
    
    
}





Measured memory_bytes: 384
N,W=map(int,input().split())
w=[]
v=[]
for _ in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)
dp=[[float('inf')]*(V+1) for _ in range(N+1)]
dp[0][0]=0
for i in range(N):
    for sum_v in range(V+1):
        if sum_v-v[i]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v],dp[i][sum_v-v[i]]+w[i])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]
res = 0
for i in range(V+1):
    if dp[N][i]<=W:
        res = i
print(res)


Measured memory_bytes: 307912
n, w_max = gets.split.map(&:to_i)
items = Array.new(n){gets.split.map(&:to_i)}
v_max = items.map(&:last).inject(:+)
dp = Array.new(v_max+1, Float::INFINITY)
dp[0] = 0
items.each do |iw, iv|
  prev = dp.dup
  (iv..v_max).each do |v|
    w = prev[v-iv] + iw
    dp[v] = w if w <= w_max && w < prev[v]
  end
end
puts dp.rindex{|v|v != Float::INFINITY}


Measured memory_bytes: 28108
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   int ans = 0;
   f(i,1,n+1){
      if(i%3 == 0 or i%5 == 0) continue;
      ans += i;
   }
   cout << ans << '\n';
   return 0;
} 


Measured memory_bytes: 3600
#include<stdio.h>

#define H 500001


int A[H];
int n;

void MaxHeapify(int i){
  int Left = 2*i;
  int Right = 2*i+1;
  int Largest;
  int temp;

  if(Left <= n && A[Left] > A[i]){
    Largest = Left;
  }
  else{
    Largest = i;
  }
  if(Right <= n && A[Right] > A[Largest]){
    Largest = Right;
  }
  if(Largest != i){
    temp = A[i];
    A[i] = A[Largest];
    A[Largest] = temp;
    MaxHeapify(Largest);
  }
}

void BuildMaxHeap(void){
  int i;
  for(i = (n/2);i >=1;i--){
    MaxHeapify(i);
  }
}

int main(){
 
  int i;

  scanf("%d",&n);
  for(i = 1;i <= n;i++){
    scanf("%d",&A[i]);
  }

  BuildMaxHeap();

  for(i = 1;i <= n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}
 

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin>>s;
  ll a[s.size()];
  for(int i=0;i<s.size();i++)a[i]=s[i]-'a'+49;
  ll sum=0;
  int n=s.size();
  if(n==1){
    cout<<a[0]<<endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n-i;j++){
      if(j<n-i-1)sum+=a[j]*pow(2,n-2-i)*pow(10,i);
      if(j==n-i-1)sum+=a[j]*pow(2,n-1-i)*pow(10,i);
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2LL;
  }
  return res;
}

int main() {
  ll n, k, ans = 0LL, cnt[100001] = {};
  vector<int> v[100001];
  int a[1001] = {};
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k; i++) {
    for (int j = 2 * i; j <= k; j += i) {
      v[j].push_back(i);
    }
  }
  for (ll i = k; i >= 1LL; i--) {
    ll num = mod_pow(k / i, n, MOD);
    num += MOD - cnt[i];
    num %= MOD;
    for (int j = 0; j < v[i].size(); j++) {
      cnt[v[i][j]] += num;
      cnt[v[i][j]] %= MOD;
    }
    num *= i;
    num %= MOD;
    ans += num;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 14380
#include<stdio.h>
int main()
{
	int K, R;
	int inner;
	scanf("%d %d", &K, &R);
	inner = 100 * (10-K);
	
	if(K<10)
	{
		printf("%d\n", inner+R);
	}
	else if(K>=10)
	{
		printf("%d\n", R);
	}
	return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

tuple<vi, vi> split(int N, string& s) {
    vi row(N, 0), col(N, 0);
    for (int i = 0; i < N; i++) {
        if (s[i] == 'U') row[i] = -1;
        else if (s[i] == 'D') row[i] = 1;
        else if (s[i] == 'L') col[i] = -1;
        else col[i] = 1;
    }
    return make_tuple(row, col);
}

bool safe(int N, vi& atk, vi& def, int loc, int D) {
    vi moves;
    for (int i = 0; i < N; i++) {
        moves.push_back(atk[i]);
        moves.push_back(def[i]);
    }
    N *= 2;

    vector<array<int, 2>> safe(N);
    safe[N - 1] = { 0, D - 1 };
    for (int m = N - 2; m >= 0; m--) {
        safe[m] = safe[m+1];
        int &l = safe[m][0],
            &r = safe[m][1];
        if (l > r) continue;

        if ((m&1)) {
            // defender
            if (moves[m] == 1)
                l = max(l - 1, 0);
            if (moves[m] == -1)
                r = min(r + 1, D - 1);
        } else {
            // attacker
            if (moves[m] == 1)
                r--;
            if (moves[m] == -1)
                l++;
        }
    }

    return safe[0][0] <= loc && loc <= safe[0][1];
}

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

    int H, W, N;
    cin >> H >> W >> N;

    int sr, sc;
    cin >> sr >> sc;
    sr--, sc--;

    string S, T;
    cin >> S >> T;

    vi atkR, atkC, defR, defC;
    tie(atkR, atkC) = split(N, S);
    tie(defR, defC) = split(N, T);

    bool ans = safe(N, atkR, defR, sr, H)
            && safe(N, atkC, defC, sc, W);

    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 11040
// C - Domino Quality
#include <bits/stdc++.h>

using namespace std;

const char *a3[] = {
	"a..",
	"a..",
	".bb",
};

const char *a4[] = {
	"abcc",
	"abdd",
	"ccab",
	"ddab",
};

const char *a5[] = {
	"accdd",
	"ae..a",
	"be..a",
	"b.ffb",
	"ccddb",
};

const char *a6[] = {
	"aabc..",
	"ddbc..",
	"..aabc",
	"..ddbc",
	"bc..aa",
	"bc..dd",
};

const char *a7[] = {
	"aabbcc.",
	"dd.dd.a",
	"..d..da",
	"..d..db",
	"dd.dd.b",
	"..d..dc",
	"..d..dc",
};

void fill3(vector<string> &a, int x, int y)
{
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) a[x + i][y + j] = a3[i][j];
}

void fill4(vector<string> &a, int x, int y)
{
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++) a[x + i][y + j] = a4[i][j];
}

void fill5(vector<string> &a, int x, int y)
{
	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++) a[x + i][y + j] = a5[i][j];
}

void fill6(vector<string> &a, int x, int y)
{
	for (int i = 0; i < 6; i++)
		for (int j = 0; j < 6; j++) a[x + i][y + j] = a6[i][j];
}

void fill7(vector<string> &a, int x, int y)
{
	for (int i = 0; i < 7; i++)
		for (int j = 0; j < 7; j++) a[x + i][y + j] = a7[i][j];
}
int main(int argc, char *argv[])
{
	int n;
	cin >> n;

	bool ok = false;
	vector<string> a(n, string(n, '.'));

	if (n % 3 == 0) {
		for (int i = 0; i < n; i += 3) fill3(a, i, i);
		ok = true;
	} else if (n % 4 == 0) {
		for (int i = 0; i < n; i += 4) fill4(a, i, i);
		ok = true;
	} else if (n % 5 == 0) {
		for (int i = 0; i < n; i += 5) fill5(a, i, i);
		ok = true;
	} else if (n % 7 == 0) {
		for (int i = 0; i < n; i += 7) fill7(a, i, i);
		ok = true;
	}

	for (int x = 0, y = n; x < n && !ok; x += 4, y -= 4) {
		if (y % 5 == 0) {
			ok = true;
			for (int i = 0; i < x; i += 4) fill4(a, i, i);
			for (int i = x; i < n; i += 5) fill5(a, i, i);
		} else if (y % 6 == 0) {
			ok = true;
			for (int i = 0; i < x; i += 4) fill4(a, i, i);
			for (int i = x; i < n; i += 6) fill6(a, i, i);
		} else if (y % 7 == 0) {
			ok = true;
			for (int i = 0; i < x; i += 4) fill4(a, i, i);
			for (int i = x; i < n; i += 7) fill7(a, i, i);
		}
	}

	if (ok)
		for (int i = 0; i < n; i++) cout << a[i] << endl;
	else
		cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int N, M;
int g[55][55];

bool used[55];
void dfs(int s) {
    if(used[s]) return;
    used[s] = true;
    rep(i, N) {
        if(g[s][i]) dfs(i);
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    cin >> N >> M;
    memset(g, 0, sizeof(g));
    rep(i, M) {
        int a, b; cin >> a >> b;
        a --; b --;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    int cnt = 0;
    rep(i, N) {
        Rep(j, i + 1, N) {
            if(g[i][j]) {
                g[i][j] = 0; g[j][i] = 0;
                rep(k, N) used[k] = false;
                dfs(0);
                bool flag = true;
                rep(k, N) {
                    if(used[k] == false) flag = false;
                }
                if(flag) cnt ++;
                g[i][j] = 1; g[j][i] = 1;
            }
        }
    }
    cout << M - cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] n = saori.nextHayami().split("");
		if(n[0].equals("9")){
			System.out.println("Yes");
		} else if(n[1].equals("9")){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

void solve(){
  ll N;
  cin >> N;
  vector<string> S(N);
  vector<ll> T(N);
  rep(i, N){
    cin >> S[i];
    cin >> T[i];
  }
  string X;
  cin >> X;
  ll ans = 0;
  bool ok = 0;
  rep(i, N){
    if(ok) ans += T[i];
    if(S[i] == X) ok = 1;
  }
  cout << ans << endl;

}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define rep(i,b) for(int i = 0 ; i < b; i++)
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(a) (int)a.size()
#define mod 1000000007
#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>



void solve()
{
    int n;cin>>n;
    ld a[n];rep(i,n) cin>>a[i];
    sort(a,a+n);
    ld ans=a[0];
    rep(i,n-1){
        ans=(a[i+1]+ans)/2;
    }
    cout<<ans;
}
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(11);
    clock_t beg=clock();
    int t=1, n;
    // cin>>t;
    // n = t;
    while(t--){
        // cout << "Case #" << n-t << ": ";
        solve();
    }
    //
    clock_t end=clock();
    fprintf(stderr, "%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines
    val n = in.next.toInt
    val es = in.take(n).flatMap(e => {
        val Array(r, _, t@_*) = e.split(" ").map(_.toInt)
        t.map((r, _))
    }).toList
    in.next
    for (Array(s, d, v) <- in.map(_.split(" ").map(_.toInt))) {
        val g = Array.fill(n+1)(Int.MaxValue-100)
        g(s) = 1
        var flag = true
        while(flag) {
            flag = false
            for (e <- es) if (g(e._1) + 1 < g(e._2)) {g(e._2) = g(e._1) + 1; flag = true}
        }
        println(if (v >= g(d)) g(d) else "NA")
    }
}

Measured memory_bytes: 49200
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int f[N],a[N];
bool vis[N];
int sf(int x) {
    return f[x] == x? x: f[x] = sf(f[x]);
}
void merge(int u,int v) {
    u = sf(u), v = sf(v);
    if(u > v) swap(u,v);
    f[v] = u;
}
int main()
{
    int n,m,k;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)f[i]=i;
    for(int i=1;i<=n;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            scanf("%d",&a[j]);
            vis[a[j]]=true;
        }
        for(int j=0;j<k-1;j++){
            merge(a[j], a[j+1]);
        }
    }
    int cnt = 0;
    for(int i=1;i<=m;i++) {
        if(!vis[i]) continue;
        if(i == sf(i)) cnt++;
        //cout << i << ' ' << sf(i) << endl;
    }
    //cout << "ck " << cnt << endl;
    puts(cnt==1?"YES":"NO");
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 305;

signed main(){
    int n,m;
    cin >> n >> m;
    int A[n_max][n_max];
    REP(i,n) REP(j,m){
        cin >> A[i][j];
        A[i][j] --;
    }
    int ans = INF;
    bool use[m];
    REP(i,m) use[i] = true;
    int cnt[m];
    REP(i,m){
        REP(j,m) cnt[j] = 0;
        REP(j,n){
            REP(k,m){
                if(use[A[j][k]]){
                    cnt[A[j][k]] ++;
                    break;
                }
            }
        }
        int ma = -1;
        int id = -1;
        REP(j,m) if(ma < cnt[j]){
            ma = cnt[j];
            id = j;
        }
        chmin(ans,ma);
        use[id] = false;
    }
    cout << ans << endl;

}

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

int main(void){
  //数列を格納する文字列str
  //int型の配列seq
  char str[1000] = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  int seq[32];
  char *p;
  
  //int型変数 K
  int K;
  char num[1000];

  //Kに値を格納する
  fgets(num, sizeof(num), stdin);
  K = atoi(num);
  
  int i = 1;
  p = strtok(str, ",");
  seq[0] = atoi(p);
  
  //seqに数値を格納していく
  while(p != NULL){
    p = strtok(NULL, ",");
    if(p == NULL){
      break;
    }
    seq[i] = atoi(p);
    i += 1;
  }
  
  printf("%d\n", seq[K - 1]);  
  return 0;
}

Measured memory_bytes: 2056
n = map(int,input().split())
a = list(map(int,input().split()))
LIM = 10**18

ans = 1

if 0 in a:
    print(0)
    exit()
else:
    for i in a:
        ans *= i
        if ans > LIM:
            print(-1)
            exit()

print(ans)


Measured memory_bytes: 21472
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Monad.Primitive
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Sequence as Sq
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

readIntBS = fst . fromJust . BS.readInt

for = flip map

infixr 1 ?
(?) :: Bool -> (a,a) -> a
(?) b t = (if b then fst else snd) t


main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine :: IO [Int]
  as <- scanl1 (+) . sort . map read . words <$> getLine :: IO [Int]

  let a = length $ takeWhile (<=x) as

  print $
    if a == n && last as < x then
      a - 1
    else
      a


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
vector<long long> v;
int main(){
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
long long n,q,sum=0; cin>>n;
for(long long i=0;i<n;i++){
    cin>>q;
    sum+=q;
    v.push_back(q);
}
q=0;
for(long long i=0;i<n;i++){
    long long el=v[i];
    sum-=el;
   q+=el*(sum%mod);
   q%=mod;
}
cout<<q<<'\n';
return 0;
}


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

using namespace std;

const int INF = 1e9 + 7;
vector<int> prime;
bool p[1001];
int cnt[1001];

int main(void)
{
	for(int i = 2; i <= 1000; i++)
	{
		if(p[i])	continue;

		for(int j = i+i; j <= 1000; j += i)
			p[j] = true;
		prime.push_back(i);
	}

	int n;
	scanf("%d", &n);
	if(n == 1)
	{
		printf("1\n");
		return 0;
	}

	for(int i = 2; i <= n; i++)
	{
		int cur = i;
		for(int it: prime)
		{
			while(cur % it == 0)
			{
				cur /= it;
				cnt[it]++;
			}
		}
	}

	long long ret = 1;
	for(int i = 1; i <= 1000; i++)
		ret = (ret * (cnt[i]+1)) % INF;
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];
        for(int i = 0; i < n; i++){
            d[i] = Integer.parseInt(sc.next());
        }
        
        int ans = 0;
        for(int a = 0; a < n-1; a++){
            for(int b = 0; b < n-1-a; b++){
                ans += d[a] * d[a+1+b];
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
/*
 * PrintTestCases.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

int main(void) {

	vector<int> vecValue;

	while(1) {
		int a = 0;
		cin >> a;
		if (0 == a) {
			break;
		}
		vecValue.push_back(a);
	}

	for (unsigned int i = 0; i < vecValue.size(); i++) {
		cout << "Case " << i + 1 << ": " << vecValue.at(i) << endl;
	}

	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e2 + 5;
const int INF = 1e9 + 7;

int a, b, h, m;

long double Convert(long double degree)
{
	long double pi = 3.14159265359;
	return (degree * (pi / 180));
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> h >> m;
	long double degreeofhour = 0, degreeofminute = 0;
	if (h != 12)
		degreeofhour = (long double)0.5 * (h * (long double)60 + m);
	if (m != 60)
		degreeofminute = m * (long double)6;
	long double degreebetweentwohands = max(degreeofhour, degreeofminute) - min(degreeofhour, degreeofminute);
	degreebetweentwohands = min(360 - degreebetweentwohands, degreebetweentwohands);
	long double angleinrad = Convert(degreebetweentwohands);
	// long double finalangle = cal_cos(degreebetweentwohands);
	long double ans = sqrt(a * a + b * b - (2 * a * b * cos(angleinrad)));
	cout << fixed << setprecision(9) << ans;
	return 0;
}
//11-09-2020 09:39:01

Measured memory_bytes: 4132
package main

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

func main() {
	solve(os.Stdin, os.Stdout)
}

var K int

func solve(in io.Reader, out io.Writer) {
	var bs = NewBufScanner(in)
	var bw = NewBufWriter(out)
	defer bw.w.Flush()

	line := strings.Split(bs.Scan(), " ")
	N, _ := strconv.Atoi(line[0])
	K, _ = strconv.Atoi(line[1])

	m := make([][]int, 2*K)
	sum := make([][]int, 2*K)

	for i := 0; i < 2*K; i++ {
		m[i] = make([]int, 2*K)
		sum[i] = make([]int, 2*K)
	}

	for i := 0; i < N; i++ {
		line = strings.Split(bs.Scan(), " ")
		x, _ := strconv.Atoi(line[0])
		y, _ := strconv.Atoi(line[1])
		if line[2] == "W" {
			y += K
		}

		m[x%(2*K)][y%(2*K)]++
	}

	// 2次元累積和（ゼータ返還）
	// x方向に加算
	for y := 0; y < 2*K; y++ {
		for x := 0; x < 2*K; x++ {
			if x > 0 {
				m[x][y] += m[x-1][y]
			}
		}
	}

	// y方向に加算
	for x := 0; x < 2*K; x++ {
		for y := 0; y < 2*K; y++ {
			if y > 0 {
				m[x][y] += m[x][y-1]
			}
		}
	}

	max := 0
	for x := 0; x < 2*K; x++ {
		for y:= 0; y < 2*K; y++ {
			tmp := get(x, y, m)
			tmp += get(x-K, y+K, m)
			tmp += get(x+K, y-K, m)
			tmp += get(x+K, y+K, m)
			tmp += get(x-K, y-K, m)
			tmp += get(x-2*K, y, m)
			tmp += get(x, y-2*K, m)
			tmp += get(x-2*K, y-2*K, m)
			max = int(math.Max(float64(max), float64(tmp)))
		}
	}

	bw.Printf("%d\n", max)
}

func get(x, y int, m [][]int) int {
	if !isGet(x, y) {
		return 0
	}

	tx := int(math.Min(float64(x+K-1), float64(len(m)-1)))
	ty := int(math.Min(float64(y+K-1), float64(len(m)-1)))
	num := m[tx][ty]
	if in(x-1, y-1) {
		num += m[x-1][y-1]
	}
	if in(x-1, ty) {
		num -= m[x-1][ty]
	}
	if in(tx, y-1) {
		num -= m[tx][y-1]
	}
	return num
}

func in(x, y int) bool {
	return 0 <= x && x < 2*K && 0 <= y && y < 2*K
}

// わかりにくいけど図示
// △:x - 1, y + K -1 || x + K - 1, y -1
// ★:x, y
// ☆:x + K -1, y + K -1
// ☐☐☐☐
// △☐☆☐
// ☐★☐☐
// ☐☐△☐
func isGet(x, y int) bool {
	return in(x, y) || in(x+K-1, y+K-1) || in(x-1, y+K-1) || in(x+K-1, y-1)
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 51456
#include <stdio.h>

void Do(int N, int L){
  int i, S;
  S = 0;
  for(i = 0;i < N;i++) S += L + i;
  if(L > 0) S -= L;
  else if(L + N - 1 < 0) S -= L + N - 1;
  printf("%d\n", S);
}

int main(void){
  int N, L;
  scanf("%d %d", &N, &L);
  Do(N, L);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, q;
    cin >> n >> q;
    UnionFind uf(n);
    rep(i, q) {
        ll com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            uf.merge(x, y);
        }
        else {
            cout << (uf.is_same(x, y) ? 1 : 0) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
 
int x,n,a;
map<int,int> m;
 
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>x;
		m[x]++;
	}
	
	for (auto i=m.begin();i!=m.end();i++){
		//cout<<i->first<<' '<<i->second<<endl;
		if (i->first != i->second){
			if (i->second > i->first)
				a += (i->second - i->first);
			else 
				a += i->second;
		}
	}
	
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 4736
import math
def lb(a,x):
    l=0
    r=len(a)-1
    while l<r:
        mid=int((l+r)/2)
        #print "l=",l,' r=',r
        if a[mid]<x:
            l=mid+1
        else:
            r=mid
    return l

#maxn=1000001 // Wrong Answer?
maxn=1000010
a=[False for i in xrange(maxn)]
for i in xrange(2,int(math.sqrt(maxn))):
    for j in xrange(i+i,maxn,i):
        a[j]=True
b=[]
for i in xrange(2,maxn):
    if not a[i]:
        b.append(i)
while True:
    try:
        n=input()
        f=lb(b,n)
        if b[f]==n:
            print(f+1)
        else:
            print(f)
    except EOFError: break

Measured memory_bytes: 14612
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  string str = in<string>();
  cout << (str=="ABC"?"ARC":"ABC") << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
#include <bits/stdc++.h>
#include<fstream>
using namespace std;

int main(){
   long long n,d;
   cin>>n>>d;
   d=d*d;
   long long x[n],y[n];
   for(long long i=0;i<n;i++){
      cin>>x[i]>>y[i];
   }
   long long ans=0;
   for(long long i=0;i<n;i++){
      long long dis;
      dis = x[i]*x[i]+y[i]*y[i];
      if(dis<=d) ans+=1;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 6708
import java.util.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer t;
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		int[] A = new int[n];
		int[] B = new int[n];
		int[] C = new int[n];
		for(int i = 0 ; i < n ; i++)
		{
		      t = new StringTokenizer(br.readLine());
		      a[i] = Integer.parseInt(t.nextToken());
		      b[i] = Integer.parseInt(t.nextToken());
		      c[i] = Integer.parseInt(t.nextToken());
		} 
		Arrays.fill(A,Integer.MIN_VALUE);
		Arrays.fill(B,Integer.MIN_VALUE);
		Arrays.fill(C,Integer.MIN_VALUE);
		A[n-1] = a[n-1];
		B[n-1] = b[n-1];
		C[n-1] = c[n-1];
		for(int i = n-2 ; i >= 0 ; i--)
		{
		      A[i] = a[i]+Math.max(B[i+1],C[i+1]);
		      B[i] = b[i]+Math.max(A[i+1],C[i+1]);
		      C[i] = c[i]+Math.max(B[i+1],A[i+1]);
		}
		System.out.println(Math.max(Math.max(A[0],B[0]),C[0]));
	}
}

Measured memory_bytes: 46276
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,l;
  cin>>n>>l;
  int a[n],i,s;
  s=0;
  bool t;
  t=true;
  int sum=0;
  vector<int> p;
  for(i=0;i<n;i++)
  {
    s = l+i;
    a[i]=s;
    sum = sum+a[i];
    
    if(s==0)
      t = false;
  }
    if(t && a[0]>0)
    {
      cout<<sum-a[0];
    }
  if(t && a[0]<0)
  {
    cout<<sum-a[n-1];
  }
  if(!t)
    cout<<sum;
  return 0;
}


Measured memory_bytes: 256
eval'N,A,B='+`dd`.split*?,
A*=t=(A+B).pow -2+s=M=10**9+7,M
B*=t
a=A.pow N,M
b=B.pow N,M
[g=1,*(1...N).map{g=g*_1%M}].map{s+=_1.pow(M-2,M)*(a+b)*100*t=t*N%M
N+=1
a=a*B%M
b=b*A%M}
p s%M

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	lint a,v,b,w,t; cin>>a>>v>>b>>w>>t;
	puts(abs(a-b)<=(v-w)*t?"YES":"NO");
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
int main(void){
    char S[1000000];
    int a,b,c,cou;

    scanf("%s",S);
    a=strlen(S);
    for(int i=0;i<a;i++){
        if(S[i]==S[i+1]){
            if(S[i]=='0'){
                S[i+1]='1';
            }else{
                S[i+1]='0';
            }
            cou++;
        }
    }

    printf("%d",cou);

    return 0;
}

Measured memory_bytes: 256
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]

a_b=[]
x=0
for a,b in ab:
    a_b.append(a+b)
    x-=b
a_b.sort(reverse=True)
ans=0
for i in range(0,n,2):
    ans+=a_b[i]

print(ans+x)

Measured memory_bytes: 31876
package main

import (
	"fmt"
	"math"
)

var N, M, ans int
var k, p []int
var s [][]int

func main() {

	fmt.Scan(&N, &M)

	k = make([]int, M)
	s = make([][]int, M)
	p = make([]int, M)

	for i := 0; i < M; i++ {
		fmt.Scan(&k[i])
		s[i] = make([]int, k[i])

		for j := 0; j < k[i]; j++ {
			fmt.Scan(&s[i][j])
		}
	}
	for i := 0; i < M; i++ {
		fmt.Scan(&p[i])
	}

	dfs(0, []int{})
	fmt.Println(ans)
}

func dfs(n int, comb []int) {
	if n == N {
		calc(comb)
		return
	} else {
		for i := 0; i <= 1; i++ {
			dfs(n+1, append(comb, i))
		}
	}
}

func calc(comb []int) {
	var cnt_l int

	// 電球
	for i := 0; i < M; i++ {
		var cnt_s int

		// スイッチ
		for j := 0; j < k[i]; j++ {
			if comb[s[i][j]-1] == 1 {
				cnt_s++
			}
		}
		if cnt_s%2 == p[i] {
			cnt_l++
		}
	}
	if cnt_l == M {
		ans++
	}
	return
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }


Measured memory_bytes: 640