akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N, K;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  vector<pair<int, int> > v;
  map<int, int> mp;
  set<int> st;
  int res = 0;
  for(int i=0; i<N; ++i){
    int x; cin >> x;
    st.insert(x);
    ++mp[x];
  }
  auto it = mp.begin();
  while(it != mp.end()){
    v.push_back({it->first, it->second});
    ++it;
  }
  sort(all(v), [&](const pair<int, int> a, const pair<int, int> b){
         return a.second < b.second;
      });
  int p = st.size(), id = 0;
  while(p > K && id < (int)v.size()){
    res += v[id].second;
    --p;
    ++id; 
  }
  cout << res << "\n";
  return 0;  
}



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

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define f_in freopen("test.in","r",stdin);
#define f_out freopen("test.in","w",stdout);
#define debug(x) cerr << #x << " : " << x << "\n";
#define _ cin.sync_with_stdio(0); cin.tie(0);
#define tl cout <<"\nTime elapsed: "<<(1000 * clock() / CLOCKS_PER_SEC)<<"ms\n"


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

inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

template<typename T = int>
inline T nxt(){
    char c=nc();T x=0; int f=1;
    for(;c>'9'||c<'0';c=nc())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc()); x*=f;
    return x;
}

const int N = 100010;
int x[N];
bool vis[N], ans;
vector<vector<pii> > G;

void dfs(int u, int d){
    vis[u] = true;
    x[u] = d;
    trav(v, G[u]){
        if(!vis[v.F]) dfs(v.F, d + v.S);
        else if(x[v.F] - x[u] != v.S) ans = false;
    }
}

int main(){
    int n = nxt(), m = nxt();
    G.resize(n);
    rep(i,0,m){
        int u = nxt(), v = nxt(), d = nxt();
        u--, v--;
        G[u].push_back({v, d});
        G[v].push_back({u, -d});
    }
    memset(vis, 0 ,sizeof vis);
    memset(x, 0, sizeof x);
    ans = true;
    rep(i,0, n){
        if(!vis[i]) dfs(i, 0);
    }
    cout << (ans ? "Yes\n" : "No\n");
}


Measured memory_bytes: 12160
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] x = new int[n];
			int[] y = new int[n];
			boolean[][] map = new boolean[5001][5001];
			for(int i=0;i<n;i++){
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				map[y[i]][x[i]] = true;
			}
			
			int max = 0;
			int p, q, a, b, c, d;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					p = x[i] - x[j];
					q = y[i] - y[j];
					a = y[i] + p;
					b = x[i] - q;
					c = y[j] + p;
					d = x[j] - q;
					
					for(int k=0;k<2;k++){
						if(0<=a && a<=5000 && 0<=b && b<=5000 && 0<=c && c<=5000 && 0<=d && d<=5000){
							if(map[a][b]==true && map[c][d]==true){
								max = Math.max(max, p*p + q*q);
								break;
							}
						}
						a -= 2*p;
						b += 2*q;
						c -= 2*p;
						d += 2*q;
					}
				}
			}
			System.out.println(max);
		}	
	}	
}

Measured memory_bytes: 128356
#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            final int y = in.nextInt();
            final int z = in.nextInt();
            x -= z;
            int ans = x / (y + z);
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21844
#include<stdio.h>

int main(void)
{
	int a,b;
	
	
	scanf("%d%d", &a,&b);
	
	if(a > b){
		printf("a > b\n");
		
	}else if(a < b){
		printf("a < b\n");
		
	}else{
		printf("a == b\n");
	}
	
	return 0;
}


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

int main() {
  int m, f, b;
  cin >> m >> f >> b;
  if (m + f < b) cout << "NA\n";
  else {
    if (m >= b) cout << "0\n";
    else cout << b - m << "\n";
  }
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
    
typedef long long ll;

void calc(string s, int index[]){

    for(int i = 0; i < s.size(); i++){
        index[s[i] - 'a'] = 1;
    }

    int cnt = 0;
    for(int i = 0; i < 26; i++){
        if(index[i]) cnt ++;
    }
}

int calc2(int index1[], int index2[]){

    int cnt = 0;
    for(int i = 0; i < 26; i++){
        if(index1[i] && index2[i]) cnt ++;
    }
    return cnt;
}


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

    int m = 0;
    for(int i = 1; i < s.size()-1; i++){
        string left = s.substr(0, i);
        string right = s.substr(i, s.size()-i);
        int indL[26] = {0};
        int indR[26] = {0};
        calc(left,indL);
        calc(right,indR);
        m = max(m, calc2(indL, indR) );

    }
    cout << m << endl;
}

Measured memory_bytes: 256
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))

to_zero = 0
to_N = 0
for A_i in A:
    if A_i < X:
        to_zero += 1
    elif N > A_i > X:
        to_N += 1
