akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
string a[10005];
int cnt;
int cnta,cntb;
int cntab;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i].length()-1;j++){
			if(a[i][j]=='A'&&a[i][j+1]=='B'){
				cnt++;
			}
		}
		if(a[i][0]=='B'){
			cntb++;
//			cout<<"B"<<endl;
		}
		if(a[i][a[i].length()-1]=='A'){
			cnta++;
		}
		if(a[i][0]=='B'&&a[i][a[i].length()-1]=='A'){
			cntab++;
		}
	}
	cnt+=min(cnta,cntb);
	if(cntab==cnta&&cntab==cntb&&cntab!=0){
		cnt--;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

// t <= Si + n*Fiを満たす最小のnを求め、s+n*fを返す
int func(int t, int s, int f) {
	int n = 0;
	while (s + f * n < t) n++;
	return s + f * n;
}

int main() {
	int N; cin >> N;
	int c[N - 1], s[N - 1], f[N - 1];

	
	for (int i = 0; i < N - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	

	for (int j = 0; j < N - 1; j++) {

		int t = 0;

		for (int i = j; i < N - 1; i++) {
			t = func(t, s[i], f[i]) + c[i]; // i+1番目の駅に着く時刻
		}

		cout << t << endl;
	}

	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
import queue

N, M = map(int,input().split(' '))
#AB=[]
Root=[]
Sign=[]

for i in range(N+1):
    Root.append([])
    Sign.append(0)
#print(Root)

for i in range(M):
    a,b = map(int,input().split(' '))
    #AB.append([a,b])
    Root[a].append(b)
    Root[b].append(a)

q = queue.Queue()
q.put(1)

while not q.empty():
    r = q.get()
    for nextR in Root[r]:
        if Sign[nextR] == 0:
            q.put(nextR)
            Sign[nextR]=r

if 0 in Sign[1:]:
    print('No')
else:
    print('Yes')
    for i in range(2,N+1):
        print(Sign[i])


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

int calc(string x)
{
    int result = 0;
    for (char i : x)
    {
        result += i - '0';
    }
    return result;
}

int main()
{
    vector<int> ans;

    while (true)
    {
        string x;
        cin >> x;
        if (x == "0")
        {
            break;
        }
        ans.push_back(calc(x));
    }

    for (int i : ans)
    {
        cout << i << endl;
    }
}


Measured memory_bytes: 3160
def make_divisors(n) -> list:
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N = int(input())
cnt = 0
for i in range(105, N+1, 2):
    if len(make_divisors(i)) == 8:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int num = 'a' - 'A';
    S[K - 1] += num;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int *A,n,i,j,count=0,flag;
  scanf("%d",&n);
  A=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  for(i=0;i<n;i++){
    for(j=1;j*j<A[i];j++){
      flag=0;
      if(0==A[i]%(j+1)){
	flag=1;
	break;
      }
    }
    if(2==A[i])
      count++;
    else if(flag==0)
      count++;
    else
      count=count;
  }
  printf("%d\n",count);
  free(A);
  return 0;
}

Measured memory_bytes: 628
using System;

class Program {
    static void Main(string[] args) {
        int d = int.Parse(Console.ReadLine()), count = 0;
        var a = Console.ReadLine();
        var b = Console.ReadLine();
        for (int i = 0; i < d; i++) {
            var c = b.Substring(0, i + 1);
            if (a.Contains(c)) {
                count++;
            }
        }
        Console.WriteLine(a.Length + b.Length - count);
    }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
from collections import defaultdict

n, s, q = int(input()), list(map(int, input().split())), int(input())
sm, f = sum(s), defaultdict(int)
for i in s: f[i] += 1
for _ in range(q):
    b, c = map(int, input().split())
    sm += (c - b) * f[b]
    f[c] += f.pop(b)
    print(sm)

Measured memory_bytes: 93868
n, @a, @b=gets.split.map(&:to_i)
@hp=[]
n.times{@hp << gets.to_i}

def check(t)
  _t=0
  @hp.each do |e|
    res=e-@b*t
    _t+=[0, (res+@a-@b-1)/(@a-@b)].max
  end
  _t<=t
end

l, u=0, (@hp.max+@b-1)/@b
while u-l>1
  m=(u+l)/2
  check(m) ? u=m : l=m
end

puts u


Measured memory_bytes: 2996
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll dir[N];
ll Division(ll a,ll b){
    ll temp;
    if(a < b){
        temp = a;
        a = b;
        b = temp;

    }
    while(a%b != 0){
            temp = a%b;
            a = b;
            b = temp;
    }
    return b;
}
int main()
{
//    freopen("in.txt","r",stdin);
    ll n,x;
    while (cin>>n>>x)
    {
        memset(dir,0,sizeof(dir));
        if (n==1)
        {
            ll temp;
            cin>>temp;
            cout<<abs(x-temp)<<endl;
        }
        else
        {
            int flag=0;
            for (int i=0;i<n;i++)
            {
                ll temp;
                cin>>temp;
                dir[i]=temp;
                if (temp==x)
                {
                    flag=1;
                }
            }
            if (!flag)
            {
                dir[n]=x;
                n++;
            }
            sort(dir,dir+n);
            ll a=dir[1]-dir[0],b=dir[2]-dir[1];
            ll ans=Division(a,b);
            for (int i=2;i<n;i++)
            {
                ll temp=dir[i]-dir[i-1];
                ans=Division(ans,temp);
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int main() {
 
char ch[2000] = {0};
char W[15] = {0};
int i,j,k,l,m,n,o,p; 
 
m=0; /* ??????W?????\??? */
while(1) {
 
scanf("%c" , &W[m]);
/* printf("W[%d]???%c ",m,W[m]); /*W[m]????¢????*/
if(W[m] == '\n') {
break;
}
m = m+1;
}
 
n=0; /* ?????????T?????\??? */
while(1) {
 
scanf("%c",&ch[n]);
 
 /*printf("ch[%d]???%c ",n ,ch[n]); /*  ch[n]????¢???? */
  
 
if(ch[n] =='T' && ch[n-1] == 'X' && ch[n-2] == 'E' && ch[n-3] == 'T' && ch[n-4] == '_' && ch [n-5] == 'F' && ch[n-6] == 'O' && ch[n-7] == '_' && ch[n-8] == 'D' && ch[n-9] == 'N' && ch[n-10] == 'E') {
/* printf("break??????\n"); */
break;
}
n +=1;
} /*while??\????????????*/
 
 
/*??????????????¨?????????????¢????*/
p=0;
for(i=0; i<n; i++){
if(W[0] == ch[i] || W[0] == ch[i]+32 || W[0] == ch[i]-32) {
/* printf("????????????????¢????ch[%d]\n",i); /**/
if(ch[i+m] == ' ' || ch[i+m] == '\n' || W[0] == ch[0]  ) { 
if(ch[i-1] == ' ' || ch[i-1] == '\n' ||  W[0] == ch[0]+32 || W[0] == ch[0]-32){
o=o+1;
/*printf("ch[%d]???%c?????????\n",i,ch[i]); /*??????????¢????*/
 
for(j=0;j<m; j++) {
if(W[j] == ch[i+j] || W[j] == ch[i+j]+32 || W[j] == ch[i+j]-32){
/*printf("W[%d]???%c ch[%d]???%c\n",j,W[j],i+j,ch[i+j]); /*???= ????¢???????*/
o=o+1;
}
}
}
}
 
if(o==m+1){
p=p+1;
}
o=0;
}
}
 
printf("%d\n",p);
 
return 0;
 
}


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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,w,wi,vi;
	cin>>n>>w;
	ll dp[w+1];
	memset(dp,0,sizeof(dp));
	forn(i,n){
		cin>>wi>>vi;
		for(ll j = w-wi; j>=0; j--) dp[j+wi] = max(dp[j+wi],dp[j]+vi);
	}
	cout<<dp[w]<<'\n';
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""
 


Measured memory_bytes: 4428
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;
std::pair<string,pair<int,int>> Q[101];
    ll N,M;
    ll A,B,C;
    bool F=false;
    ll ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        string s;int a;
        cin>>s>>a;
        Q[i]={s,{-a,i+1}};
    }
    sort(Q,Q+N);
    REP(i,N){
        cout<<Q[i].second.second<<endl;
    }
    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);
    int X = sc.nextInt();
    if (X <= 40 && X >= -40) {
      if (X>=30) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
long long ans=1;
long long mm=0;
struct node
{
	char str[12];
}st[100000+100];
bool cmp1(char a,char b)
{
	return a<b;
}
bool cmp2(node a,node b)
{
	return strcmp(a.str,b.str)<0;
}
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>st[i].str;
	}
	for(int i=1;i<=n;i++)
	{
		sort(st[i].str,st[i].str+10,cmp1);
	}
	sort(st+1,st+n+1,cmp2);
	for(int i=2;i<=n;i++)
	{
		if(strcmp(st[i].str,st[i-1].str)==0)
		{
			ans++;
		}
		if(strcmp(st[i].str,st[i-1].str)!=0)
		{
			mm=mm+ans*(ans-1)/2;
			ans=1;
		}
	}
	mm=mm+ans*(ans-1)/2;
	printf("%lld ",mm);
	return 0;
}

Measured memory_bytes: 1408
using System;
using System.Linq;
using System.Collections.Generic;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = long.Parse(_[0]);
            var t = long.Parse(_[1]);
            var s = Console.ReadLine().Split().Select(i => long.Parse(i)).ToArray();

            var count = 0L;
            for(var i = 0; i < n-1; i++){
                if(s[i+1] - s[i] >= t){
                    count += t;
                }else{
                    count += (s[i+1] - s[i]);
                }
            }
            count += t;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 28832
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
string s;
int n,k;
bool f[201011];
int a[201101],b[201101];
int main(){
	cin>>n>>k;
	cin>>s;
	int ans=0,ans1=0,tt=1,ttt=1,zero=0,one=0,cnt=0;
	for (int i=0;i<s.size();i++){
		if (s[i]=='1') ans++;else {
			if (ans!=0){
			b[tt++]=ans;
			one+=ans;
			ans=0;
			}
		}
		if (i==n-1){
			if (ans!=0){
				b[tt++]=ans;
				one+=ans;
				ans=0;	
			}
		}
		if (s[i]=='0') ans1++;else {
			if (ans1!=0){
			a[ttt++]=ans1;
			zero+=ans1;
			ans1=0;
			}
		}
		if (i==n-1){
			if (ans1!=0){
				a[ttt++]=ans1;
				zero+=ans1;
				ans1=0;	
			}
		}
	}
	//for (int i=1;i<=tt;i++) cout<<b[i]<<endl;
	if (k==0){
		for (int i=1;i<=tt-1;i++)
			if (b[i]>cnt) cnt=b[i];
	} else
	if (k>=zero){
		cnt=s.size();	
	}else if (k>ttt-1) cnt=s.size();
		else {
			int i=1;
			while (i+k-1<=ttt-1){
				int q=0;
				if (s[0]=='1') {
				for (int j=i;j<=i+k-1;j++)
					q+=b[j]+a[j];
				q+=b[i+k];
				}else {
					for (int j=i;j<=i+k-1;j++)
					q+=b[j]+a[j];
					q+=b[i-1];
				}
				//cout<<q<<endl;
				if (q>cnt) cnt=q;
				i++;	
			}
		}
	cout<<cnt<<endl;
	
	return 0;
}



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

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

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0ll) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(All(ret));
  return (ret);
};

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

  ll x;
  cin >> x;

  auto div = divisor(x);

  for (ll di: div) {
    ll tmp = x / di;
    // debug(tmp);
    for (ll a = 0; a <= 100005ll; a++) {
      ll b = a - di;
      // debug(b);
      if (a*a*a*a + a*a*a*b + a*a*b*b + a*b*b*b + b*b*b*b == tmp) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
};


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[200005];
int main() {
	int n, k, c;
	scanf("%d%d%d", &n, &k, &c);
	scanf("%s", str);
	vector<int> dp(n + 1), rdp(n + 2);
	int las = -1e9;
	for (int i = 0; i < n; ++i) {
		if (str[i] == 'o' && i > las + c) {
			las = i;
			dp[i + 1] = dp[i] + 1;
		} else {
			dp[i + 1] = dp[i];
		}
	}
	las = 1e9;
	for (int i = n - 1; i >= 0; --i) {
		if (str[i] == 'o' && i < las - c) {
			las = i;
			rdp[i + 1] = rdp[i + 2] + 1;
		} else {
			rdp[i + 1] = rdp[i + 2];
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (dp[i - 1] + rdp[i + 1] < k) {
			printf("%d\n", i);
		}
	}
}


Measured memory_bytes: 5084
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    int mini = 10000, maxi = -1;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        chmax(maxi, a);
        chmin(mini, a);
    }
    cout << maxi - mini << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    char str[20001];
    int maxh[20002];
    char* ptr = str;
    int hstart = 0;
    int h;
    int total = 0;
    int double_water = 0;
    bool down = false;
    vector<int> pool;

    scanf("%20000[^\n]", str);
    int i = 0;
    while (str[i]) { ++i; }
    int mh = hstart;
    for (; i >= 0; --i)
    {
        if (str[i] == '/')
        {
            mh = MAX(mh, hstart);
            maxh[i + 1] = mh;
            --hstart;
        }
        else if (str[i] == '\\')
        {
            mh = MAX(mh, hstart);
            maxh[i + 1] = mh;
            ++hstart;
        }
        else if (str[i] == '_')
        {
            maxh[i + 1] = mh;
        }
    };
    maxh[0] = MAX(mh, hstart);

    while (*ptr)
    {
        if (*ptr == '/')
        {
            if (down)
            {
                double_water += ((hstart - h) << 1) - 1;
                ++h;
                if (hstart == h)
                {
                    down = false;
                    pool.push_back(double_water >> 1);
                    total += (double_water >> 1);
                    double_water = 0;
                }
            }
            else
            {
                ++hstart;
            }
        }
        else if (*ptr == '\\')
        {
            if (!down && hstart <= maxh[ptr - str + 1])
            {
                down = true;
                h = hstart;
            }

            if (down)
            {
                double_water += ((hstart - h) << 1) + 1;
                --h;
            }
            else
            {
                --hstart;
            }
        }
        else if (*ptr == '_')
        {
            if (down)
            {
                double_water += ((hstart - h) << 1);
            }
        }
        ++ptr;
    }

    if (down)
    {
        pool.push_back(double_water >> 1);
        total += (double_water >> 1);
    }

    cout << total << "\n";
    cout << pool.size();
    for (auto it : pool)
    {
        cout << " " << it;
    }
    cout << "\n";

    return 0;
}



Measured memory_bytes: 3352
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int n=scanner.nextInt();
                int[] l=new int[n];
                long[] snuke=new long[n];
                for(int i=0;i<n;i++){
                        l[i]=scanner.nextInt();
                }

                long sum=0;
                for(int i=0;i<n;i++){
                        sum+=l[i];
                        snuke[i]=sum;
                }

                long sub=0;
                long min=0;
                sub=2*snuke[0]-sum;
                if(sub<0){
                        sub=-sub;
                }
                min=sub;
                for(int i=0;i<n-1;i++){
                        sub=2*snuke[i]-sum;
                if(sub<0){
                        sub=-sub;
                }
                        if(sub<min){
                                min=sub;
                        }
                }
                System.out.println(min);
        }
}