print(min(to_zero, to_N))

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i, a, n) for(int i=(a);i<(n);++i)
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string s;cin>>s;
  for(int i=s.size()-2;i;i-=2){
    s.pop_back();
    s.pop_back();
    //cout<<"s1: "<<s.substr(0, s.size()/2)<<" s2: "<<s.substr(s.size()/2)<<endl;
    if(s.substr(0, s.size()/2)==s.substr(s.size()/2)){
      cout<<s.size()<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)


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

# Y,P,i
Cities = []

for i in range(M):
	P, Y = list(map(int, input().split(' ')))
	Cities.append([Y,P,i])

Cities.sort()
PsCount = {}

# i, P, junban
ans = []

for c in Cities:
	if c[1] in PsCount:
		PsCount[c[1]] += 1
		ans.append([c[2], c[1], PsCount[c[1]]])
	else:
		PsCount[c[1]] = 1
		ans.append([c[2], c[1], 1])

ans.sort()


for elem in ans:
	print(str(elem[1]).zfill(6)+str(elem[2]).zfill(6))

Measured memory_bytes: 41792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


int main(){
  string s;
  cin >> s;
  vector<bool> d(26, true);
  rep(i, s.size()){
    int n = s[i] - 'a';
    d[n] = false;
  }
  rep(i, 26) {
    if (d[i]){
      char ans = i + 'a';
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None\n";

} 

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int n,a[100];

  cin >> n;

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

  for(int l = n-1; l >= 0;l--){
    if(l == 0) {
      cout << a[l];
    }
   else cout << a[l] << " ";
  }
  cout << endl;
  return 0;
    }

Measured memory_bytes: 1160
#include <iostream>
#include<string>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = a;
    if(b>max) max=b;
    if(c>max) max=c;
    printf("%d\n", a+b+c-max);

    return 0;
}

Measured memory_bytes: 256
n = int(input())
if n <= 111:
    print(111)
elif n<=222:
    print(222)
elif n<=333:
    print(333)
elif n<=444:
    print(444)
elif n<=555:
    print(555)
elif n<=666:
    print(666)
elif n<=777:
    print(777)
elif n<=888:
    print(888)
else:
    print(999)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int debt = 100000;
	for(int i = 0; i < n; i++){
		debt *= 1.05;
		debt += 999;
		debt /= 1000;
		debt *= 1000;
	}
	cout << debt << endl;
	return 0;
}

Measured memory_bytes: 1160
N, M, C = map(int, input().split())
B=list(map(int, input().split()))
answer=0
for i in range(N):
  A=list(map(int, input().split()))
  sum=C
  for j in range(M):
    sum+=B[j]*A[j]
  if sum>0:
    answer+=1
print(answer)

Measured memory_bytes: 3060
using System;
using System.Linq;
class _0060 {
	public static void Main() {
		string str;
		while((str = Console.ReadLine()) != null) {
			var vs = str.Split().Take(3).Select(s => byte.Parse(s)).ToArray();
			var uc = (new byte[10]).Select(v => 1).ToArray();
			uc[vs[0] - 1] = uc[vs[1] - 1] = uc[vs[2] - 1] = 0;
			Console.WriteLine(((double)(uc.Take((20 - vs[0] - vs[1] > 10) ? 10 : 20 - vs[0] - vs[1]).Sum()) / 7.0 < 0.5) ? "NO" : "YES");
		}
	}
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

#define MXNK 2020202

ll N,K,NK;
char S[1010101];
ll Fa[MXNK+10],iFa[MXNK+10];
ll p26[MXNK + 10], p25[MXNK + 10];
ll ans;
ll i, j, k;



void init(){
    ll i;
    Fa[0] = p26[0] = p25[0] = 1;
    rep(i,0,MXNK){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
        p26[i + 1] = p26[i] * 26 % MOD;
        p25[i + 1] = p25[i] * 25 % MOD;
    }
    iFa[i] = moddiv(1, Fa[i]);
    for (i; i > 0;--i){
        iFa[i - 1] = iFa[i] * i % MOD;
    }
}
ll C(ll a,ll b){
    if(a<b)
        return 0;
    return Fa[a] * iFa[a - b] % MOD * iFa[b] % MOD;
}


int main(){
    scanf("%lld%s", &K,S);
    N = strlen(S);
    init();

    rep(i,0,K+1){
        ll b = K - i;
        (ans += C(b + N - 1, N - 1) * p25[b] % MOD * p26[i]) %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 67808
#include <cstdio>
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <tuple>
#include <string>

using namespace std;

#define MAX(A, B)	((A) > (B) ? (A) : (B))
#define MIN(A, B)	((A) < (B) ? (A) : (B))

int main(int argc, char const *argv[]) {
	int64_t n, k;
	cin >> n >> k;

	vector<tuple<int64_t, int64_t>> v;

	for (int64_t i = 0; i < n; ++i) {
		int64_t a, b;
		cin >> a >> b;
		v.push_back(make_tuple(a, b));
	}

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

	for (int64_t i = 0; i < n; ++i) {
		int a = get<0>(v[i]), b = get<1>(v[i]);
		k -= b;
		if (k <= 0) {
			cout << a << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <math.h>

main(){
  double datax=0.0, datay=0.0, d=0.0, s, n, pi=3.1415926535;

  while(1){
    scanf("%lf,%lf", &n, &s);
    if(n==0.0 && s==0.0) break;
    datay= datay + n*cos(d/180.0*pi);
    datax= datax + n*sin(d/180.0*pi);
    d+=s;
    if(d>180){
      d-=360.0;
    }
    else if(d<=-180){
      d+=360.0;	
    }
  }
  printf("%d\n%d\n", (int)datax, (int)datay);
  return 0;
}

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

int main() {

  int *a;
  int i, j,k;
  int n;
  int v;

  /* 確保する要素数をscan */
  scanf("%d", &n);

  a = (int *)malloc(n * sizeof(int)); //メモリ領域の確保

  for (i=0; i<n; i++)
    scanf("%d", &a[i]);


  for (i=0; i<n; i++) {
    if(i != n-1 )printf("%d ", a[i]);
    else if(i == n-1 ) printf("%d", a[i]);

  }
      printf("\n");
  
  
  /* sort */
  for (i=1; i<n; i++) {
    v = a[i];
    j = i-1;

    while(j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }

    a[j+1] = v;

    for (k=0; k<n; k++) {
      if(k != n-1) printf("%d ", a[k]);
      else if(k == n-1) printf("%d", a[k]);
    }
    printf("\n");
  }

    
  free(a);
  return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll f(vector<pii> p){
    int n = p.size();
    rep(i,n) p[i].first = min(p[i].first ,n);
    vector<vector<int>>  s(n+1);
    rep(i,n) s[p[i].first].push_back(p[i].second);

    ll res = 0;
    priority_queue<int> q;
    for(int i = n;i >= 1; --i){
        for(int x: s[i])q.push(x);
        if(q.size() > 0){
            res += q.top();
            q.pop();
        }
    }
    return res;
}


void solve(){
    int n;
    cin >> n;
    vector<pii> pl,pr;
    ll ans = 0;
    rep(i,n){
        int k,l,r;
        cin >> k >> l >> r;
        int m = min(l,r);
        ans += m;
        l -= m;r -= m;
        if(l > 0) pl.emplace_back(k,l);
        else pr.emplace_back(n-k,r);
    }
    ans += f(pl);
    ans += f(pr);
    cout << ans << endl;
}

int main(){
    int ts;
    cin >> ts;
    rep(i,ts) solve();
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	
	int A=stoi(s.substr(0,2));
	int B=stoi(s.substr(2,2));
	bool flagA=true;
	bool flagB=true;
	
	if(A>12 || A<1) flagA=false;
	if(B>12 || B<1) flagB=false;
	
	if(flagA && flagB) cout << "AMBIGUOUS" << endl;
	else if(flagA && flagB == false) cout << "MMYY" << endl;
	else if(flagA == false && flagB) cout << "YYMM" << endl;
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] arr = new int[n+1];
      for(int i = 1; i <= n; i++)
        arr[i] = sc.nextInt();

      int[] res = new int[n+1];

      int m = 0;
      for(int i = n; i >= 1; i--) {
        int cnt = cntSum(res, i);
        if(cnt % 2 != arr[i]) {
          m++;
          res[i] = 1;
        }
      }
      
      System.out.println(m);
      
      StringBuilder sb = new StringBuilder();
      for(int i = 1; i <= n; i++) {
        if(res[i] == 0) continue;
        sb.append(i + " ");
      }
      if(sb.length() > 0)
        System.out.println(sb.toString().substring(0, sb.length() - 1));
  }

  private static int cntSum(int[] res, int n) {
    int sum = 0;
    for(int i = n * 2; i < res.length; i += n)
      sum += res[i];
    return sum;
  }
}


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

int main() 
{
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << a * b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;

int main()
{

    #ifdef fisier
        ifstream cin("input.in");
        ofstream cout("output.out");
    #endif

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

	string a, b;
	cin >> a >> b;
	if(b.size() - a.size() != 1)
		cout << "No";
	else
	{
		a += b.back();
		if(a == b)
			cout << "Yes";
		else
			cout << "No";
	}
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  int A, B;
  cin >> A >> B;
  
  cout << (A-1)*(B-1) << endl;
  
}

Measured memory_bytes: 256
using System;
using System.Linq;
class P
{
    static void Main(string[] args)
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sx = a[0]; int sy = a[1];int tx = a[2];int ty = a[3];
        for (int i = 0; i < ty - sy; i++) { Console.Write("U"); }
        for (int i = 0; i < tx - sx; i++) { Console.Write("R"); }
        for (int i = 0; i < ty - sy; i++) { Console.Write("D"); }
        for (int i = 0; i < tx - sx; i++) { Console.Write("L"); }
        Console.Write("L");
        for (int i = 0; i < ty - sy + 1; i++) { Console.Write("U"); }
        for (int i = 0; i < tx - sx + 1; i++) { Console.Write("R"); }
        Console.Write("DR");

        for (int i = 0; i < ty - sy + 1; i++) { Console.Write("D"); }

        for (int i = 0; i < tx - sx + 1; i++) { Console.Write("L"); }
        Console.Write("U");
       
   
    
        Console.ReadLine();
    }
}

//UURDDLUUURRDRDDDLLU
//UURDDLLUUURRDRDDDLLU



Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>


typedef long long ll;


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

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

using namespace std;







int main()
{
	int a, b; cin >> a >> b;
	cout << a * b << endl;
}




Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
	
public class Main {
	
	public static ArrayList<Integer>[]graph;
	
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		
		graph=new ArrayList[N];
		
		for(int i=0;i<N;i++){
			graph[i]=new ArrayList<>();
		}
		
		for(int i=1;i<N;i++){
			int a=sc.nextInt();
			graph[a-1].add(i);
		}
		//グラフは完成
		System.out.println(dfs(0)-1);
		
	}
	private static int dfs(int v){
		if(graph[v].isEmpty())return 1;
		
		int[] temp=new int[graph[v].size()];
		for(int i=0;i<temp.length;i++){
			int u=graph[v].get(i);
			temp[i]=dfs(u);
		}
		Arrays.sort(temp);
		int max=0;
		for(int t:temp){
			if(t<=max){
				t++;
			}
			else{
				max=t;
			}
			max++;
		}
		return max;
	}
}


Measured memory_bytes: 70968
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;

int main() {
  	int n;
  	cin >> n;
  	vector<ll> nums(n);
  	for(int i = 0; i < n; i++) {
  		cin >> nums[i];
  	}
  	sort(nums.begin(), nums.end());
  	ll total_count = 0; 
  	for(int i = 0; i < n - 2; i++) {
  		int j = i + 1;
  		while(j < n && nums[j] == nums[i]) {
  			j++;
  		}
  		int k;
  		for(; j < n - 1; j++) {
  			k = n - 1;
	  		int j_last = j;
	  		while(j_last < n - 1 && nums[j_last] == nums[j_last + 1]) {
	  			j_last++;
	  		}
	  		ll sum = nums[i] + nums[j];
	  		while(k > j_last && sum <= nums[k]) {
	  			k--;
	  		}
	  		total_count += (k - j_last);
	  	}
  	}
  	cout << total_count;
	return 0;
}

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

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int n, l ;
  cin >> n >> l ;
  int sum = 0 ;
  
  vector<int> vec(n) ;
  vector<int> vecvec(n) ;
  
  rep(i, n){
    vec.at(i) = l+i ;
  }
  
  rep(i, n){
    sum += vec.at(i)  ;
  }
  
  sort(all(vec)) ;
  
  if(vec.at(0)>0){
    cout << sum- vec.at(0)<<endl ;
  }
  else if(vec.at(n-1)<0){
    cout << sum - vec.at(n-1)<<endl ;
  }
  else{
    cout << sum << endl ;
  }
    return 0 ;
}




Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
ans = 0
c_odd = Counter(v_odd)
c_even = Counter(v_even)
v_o, c_o = zip(*c_odd.most_common())
v_e, c_e = zip(*c_even.most_common())
if len(c_o) == 1:
    odd1 = 0
else:
    odd1 = c_o[1]
if len(c_e) == 1:
    even1 = 0
else:
    even1 = c_e[1]
if not v_o[0] == v_e[0]:
    print(sum(c_o) - c_o[0] + sum(c_e) - c_e[0])
else:
    ans = min(sum(c_o) - c_o[0] + sum(c_e) - even1, sum(c_o) - odd1 + sum(c_e) - c_e[0])
    print(ans)


Measured memory_bytes: 22672
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		
		int n; cin >> n;
		if (n == 0) break;
		
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];
		}
		
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for (int j = i; j < n; j++) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					check[idx] -= str[j].size();
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++) {
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

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

Measured memory_bytes: 3152
n,m = map(int,input().split())
edge = []
bridge = []
for i in range(n+1):
    edge.append([])
for i in range(m):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
    bridge.append((a,b))

def dfs(start, st, go):
    stack = [start]
    used = set()
    used.add(start)
    while stack:
        here = stack.pop()
        for i in edge[here]:
            if here == st and i == go:
                pass
            elif i == st and here == go:
                pass
            elif i not in used:
                stack.append(i)
                used.add(i)
    return used

ans = 0
for i in range(m):
    tar = bridge[i]
    used = dfs(1, tar[0], tar[1])
    if len(used) != n:
        ans += 1
print(ans)




Measured memory_bytes: 39280
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;

ll c[710],f[710];

inline ll C(int x,int y){
	long double ret=1;
	for(int i=1;i<=x-y;i++) ret=ret*(i+y)/i;
	return (ll)(ret+0.1);
}

int main(){
	ll k;
	cin>>k;
	for(int i=1;i<=700;i++) f[i]=C(i+6,7);
	for(int i=700;i;i--)
		c[i]=k/f[i],k%=f[i];
	int t=700;
	while(!c[t]) t--;
	for(int i=t;i;i--)
		cout<<string(c[i],'F')<<"ESTIVAL";
	return 0;
}

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

using ll=long long;
using P=pair<int,int>;
#define int long long

const int MOD=1e9+7;
const int INF=1<<30;
const int MAX=1e5;

int n;

template<class T>
inline void xmin(T &a, T b){a=(a<b)?a:b;}
template<class T>
inline void xmax(T &a, T b){a=(a>b)?a:b;}

int a[200000];
int f[200000];

template<class T>
T vmax(T a, T b){
    if(a>b)return a;
    else return b;
}

int k;

bool isOK(int mid){
    int temp=0;
    for(int i=0; i<n; i++){
        temp+=vmax(0LL,((a[i]*f[n-1-i]-mid)+f[n-1-i]-1)/f[n-1-i]);
    }
    return temp<=k;
}

int bins(int ok=1e18, int ng=-1){
    while(abs(ng-ok)>1){
        int mid=(ok+ng)/2;
        if(isOK(mid))ok=mid;
        else ng=mid;
    }
    return ok;
}

void solve(){
    cin>>n>>k;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        cin>>f[i];
    }
    sort(a,a+n);
    sort(f,f+n);
    int ans=bins();
    cout<<ans<<endl;
}