Measured memory_bytes: 87444
#include <cstdio>
#include <cmath>
#define buf 10000
using namespace std;

int main(void){
  int i;
  double n,m,sum;
  char str[buf];

  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
    sscanf(str,"%lf",&n); sum=0;
    for(i=0;i<n;i++){
      fgets(str,sizeof(str),stdin);
      sscanf(str,"%lf",&m);
      sum+=m;
    }
    sum=floor(sum/n);
    printf("%.0f\n",sum);
  }
  return 0;
}

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

int main()
{
  string a, b, c;
  cin >> a >> b >> c;

  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
    cout << "YES" << endl;
  }

  else cout << "NO" << endl;

  return 0;

}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc071/tasks/abc071_b

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s, a = "abcdefghijklmnopqrstuvwxyz", r = "None";

  cin >> s;

  REP(i, 26)
  {
    if (s.find(a[i]) == string::npos)
    {
      r = a[i];
      break;
    }
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

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

int main(){
    int a[100], n, i, sw;

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

    sw = selectionSort(a, n);

    for(i = 0; i < n; i++){
        if( i > 0)printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}


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

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7  
int main() {
    int a,b;
    cin>>a>>b;
    if(a>=b){
        REP(i,a){
            cout<<b;
        }
        cout<<endl;
    }
    else {
        REP(i,b){
            cout<<a;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 200005;
struct Edge{
	int to,next,w;
}e[MAXN<<3];
struct E{
	int u,v,c;
	bool operator < (const E &b)const
	{
		return c<b.c;
	}
}t[MAXN<<1];
int head[MAXN<<3],n,m,fa[MAXN],id[MAXN],sz;
bool vis[MAXN<<3];
int getan(int x)
{
	return x==fa[x]?x:fa[x]=getan(fa[x]);
}
int cnt=0;
inline void insert(int u,int v,int w)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt,e[cnt].w=w;
}
inline void work(int l,int r)
{
	for(int i=l;i<=r;++i){
		vis[t[i].u]=vis[t[i].v]=id[t[i].u]=id[t[i].v]=0;
		fa[t[i].u]=t[i].u;
		fa[t[i].v]=t[i].v;
	}
	for(int i=l,x,y;i<=r;++i)
		x=getan(t[i].u),y=getan(t[i].v),fa[x]=y;
	for(int i=l,x,y;i<=r;++i){
		x=getan(t[i].u),y=getan(t[i].v);
		if(!vis[t[i].u]){
			if(!id[x])id[x]=++sz;
			insert(t[i].u,id[x],0);
			insert(id[x],t[i].u,1);
			vis[t[i].u]=1;
		}
		if(!vis[t[i].v]){
			if(!id[y])id[y]=++sz;
			insert(t[i].v,id[y],0);
			insert(id[y],t[i].v,1);
			vis[t[i].v]=1;
		}
	}
}
struct Node{
	int x,v;
	bool operator < (const Node &b)const
	{
		return v>b.v;
	}
};
priority_queue<Node>q;
int d[MAXN<<3];
inline void dij()
{
	memset(vis,0,sizeof(vis));
	memset(d,0x3f,sizeof(d));
	d[1]=0;
	q.push((Node){1,0});
	while(!q.empty()){
		Node x=q.top();
		q.pop();
		int u=x.x;
		if(vis[u])continue;
		vis[u]=true;
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			if(d[v]>d[u]+e[i].w){
				d[v]=d[u]+e[i].w;
				q.push((Node){v,d[v]});
			}
		}
	}
	cout<<(d[n]==0x3f3f3f3f?-1:d[n])<<endl;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		scanf("%d%d%d",&t[i].u,&t[i].v,&t[i].c);
	}
	sz=n;
	sort(t+1,t+m+1);
	int p=1;
	while(p<=m){
		int r=p;
		while(t[r+1].c==t[r].c)++r;
		work(p,r);
		p=r+1;
	}
	dij();
	return 0;
}


Measured memory_bytes: 30072
N, M = map(int, input().split())
P = [[] for _ in range(N+1)]
ite = []

for _ in range(M):
    p, y = map(int, input().split())
    P[p].append(y)
    ite.append([p, y])

dic = {}
for p in range(N+1):
    P[p] = sorted(P[p])
    for i, y in enumerate(P[p]):
        i += 1
        dic[y] = '{}{}'.format(str(p).zfill(6), str(i).zfill(6))

for i in range(M):
    p, y = ite[i]
    print(dic[y])

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


//0045
int main(){
	int p,n, p_sum=0, n_sum=0, cnt=0;
	char ch;
	while(cin >> p >> ch >> n){
		p_sum += p*n;
		n_sum += n;
		++cnt;
	}

	int avg = ((n_sum * 10 / cnt) + 5)/10;
	cout << p_sum << endl;
	cout << avg << endl;

	
}

Measured memory_bytes: 0
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);
	
	static String s;
	public static void main(String[] args) {
		s = sc.next();
		boolean[] plus = new boolean[s.length()-1];
		
		so.println(sum(plus, 0));
	}
	
	static long sum(boolean[] b, int lev) {
		if (lev == b.length)
			return parse(s, b);
		
		long sum = 0;
		b[lev] = false; // 12
		sum += sum(b, lev+1);
		
		b[lev] = true;  // 1+2
		sum += sum(b, lev+1);
		
		return sum;
	}

	static long parse(String s, boolean[] b) {
		if (s.length()-1 != b.length) throw new RuntimeException();
		
		StringBuilder ev = new StringBuilder();
		ev.append(s.charAt(0));
		
		for (int i = 0; i < b.length; i++) {
			if (b[i])
				ev.append("plus");
			ev.append(s.charAt(i+1));
		}
		
		String[] longs = ev.toString().split("plus");
		long ans = 0;
		for (int i = 0; i < longs.length; i++) {
			ans += Long.parseLong(longs[i]);
		}
		return ans;
	}
}


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