signed main(){
    //while(1)
    solve();
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N=int(input())

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

def func1(x, xi):
    if x % xi == 0:
        return x
    else:
        return xi * (x // xi) + xi

for i in range(N):
    ti,ai = map(int,input().split())
    if i == 0:
        t,a = ti,ai
    else:
        t,a = func1(t, ti),func1(a, ai)

        # a is short
        if ti / ai < t / a:
            a = t // ti * ai
        else:
            t = a // ai * ti

    # print("t,a=",t,a)
print(a+t)



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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> inline istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> inline ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

template<typename T> inline T min(vector<T>& v) {return *min_element(v.begin(), v.end());}

template<typename T> inline T max(vector<T>& v) {return *max_element(v.begin(), v.end());}

template<typename T> inline void sort(vector<T>& v) {sort(v.begin(), v.end());}

template<typename T, typename Function> inline void sort(vector<T>& v, Function func) {sort(v.begin(), v.end(), func);}

template<typename T> inline void rsort(vector<T>& v) {sort(v.rbegin(), v.rend());}

template<typename T> inline void reverse(vector<T>& v) {reverse(v.begin(), v.end());}

template<typename T> inline void unique(vector<T>& v) {v.erase(unique(v.begin(), v.end()), v.end());}

template<typename T> inline void nth_element(vector<T>& v, int n) {nth_element(v.begin(), v.begin() + n, v.end());}

template<typename T> inline bool next_permutation(vector<T>& v) {return next_permutation(v.begin(), v.end());}

template<typename T> inline int find(vector<T>& v, T t) {return find(v.begin(), v.end(), t) - v.begin();}

template<typename T> inline int in(vector<T> v, T t) {return find(v, t) != (int)v.size();}

template<typename T> inline int lower_bound(vector<T>& v, T t) {return lower_bound(v.begin(), v.end(), t) - v.begin();}

template<typename T> inline int upper_bound(vector<T>& v, T t) {return upper_bound(v.begin(), v.end(), t) - v.begin();}

template<typename T> inline T accumulate(const vector<T>& v, function<T(T, T)> func = plus<T>()) {return accumulate(v.begin(), v.end(), T(0), func);}

template<typename T> inline void adjacent_difference(vector<T>& v) {adjacent_difference(v.begin(), v.end(), v.begin());}

template<typename T> inline void adjacent_difference(vector<T>& v, vector<T>& u) {adjacent_difference(v.begin(), v.end(), u.begin());}

template<typename T> inline void partial_sum(vector<T>& v, vector<T>& u) {partial_sum(v.begin(), v.end(), u.begin());}

template<typename T> inline T inner_product(vector<T>& v, vector<T>& u) {return inner_product(v.begin(), v.end(), u.begin(), T(0));}

template<typename T, typename Function> inline int count_if(vector<T> v, Function func) {return count_if(v.begin(), v.end(), func);}

template<typename T, typename Function> inline void remove_if(vector<T>& v, Function func) {v.erase(remove_if(v.begin(), v.end(), func), v.end());}

template<typename T, typename Function> inline bool any_of(vector<T> v, Function func) {return any_of(v.begin(), v.end(), func);}

template<typename T> inline vector<T> subvector(vector<T>& v, int a, int b) {return vector<T>(v.begin() + a, v.begin() + b);}

int main() {
  int n, res = 0;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  for (int i = 0; i < n; ++i) {
    if (a[a[i] - 1] - 1 == i) ++res;
  }
  cout << res / 2 << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int a[216000], n, k;
Int f(Int x){
  Int res = 0;
  for(int i = 0;i < n;i++)res += x ^ a[i];
  return res;
}
Int greedy[47];
int main(){
  cin >> n >> k;
  for(int i = 0;i < n;i++)cin >> a[i];
  for(int j = 0;j < 45;j++){
    greedy[j+1] = greedy[j];
    if(f(greedy[j+1]) < f(greedy[j+1] + (1LL << j)))
      greedy[j+1] += 1LL << j;
  }
  Int res = f(0);
  Int p = 0;
  Int tk = k;
  while(true){
    while(p+1 < 45 && tk + greedy[p+1] <= k)p++;
    res = max(res, f(tk+greedy[p]));
	if(tk == 0)break;
    tk -= tk & -tk;
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int main(void){
	int x,a,b,c;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int s=0;
	reg(i,0,a)reg(j,0,b)reg(k,0,c){
		if(i*500+j*100+k*50==x)s++;
	}
	printf("%d\n",s);
	return 0;
}






Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <string.h>         // memset()
#include <stdbool.h>

#define MAX_N (100 * 100)
#define MAX_V 1001

typedef struct doll_tbl
{
	int h;
	int r;
} doll_t;

int N;
doll_t size1[MAX_N];
doll_t size2[MAX_N];
int dp[MAX_V][MAX_V];

int
cmp_func1(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->h < r->h)
		return 1;

	if (l->h > r->h)
		return -1;

	if (l->r < r->r)
		return 1;

	if (l->r > r->r)
		return -1;

	return 0;
}

int
cmp_func2(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->r < r->r)
		return 1;

	if (l->r > r->r)
		return -1;

	if (l->h < r->h)
		return 1;

	if (l->h > r->h)
		return -1;

	return 0;
}

int
dfs(int lh, int lr)
{
	int h1, r1;
	int h2, r2;
	int i;

	if (dp[lh][lr] != -1)
		return dp[lh][lr];

	for (i = 0; i < N; ++i)
	{
		if (size1[i].h < lh && size1[i].r < lr)
		{
			h1 = size1[i].h;
			r1 = size1[i].r;
			break;
		}
	}

	int a = 0;
	if (i < N)
		a = dfs(h1, r1) + 1;

	for (i = 0; i < N; ++i)
	{
		if (size2[i].h < lh && size2[i].r < lr)
		{
			h2 = size2[i].h;
			r2 = size2[i].r;
			break;
		}
	}

	int b = 0;
	if (i < N)
		b = dfs(h2, r2) + 1;

	dp[lh][lr] = (a > b) ? a : b;
	return dp[lh][lr];
}

int
solve()
{
	for (int i = 0; i < N; ++i)
		size2[i] = size1[i];

	qsort(size1, N, sizeof(doll_t), cmp_func1);
	qsort(size2, N, sizeof(doll_t), cmp_func2);

	memset(dp, 0xff, sizeof(dp));
	return dfs(1000, 1000);
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n, m;
		scanf("%d", &n);
		if (n == 0)
			break;

		N = 0;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d%d", &size1[N].h, &size1[N].r);
			N++;
		}

		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
		{
			scanf("%d%d", &size1[N].h, &size1[N].r);
			N++;
		}

		printf("%d\n", solve());
	}

	return 0;
}


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf = 1e9;
const int MAX = 1e5+5;
const ll MOD = 1e9+7;
#define REP(i, n) for (int i = 0; i < (n); ++i)

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, m; cin >> n >> m;
    int tmp;
    int vec_tmp;
    vector<vector<int>> s(m);
    REP(i, m){
        cin >> tmp;
        REP(j, tmp){
            cin >> vec_tmp;
            s[i].push_back(vec_tmp);
        }
    }
    vector<int> p;
    REP(i, m){
        cin >> tmp;
        p.push_back(tmp);
    }
    int ans = 0;
    int tmp_ans = 0;
    bool all_on;
    // bit全探索
    for(int bit=0; bit<(1<<n); bit++){
        vector<int> S(n, 0);
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                S[i] = 1;
            }
        }
        all_on = true;
        for(int i=0; i<m; i++){
            tmp_ans = 0;
            for(int j=0; j<s[i].size(); j++){
                if(S[s[i][j]-1] == 1) tmp_ans++;
            }
            if(tmp_ans%2!=p[i]) all_on = false;
        }
        if(all_on) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!(
       s: chars,
    );

    if s[0] == s[1] && s[2] == s[3] && s[1] != s[2] {
        println!("Yes");
    } else if s[0] == s[2] && s[1] == s[3] && s[0] != s[1] {
        println!("Yes");
    } else if s[0] == s[3] && s[1] == s[2] && s[0] != s[1] {
        println!("Yes");
    } else {
        println!("No");
    }

}

Measured memory_bytes: 4352
N, M = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(M)]
wf = [[[2000 for _ in range(N + 10)] for _ in range(N + 10)] for _ in range(N + 10)]
for i in range(N):
    for j in range(N):
        wf[i][j][j] = 0
for item in edge:
    a, b, c = item
    wf[0][a - 1][b - 1] = c
    wf[0][b - 1][a - 1] = c

for i in range(N):
    for j in range(N):
        for k in range(N):
            wf[i + 1][j][k] = min(wf[i][j][k], wf[i][j][i] + wf[i][i][k])

ans = 0
for item in edge:
    a, b, c = item
    if c > wf[N][a - 1][b - 1]:
        ans += 1

print(ans)

Measured memory_bytes: 18036
SA = input()
SB = input()
SC = input()

now = 'a'

for i in range(310):
    if now == 'a':
        if len(SA) == 0:
            print('A')
            break
        else:
            now = SA[0]
            SA = SA[1:]

    if now == 'b':
        if len(SB) == 0:
            print('B')
            break
        else:
            now = SB[0]
            SB = SB[1:]

    if now == 'c':
        if len(SC) == 0:
            print('C')
            break
        else:
            now = SC[0]
            SC = SC[1:]


Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Node{
        vector<int> inEdges, outEdges;
        vector<int>& edges(bool rev = false){ return rev ? inEdges : outEdges; }
    };
    struct Edge{
        int from, dest;
        ll limit, rem;
        Edge(){ }
        Edge(int from, int dest, ll limit = 1): from(from), dest(dest), limit(limit), rem(limit){ }
        int to(bool rev = false){ return rev ? from : dest; }
        ll remain(bool rev = false){ return rev ? limit - rem : rem; }
        void pour(ll qua, bool rev = false){ rem -= rev ? - qua : qua; }
    };
    vector<Node> nodes;
    vector<Edge> edges;
    Graph(int nn, int en = 10): nodes(nn){
        edges.reserve(en);
    }

    void addEdge(int from, int dest, ll limit){
        nodes[from].outEdges.emplace_back(edges.size());
        nodes[dest].inEdges.emplace_back(edges.size());
        edges.emplace_back(from, dest, limit);
    }
    ll flow(int start, int goal, vector<char>& visited, ll cur){
        if(start == goal){ return cur; }
        auto _flow = [&](bool rev = false){
            for(int eidx : nodes[start].edges(rev)){
                Edge& e = edges[eidx];
                int vidx = e.to(rev);
                if(!e.remain(rev) || visited[vidx]){ continue; }
                visited[vidx] = true;
                ll lim = min(cur, e.remain(rev));
                if((lim = flow(vidx, goal, visited, lim))){
                    e.pour(lim, rev);
                    return lim;
                }
            }
            return 0ll;
        };
        ll ret = _flow();
        return ret ? ret : _flow(true);
    }
    ll maxFlow(int start, int goal){
        if(start == goal){ exit(1); }
        ll ret = 0;
        while(1){
            ll prev = ret;
            vector<char> visited(nodes.size());
            ret += flow(start, goal, visited, MLL);
            if(ret == prev){ break; }
        }
        return ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n + 2, 2 * n);
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        int a; cin >> a;
        if(a > 0){
            sum += a;
            g.addEdge(i, n + 1, a);
        }else{
            g.addEdge(0, i, - a);
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + i; j <= n; j += i){
            g.addEdge(i, j, MLL);
        }
    }
    ll mi = g.maxFlow(0, n + 1);
    cout << sum - mi << '\n';
}


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