int main() {
	int n, d, x[15][15], temp, akar, ans = 0;
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++)
			scanf("%d", &x[i][j]);
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++) {
			temp = 0;
			for (int k = 0; k < d; k++)
				temp += ((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
			akar = sqrt(temp);
			if (akar * akar == temp)
				ans++;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,c[20][20];
long long ans,tmp;
int main(){
//	freopen("A.in","r",stdin);
//	freopen("A.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;++i){
		double x;
		int t1=0,t2=0;
		scanf("%lf",&x);
		tmp=(long long )(x*1e9+0.5);
		while(tmp%2==0)tmp/=2,t1++;
		while(tmp%5==0)tmp/=5,t2++;
		t1=min(t1,18),t2=min(t2,18);
		for(int j=0;j<=18;++j)
		for(int k=0;k<=18;++k){
			if(min(t1+j,t2+k)>=18)ans+=c[j][k];
		}
		c[t1][t2]++;
	//	cout<<ans<<endl;
	}
	cout<<ans<<endl;
	/*(int i=0;i<=10;++i){
		for(int j=0;j<=10;++j)printf("%d ",c[i][j]);
		puts("");
	}*/
	return 0;
} 

Measured memory_bytes: 3728
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll d[2020][2020];
ll d1[10010];

int main(){
  ll n,x,y;
  cin>>n>>x>>y;
  x--;
  y--;
  vector<vector<ll> > vv(n,vector<ll>());
  rep(i,0,n-1){
    vv[i].pb(i+1);
    vv[i+1].pb(i);
  }
  vv[x].pb(y);
  vv[y].pb(x);
  rep(i,0,2020)rep(j,0,2020)d[i][j] = 10000;
  rep(i,0,n){
    queue<ll> q1;
    queue<ll> q2;
    q1.push(i);
    q2.push(0);
    while(!q1.empty()){
      ll a = q1.front();q1.pop();
      ll b = q2.front();q2.pop();
      if(d[i][a]!=10000)continue;
      d[i][a] = b;
      rep(j,0,vv[a].sz){
        q1.push(vv[a][j]);
        q2.push(b+1);
      }
    }
  }
  rep(i,0,n){
    rep(j,i+1,n){
      d1[d[i][j]]++;
    }
  }
  rep(i,1,n){
    cout << d1[i] << endl;
  }
  return 0;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){

  int n; cin >> n;
  vi v(n);
  rep(i, n) 
    cin >> v[i];
  
  ll ans = 0;
  rep(i, n)
    ans += v[i] - 1;

  pr(ans);

  return 0;
}


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

bool triangle(int a,int b,int c){
    bool ch = true;
    if(a + b <= c)
        ch = false;
    if(a + c <= b)
        ch = false;
    if(b + c <= a)
        ch = false;
    return ch;
}

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N;i++)
        cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    for (int i = 0; i < N-1;i++)
        for (int j = i + 1; j < N;j++){
            int l = j + 1;
            int r = N - 1;
            while(r - l > -1){
                int mid = (l + r) / 2;
                if(triangle(L[i],L[j],L[mid])){
                    l = mid + 1;
                }else{
                    r = mid - 1;
                }
            }
            if (triangle(L[i], L[j], L[r])){
                ans += r - j;
            } 
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c = sorted(map(int,input().split()))
ans = 0
ans += (c-b)//2
b += (c-b)//2*2
ans += (c-a)//2
a += (c-a)//2*2
a,b,c = sorted([a,b,c])
if a==b and b!=c:
  print(ans+1)
elif a==b==c:
  print(ans)
elif b==c and b!=a:
  print(ans+2)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
const int N = 2e5 + 54, P = 998244353;
std::pair <int, int> a[N];
int n, ans[N];
namespace segT {
	int max[N << 2];
	void insert(int l, int r, int x, int id, int k) {
		if (l == r) { max[x] = k; return;}
		int mid = l + r >> 1;
		if (id <= mid) insert(l, mid, x << 1, id, k);
		else insert(mid + 1, r, x << 1 | 1, id, k);
		max[x] = std::max(max[x << 1], max[x << 1 | 1]);
	}
	int query(int l, int r, int x, int ql, int qr, int ret = -1) {
		if (ql > qr || l > qr || r < ql) return -1;
		if (ql <= l && r <= qr) return max[x];
		int mid = l + r >> 1;
		if (ql <= mid) ret = std::max(ret, query(l, mid, x << 1, ql, qr));
		if (qr > mid) ret = std::max(ret, query(mid + 1, r, x << 1 | 1, ql, qr));
		return ret;
	}
}
inline int add(int x) { return x >= P ? x - P : x; }
int main() {
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> a[i].first >> a[i].second;
	std::sort(a + 1, a + n + 1);
	ans[n + 1] = 1;
	for (int i = n; i; --i) {
		int l = i, r = n, id = 0, D = a[i].first + a[i].second - 1;
		while (l <= r) {
			int mid = l + r >> 1;
			if (a[mid].first <= D) id = mid, l = mid + 1;
			else r = mid - 1;
		}
		int R = segT::query(1, n, 1, i, id);
		if (id == i) R = i;
		ans[i] = add(ans[i + 1] + ans[R + 1]);
		segT::insert(1, n, 1, i, R);
	}
	std::cout << ans[1] << '\n';
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
    fast;
	ll n,k,ans=0,val=1;
	cin>>n>>k;
	if(val+k<val*2){
	while(val+k<val*2&&ans<n)
		val+=k,ans++;
	while(ans<n)
		val*=2,ans++;
	}
	else{
	while(val*2<val+k&&ans<n)
		val*=2,ans++;
	while(ans<n)
		val+=k,ans++;
	}
    cout<<val;
    return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
    int n;
    char c;
    int i;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%c", &c);
        if (c == 'Y')
        {
            printf("Four\n");
            return 0;
        }
    }
    printf("Three\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> asum(N+1);
  asum.at(0)=0;
  long long sum=0;
  for(int i=1;i<N+1;i++){
    long long a;
    cin >> a;
    sum+=a;
    asum.at(i)=sum;
  }

  long long ans=100000000000000000;
  for(int i=1;i<N+1-1;i++){
    long long x=asum.at(i);
    long long y=asum.at(N)-asum.at(i);
    ans=min(ans,abs(x-y));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
const ll MOD = 1e9 + 7;
vi alphabet = { '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' };





int main() {
    int A, B, C, D;
    int S;
    cin >> S;
    D = S%10;
    C = (S%100)/10;
    B = (S % 1000) / 100;
    A = S/1000;
    if (A + B + C + D == 7) cout << A << "+" << B << "+" << C << "+" << D << "=" << 7 << endl;
    else if (A + B + C - D == 7) cout << A << "+" << B << "+" << C << "-" << D << "=" << 7 << endl;
    else if (A + B - C + D == 7) cout << A << "+" << B << "-" << C << "+" << D << "=" << 7 << endl;
    else if (A + B - C - D == 7) cout << A << "+" << B << "-" << C << "-" << D << "=" << 7 << endl;
    else if (A - B + C + D == 7) cout << A << "-" << B << "+" << C << "+" << D << "=" << 7 << endl;
    else if (A - B + C - D == 7) cout << A << "-" << B << "+" << C << "-" << D << "=" << 7 << endl;
    else if (A - B - C + D == 7) cout << A << "-" << B << "-" << C << "+" << D << "=" << 7 << endl;
    else if (A - B - C - D == 7) cout << A << "-" << B << "-" << C << "-" << D << "=" << 7 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

   string s;
   cin >> s;

    if(s=="ABC") cout << "ARC";
    else cout << "ABC";


    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main()
{
    int a,s,d,f;
    scanf("%d%d%d%d",&a,&s,&d,&f);
    if(a>s)
    {
        if(d>f)
            printf("%d",s+f);
        else
            printf("%d",s+d);
    }
    else
    {
        if(d>f)
            printf("%d",a+f);
        else
            printf("%d",a+d);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

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

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {
    
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in1 = br.readLine().split(" ");
        int N = Integer.parseInt(in1[0]);
        long x = Long.parseLong(in1[1]);
        
        in1 = br.readLine().split(" ");
        long[] a = Stream.of(in1).mapToLong(Long::parseLong).toArray();
        br.close();

        long[] b = a.clone();
        long ans = 0L;
        for(int i = 0; i < N; i++){
            ans += b[i];
        }

        for(int i = 1; i < N; i++){
            for(int j = 0; j < N; j++){
                b[j] = Math.min(b[j], a[(j - i + N)%N]);
            }
            long tmp_ans = i * x;
            for(int j = 0; j < N; j++){
                tmp_ans += b[j];
            }
            ans = Math.min(ans, tmp_ans);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 27216
#include <stdio.h>
int main(){
  int a[100][100],b[100][100],n,m,l,i,j,k;
  long long c[100][100];

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

  for(i=0;i<n;i++) for(j=0;j<l;j++) for(c[i][j]=0,k=0;k<m;k++) c[i][j]+=a[i][k]*b[k][j];

  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      printf("%lld",c[i][j]);
      if(j!=(l-1)) printf(" ");
      else printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 760
import math
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        a, b, x = map(int, input().split())
        h = x / (a * a)
        c = 2 * h - b
        if c < 0:
            e = (2 * x) / (a * b)
            tan = e / b
            print(90 - math.degrees(math.atan(tan)))
        else:
            d = b - c
            tan = d / a
            print(math.degrees(math.atan(tan)))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define each(i,a) for(auto&& i:a)
const ll p=1000000007;
ll modpow(ll a,ll b){
    if(b==0)return 1;
    ll ans=modpow(a,b/2);
    ans=ans*ans%p;
    if(b&1)ans=ans*a%p;
    return ans;
}
vector<ll>fac,inv;
void init(ll n){
    fac.resize(n+1);inv.resize(n+1);
    fac[0]=1;
    rep(i,1,n+1)fac[i]=fac[i-1]*i%p;
    inv[n]=modpow(fac[n],p-2);
    rrep(i,1,n+1)inv[i-1]=inv[i]*i%p;
}
ll comb(ll a,ll b){
    return fac[a]*inv[b]%p*inv[a-b]%p;
}
ll mcomb(ll n,ll r){
	return comb(n+r-1,r);
}
int main(){
	ll n,m;
	cin>>n>>m;
	init(110000);
	map<ll,ll> f;
	for(ll i=2;i<=n;i++){
		while(m%i==0){
			f[i]++;
			m/=i;
		}
	}
	if(m!=1) {
		f[m]++;
	}
	ll ans=1;
	each(i,f){
		ans=ans*mcomb(n,i.second)%p;
	}
	cout<<ans;
}

Measured memory_bytes: 1920
n=int(input())
s=list(map(int,input().split()))

import fractions as frc
from functools import reduce

def lcm_base(x, y):
	return(x*y)//frc.gcd(x, y)

def lcm_list(numbers):
	return reduce(lcm_base, numbers, 1)

x=lcm_list(s)
tot=0

for i in range(n):
	tot+=1/s[i]*x
    
print(x/tot)

Measured memory_bytes: 5588
n = int(input())
l1 = [int(x) for x in input().split()] 
m = int(input())
l2 = [int(x) for x in input().split()] 

cnt = 0
for i in range(len(l2)):
    for j in range(len(l1)):
        if(l1[j] == l2[i]):
            cnt = cnt + 1
            break
print(cnt)



Measured memory_bytes: 6556
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
int N,K;
int a[200002],ans=0;
int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    a[x]++;
  }
  int c=0;
  sort(a,a+N+1);
  for(int i=0;i<=N;i++){
    if(a[i]>0)c++;
  }
  if(c<=K)cout << "0" << endl;
  else {
    int i=0,x=0;;
    while(i<=N){
      if(a[i]>0 && x<c-K){ans+=a[i];x++;}
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int n;
vector<pair<ll,int>> a;
ll dp[2010][2010];
int flag[2010][2010];

ll ddpp(int l,int r){
    if (flag[l][r])return dp[l][r];
    flag[l][r]=1;
    int num1=n-(r-l+1);//上から何番目を数えているか
    auto p=a[num1];
    ll num=p.first;
    int a1=p.second;
    if (l==r){
        dp[l][l]=abs(a1-l)*num;
        return dp[l][l];
    }
    else{
        ll ans=max(ddpp(l+1,r)+abs(a1-l)*num,ddpp(l,r-1)+abs(a1-r)*num);
        dp[l][r]=ans;
        return ans;
    }


}

int main() {
    cin>>n;
    rep(i,n){
        ll a1;
        cin>>a1;
        a.push_back(make_pair(a1,i+1));
    }
    sort(all(a));
    reverse(all(a));
    memset(dp,0,sizeof(dp));
    ddpp(1,n);
    cout<<dp[1][n]<<endl;
    

    return 0;
}

Measured memory_bytes: 49168
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

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

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n;
	set<string> st;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
}


Measured memory_bytes: 19148
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char in[400][400];
int ret[400][400];
int main() {
	int H,W,K;
	cin >> H >> W >> K;
	vector<P> ps;
	for(int i=0;i<H;i++){
		cin >> in[i];
		for(int j=0;j<W;j++){
			if(in[i][j]=='#'){
				ps.push_back(P(i,j));
			}

		}
	}

	int c=1;
	int x=0,y=0;
	P pre=P(-1,-1);
	for(auto p:ps){
		if(pre.first!=p.first){
			x=pre.first+1;
			y=0;
		}
		else{
			y=pre.second+1;
		}
		cerr << x << ", " << y << ", " << p.first << ", " << W << ": " << c << endl;
		for(int i=x;i<=p.first;i++){
			for(int j=y;j<W;j++){
				ret[i][j]=c;
			}
		}
		pre=p;
		c++;
	}
	for(int i=0;i<H;i++){
		auto sp="";
		for(int j=0;j<W;j++){
			if(ret[i][j]==0){
				ret[i][j]=ret[i-1][j];
			}
			cout << sp << ret[i][j];
			sp=" ";
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, ans;
	cin >> a >> b;
	ans = max(a + b, max(a - b, a *b));

	cout << ans << "\n";
	return 0;
}


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

vector<int> a(100000);

int main(){
    int n; cin >> n;
    for(int i=0; i<n; i++){
        int z; cin >> z;
        a[i] = z-1;
    }
    
    bool flg = true;
    int pos = a[0];
    int res=1;
    while(true){
        
        if(pos == 1){
            break;
        }else if(res >= n){
            flg = false;
            break;
        }
        pos = a[pos]; res++;
    }
    if(flg) cout << res << endl;
    else    cout << "-1"<< endl;
    return 0;
}

Measured memory_bytes: 3692