using namespace std;

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

    int A, B;
    cin >> A >> B;
    set<int> s{1, 2, 3};
    s.erase(A);
    s.erase(B);
    cout << *s.begin() << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		for (int i=0;i<(S.length()-1)/2;i++) {
			if (S.charAt(i)!=S.charAt(S.length()-1-i)||S.charAt(i)!=S.charAt(S.length()-1-i)) {
				System.out.println("No");
				return ;
			}
		}
		for (int i=(S.length()+3)/2-1;i<S.length();i++) {
			if (S.charAt(i)!=S.charAt(S.length()-1-i+(S.length()+3)/2-1)) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}

}


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

int main(){
    int a,b;
    cin >> a>> b;
    int ans;
    if (abs(a-b)>=2){
        ans = 2*max(a,b)-1;}
    else ans = a+b;

    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 2019;
int INF = (int)2e18;

signed main() {
    int A, B;
    cin >> A >> B;
    int ans = max(A, B) - min(A, B);
    if (ans % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << ans / 2 + min(A, B) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double llf;
int main()
{
    ll a,b,x,aa,bb;
    cin>>a>>b>>x;
    aa=a/x;
    if(a%x!=0)
    {
        aa++;
    }
    bb=b/x;
    if(aa>bb)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<bb-aa+1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int m,n,a[111][111];
int h,Y[30],X[30];
int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};

map<int,int> M;

int f(int cur,int mask){
	if(__builtin_popcount(mask)<=h/2){
		if(M.find(cur<<24|mask)!=M.end())return M[cur<<24|mask];
	}
	int res=0;
	rep(d,4){
		int y=Y[cur],x=X[cur];
		while(1){
			y+=dy[d];
			x+=dx[d];
			if(y<0 || y>=n || x<0 || x>=m)break;
			if(a[y][x]==0){
				if(mask==(1<<h)-2)res++;
			}
			if(a[y][x]>=1){
				if((mask>>a[y][x]&1)==0){
					res+=f(a[y][x],mask|1<<a[y][x]);
					break;
				}
			}
		}
	}
	if(__builtin_popcount(mask)<=h/2){
		M[cur<<24|mask]=res;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	while(cin>>m>>n && m){
		M.clear();
		h=1;
		rep(i,n)rep(j,m){
			cin>>a[i][j];
			if(a[i][j]==0){
				a[i][j]=-1;
			}
			else if(a[i][j]==1){
				Y[h]=i,X[h]=j;
				a[i][j]=h++;
			}
			else{
				Y[0]=i,X[0]=j;
				a[i][j]=0;
			}
		}
		cout<<f(0,0)<<endl;
	}
}

Measured memory_bytes: 7448
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int h[100009];
int main(){
	int n;
	long long int a,b;
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	long long int sa=a-b;
	long long int mi=0,ma=1000000000,mid;
	while(ma-mi>1){
		mid=(mi+ma)/2;
		long long int cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>b*mid){
				cnt+=(h[i]-b*mid-1)/sa +1;
			}
		}
		if(cnt>mid){
			mi=mid;
		}
		else{
			ma=mid;
		}
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 640
#line 1 "test/DPL_5_A.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_5_A"
#line 1 "macro/macros.hpp"



#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";


#line 1 "math/mint.hpp"



#line 5 "math/mint.hpp"

struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};

#line 4 "test/DPL_5_A.test.cpp"

int main(){
    int n, x;
    cin >> n >> x;
    cout << mint(x).modpow(n) << endl;
}



Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>
 
using namespace std;
 
typedef long long int lld;
 
const lld mod = 1e9+7;
const lld INF = 1e9;
 
int main()
{
	lld h,w;
	char a[100][100];
 
	cin >> h >> w;
 
	for(int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}
 
	lld al[26] = {};
 
	for(int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			al[a[i][j] - 'a']++;
		}
	}
 
	lld x = min(h,w);
	lld y = max(h,w);  
 
	h = x;
	w = y;   
 
	if (h == 1 && w == 1)
	{
		cout << "Yes" << endl;
	}else
	{
		if (w % 2 == 1 && h % 2 == 1)
		{
			lld ev = 0;
 
			for(int i = 0; i < 26; i++)
			{
				if (al[i] >= 4)
				{
					ev += al[i] / 4;
					al[i] %= 4;
				}
			}
 
			if (ev <  ((w-1) / 2 ) * ((h-1) / 2) && h != 1)
			{
				cout << "No" << endl;
				return 0;
			}
 
			int odd = 0;
			for(int i = 0; i < 26; i++)
			{
				if (al[i] % 2 == 1)
				{
					odd++;
				}
			}
 
			if (odd != 1)
			{
				cout << "No" << endl;
			}else
			{
				cout << "Yes" << endl;
			}
		}else if(w % 2 == 1 || h % 2 == 1)
		{
 
			lld ev = 0;
 
			if (w %2 == 0)
			{
				ev = w;
			}else
			{
				ev = h;
			}
 
			for(int i = 0; i < 26; i++)
			{
				if (al[i] >= 4)
				{
					al[i] %= 4;
				}
			}
 
			int two = 0;
 
			for(int i = 0; i < 26; i++)
			{
				if (al[i] % 2 != 0)
				{
					cout << "No" << endl;
					break;
				}
				if (al[i] == 2)
				{
					two++;
					if (two > ev / 2)
					{
						cout << "No" << endl;
						break;
					}
 
				}
 
				if (i == 25)
				{
					cout << "Yes" << endl;
				}
			}
		}else
		{
			for(int i = 0; i < 26; i++)
			{
				if (al[i] >= 4)
				{
					al[i] %= 4;
				}
			}
 
			int red = 0;
			for(int i = 0; i < 26; i++)
			{
				if (al[i] > 0)
				{
					red++;
				}
			}
 
			if (red > 0)
			{
				cout << "No" << endl;
			}else
			{
				cout << "Yes" << endl;
			}
		}
	}
 
	return 0;
}

Measured memory_bytes: 256
N=int(input())
AB,time,memo=[],0,0
for _ in range(N):
    AB.append(list(map(int,input().split())))
AB.sort(key=lambda _:_[1])
for i in range(N):
    time+=AB[i][0]
    if time<=AB[i][1]:continue
    else:
        memo+=1
        break
if memo==0:print("Yes")
else:print("No")

Measured memory_bytes: 53720