akhauriyash/Code-Regression huggingface dataset:
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var count = 0;
	var max = 0;
	for(var i = 0; i < N - 1; i++){
		if(list[i] >= list[i + 1]){
			count++;
		}else{
			max = Math.max(max, count);
			count = 0;
		}
	}
	max = Math.max(max, count);
	myout(max);
}


Measured memory_bytes: 40688
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    double n;
    while(cin>>n)
{
    if(n==0)return 0;
    double sum=0;
    vector<double>a(n);
    REP(i,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sum/=n;
    double ans=0;
    REP(i,n)
    {
        if(a[i]<=sum)ans++;
    }
    cout<<ans<<endl;
}
}


Measured memory_bytes: 3372
import sys

n, *h = map(int, sys.stdin.read().split())

def main():
    ans = 'Yes'
    for i in range(n - 1, 0, -1):
        if h[i-1] > h[i]: h[i-1] -= 1
        if h[i-1] > h[i]: ans = 'No'; break
    print(ans)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 14108
#include<cstdio>
using namespace std;
const int mod=1e9+7;
int dp[70][3][3][2];
long long n;
int num[70];
inline void add(int &a,int b)
{
    a=a+b;
    if(a>=mod)a-=mod;
    if(a<0)a+=mod;
}
int cmp(int x,int y)
{
    return x<y?0:(x>y?2:1);
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=60;i++)
        num[i]=n&1,n>>=1;
    dp[0][1][1][0]=1;
    for(int i=1;i<=60;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                for(int l=0;l<2;l++)
                    for(int p=0;p<2;p++)
                        for(int q=0;q<=p;q++){
                            int tj=cmp(q^p,num[i]);
                            int tk=cmp((p+q+l)%2,num[i]);
                            if(tj==1)tj=j;
                            if(tk==1)tk=k;
                            add(dp[i][tj][tk][(p+q+l)/2],dp[i-1][j][k][l]);
                        }
    int res=0;
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            add(res,dp[60][i][j][0]);
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],dp[100001];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
dp[1]=0;
dp[2]=abs(a[1]-a[2]);
for(int i=3;i<=n;i++)
dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
cout<<dp[n];
return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> x(m), v;
    for(int i = 0; i < m; i++) cin >> x[i];
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(), x.end());
    for(int i = 0; i < m - 1; i++) v.push_back(x[i + 1] - x[i]);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll sum = x[m - 1] - x[0];
    for(int i = 0; i < n - 1; i++) sum -= v[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;


int main(){
    int A1[3],A2[3],A3[3],N,a1[3]={0,0,0},a2[3]={0,0,0},a3[3]={0,0,0};
    for (int i=0;i<3;i++){
        cin>>A1[i];
    }
     for (int i=0;i<3;i++){
        cin>>A2[i];
    }
     for (int i=0;i<3;i++){
        cin>>A3[i];
    }
    cin>>N;
    int b[N];
    for (int i=0;i<N;i++){
        cin>>b[i];
        for (int j=0;j<3;j++){
            if (b[i]==A1[j]) a1[j]=1;
            else if (b[i]==A2[j]) a2[j]=1;
            else if (b[i]==A3[j]) a3[j]=1;
        }
    }
    if (a1[0]*a1[1]*a1[2]==1||a2[0]*a2[1]*a2[2]==1||a3[0]*a3[1]*a3[2]==1||a1[0]*a2[0]*a3[0]==1||a1[1]*a2[1]*a3[1]==1||a1[2]*a2[2]*a3[2]==1||a1[0]*a2[1]*a3[2]==1||a1[2]*a2[1]*a3[0]==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    std::sort(std::begin(A), std::end(A));

    std::vector<int64_t> sum;
    std::partial_sum(std::begin(A), std::end(A), std::back_inserter(sum));

    int64_t result = 1;
    for (int64_t i = N-1; i >= 1; --i) {
        if (sum[i-1] *2 < A[i]) {
            break;
        }
        result ++;
    }
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 2548
N = int(input())


s_ = input()
s_set = set([s_])

ans = 'Yes'

for _ in range(N-1):
    s = input()
    if s in s_set:
        ans = 'No'
    if s[0] != s_[-1]:
        ans = 'No'
    s_set.add(s)
    s_ = s

print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

#define MULTIPLICATION_THREE 3
#define MULTIPLICATION_TEN 10
//printf("helloWorld\n");


int main(void)
{
	//�ϐ���`
	int iInput;								//����n
	int iCount;							//�J�E���g�A�b�v�ϐ�
	int iDataNoTouch;
	int iMultiplicationResult;		//SEED_MULTIPLICATION�̔{��
	int iDataMultipleTen;

	//�ϐ��̏�����
	iInput = 0;
	iMultiplicationResult = 0;
	iDataNoTouch = 0;
	iDataMultipleTen = 0;
	iCount = 1;

	//����n�̓���
	scanf("%d", &iInput);

	//����n�ɒB����܂Ń��[�v
	for (iCount = 1; iCount <= iInput; iCount++)
	{
		iDataMultipleTen = iCount;
		//iCount �� MULTIPLICATION_THREE�Ŋ��������ʁA�]�肪�o�Ȃ��Ƃ�iCount���o�͂���
		if (iDataMultipleTen % MULTIPLICATION_THREE == 0)
		{
			printf(" %d", iCount);
		}
		//iCount��MULTIPLICATION_TEN�Ŋ��������ʁA�]�肪3�ɂȂ�Ƃ�iCount���o�͂���
		else 
		{
			do 	
			{ 
				if (iDataMultipleTen % MULTIPLICATION_TEN == 3)
				{
					printf(" %d", iCount);
					iDataMultipleTen = 0;
				}
				//����ȊO�͂Ȃɂ����Ȃ�
				else
				{
					iDataMultipleTen /= MULTIPLICATION_TEN;
				}
			} while (iDataMultipleTen != 0);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    int n;
    
    scanf("%d",&n);
    
    if(n%1000)
        printf("%d",(((n/1000)+1)*1000)-n);
    else
        printf("0");

    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9


int main()
{
    fastio;
    lli n;
    cin >> n;
    lli dp[13];
    dp[0]=1;
    for(int i=1;i<13;i++)
        dp[i]=dp[i-1]*26;
    int na;
    lli n1=n;
    for(int i=1;i<13;i++)
    {
        if(n1<=dp[i])
        {
            na=i;
            break;
        }
        n1-=dp[i];
    }
    for(int i=1;i<na;i++)
        n-=dp[i];
    string ans="";
    int place=1;
    for(int i=0;i<na;i++)
    {
        lli t=dp[na-place];
        for(int j=0;j<26;j++)
        {
            if(n<=t)
            {
                char c=97+j;
                string s(1,c);
                ans+=s;
                place+=1;
                break;
            }
            n-=t;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
/**
*	author:     Bervig
*	created at: 2020-06-15 11:50:33
**/

#include <bits/stdc++.h>

using namespace std;

#define dbg(x) { cerr << #x << " = " << x << "\n"; } 
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int el;
	for(int i = 0; i < 5; i++){
		cin >> el;
		if(!el){
			cout << i + 1 << "\n";
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    
    int cnt = 0;
    for (int i = A; i <= B; ++i) {
        string str = to_string(i);
        string rts = str;
        reverse(rts.begin(), rts.end());
        if (str == rts) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int x,i,c,s;
	while(scanf("%d",&x)){
		s=0;
		if(x==0)break;
		x=1000-x;
		for(i=0;i<3;i++){
			c=x%10;
			s+=c;
			if(c>4)s-=4;
			x/=10;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
)

func main() {
	week := []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
	var s string
	fmt.Scan(&s)

	for i, v := range week {
		if s == v {
			fmt.Println(7 - i)
			return
		}
	}
}


Measured memory_bytes: 512
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

const int mod = 1000*1000*1000+7;
const int N = 500010;

int n;
int m;
int f[N];
int rf[N];
int p[N];
int q[N];
int cnt[N];
int fen[N];

int power (int a, int b) {
	int c = 1;
	while (b) {
		if (b & 1) c = ((ll)c * a) % mod;
		a = ((ll)a * a) % mod;
		b /= 2;
	}
	re c;
}

int get (int x) {
	int y = 0;
	while (x > 0) {
		y += fen[x];
		x = (x & (x + 1)) - 1;
	}
	re y;
}

void add (int x, int y) {
	while (x <= n) {
		fen[x] += y;
		x |= x + 1;
	}
}

int main () {
	scanf ("%d", &n);
	int zero = 0;
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &p[i]);
		q[p[i]] = i;
		zero += int (p[i] == 0);
	}
	cnt[0] = 0;
	int cur = 0, sum = 0, zerop = 0;
	for (int i = 1; i <= n; i++) {
		if (q[i] == 0) {
			zerop = (zerop + cur) % mod;
			cur++;
			sum = (sum + i - 1) % mod;
		}
		cnt[i] = cur;
	}	
	f[0] = rf[0] = 1;
	for (int i = 1; i <= n; i++) {
		f[i] = ((ll)f[i - 1] * i) % mod;
		rf[i] = power (f[i], mod - 2);
	}
	int ans = 0, pos = 0, tot = 0;
	for (int i = 1; i <= n; i++) {
		int cur = 0;
		if (p[i] != 0) {
			cur = (cur + (ll)(p[i] - 1) * f[zero]) % mod;
			if (zero > 0) cur = (cur - (ll)pos * cnt[p[i] - 1] % mod * f[zero - 1] % mod + mod) % mod;
			cur = (cur - (ll)f[zero] * get (p[i] - 1) % mod + mod) % mod;
			add (p[i], 1);
			tot = (tot + zero - cnt[p[i]]) % mod;
			if (tot < 0) tot += mod;
		} else {
			cur = (cur + (ll)sum * (zero - 1)) % mod;
			if (zero > 1) cur = (cur - (ll)zerop * pos % mod + mod) % mod;				
			cur = (cur - (ll)(zero - 1) * tot % mod + mod) % mod;
			cur = ((ll)cur * f[zero - 2]) % mod;
			pos++;
		}
		ans = (ans + (ll)cur * f[n - i]) % mod;
	}
	ans = (ans + f[zero]) % mod;
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11904
n = int(input())
k = int(input())
X = list(map(int, input().split()))

ans = 0
for i in range(n):
  if X[i] <= k/2:
    ans += 2*abs(X[i])
  else:
    ans += 2*abs(X[i] - k)
 
print(ans)

Measured memory_bytes: 3060
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(v => Number(v))
  const k = input[0]
  const s = input[1]
  let count = 0
  for (let xi = 0; xi <= k; xi++) {
    for (let yi = 0; yi <= k; yi++) {
      const tmp = s - (xi + yi)
      if (tmp >= 0 && tmp <= k) count++
    }
  }

  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7756
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,y,i,ans=100;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>x;
    y=0;
    while(x%2==0){
      y++;
      x/=2;
    }
    ans=min(ans,y);
  }
  cout<<ans<<endl;
}

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

int main(void)
{
  string S;
	cin >> S;
	int ans;
	if(S=="SUN") ans = 7;
	else if(S=="MON") ans = 6;
	else if(S=="TUE") ans = 5;
	else if(S=="WED") ans = 4;
	else if(S=="THU") ans = 3;
	else if(S=="FRI") ans = 2;
	else ans = 1;
  cout << ans << endl;
}

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

int main(){
  int N;
  cin >>N;
  
  map<string,int> mp;
  
  rep(i,0,N){
    string s;
    cin >>s;
    mp[s]++;
  }
  
  int M;
  cin >>M;
  
  rep(i,0,M){
    string s;
    cin >>s;
    mp[s]--;
  } 
  
  int mpmx = 0;
  map<string, int>::iterator it;
  for(it = mp.begin(); it!=mp.end(); it++){
    if( mpmx< it->second ) mpmx = it->second;
  }
  
  int ans = max(0,mpmx);
  cout <<ans<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  double a = 0;
  rep(i, N) {
    cin >> A[i];
    a += 1 / double(A[i]);
  }
  cout << setprecision(10) << 1 / a << endl;
  return 0;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
    rd1(string, n);
    int sm = 0;
    for(auto x: n) {
        int num = x - '0';
        sm += num;
    }
    
    if(sm % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
}


int main() {
	
	fastio;
	
	ll t = 1;
// 	rd1(ll, t);
    while(t--) {
        solve();
    }


	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

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

  vector<string> a(n);
  unordered_map<string, int> mp{{"RE", 0}, {"TLE", 0}, {"WA", 0}, {"AC", 0}};
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }

  for (auto x : mp) {
    cout << x.first << " x " << x.second << endl;
  }

  return 0;
}

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    int n;
    cin>>n;
    int z=n%10;
    if(z==2||z==4||z==5||z==7||z==9)
        cout<<"hon"<<endl;
    if(z==0||z==1||z==6||z==8)
        cout<<"pon"<<endl;
    if(z==3)
        cout<<"bon"<<endl;

    return 0;
}



Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iterator>
#include <random>
#include <cassert>
#include <iomanip>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double EPS = 1e-10;
const double PI = acos(-1);

class CStrawberryCakes {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int H, W, K;
        in>>H>>W>>K;
        vector<string> grid(H);
        REP(i, H) in>>grid[i];
        vii used(H, vi(W, 0));
        int cur = 1, last = -1;
        REP(i, H){
            REP(j, W){
                if(grid[i][j]=='#'){
                    int k = j;
                    while(k>=0 and not used[i][k]){
                        used[i][k] = cur;
                        k--;
                    }
                    k = j+1;
                    while(k<W and grid[i][k]=='.'){
                        used[i][k] = cur;
                        k++;
                    }
                    last = i;
                    ++cur;
                }
            }
            if(not used[i][0]) continue;
            int r = i - 1;
            while(r>=0 and not used[r][0]){
                REP(j, W) used[r][j] = used[r+1][j];
                r--;
            }
            last = i;
        }
        FOR(i, last+1, H){
            REP(j, W) used[i][j] = used[last][j];
        }
        REP(i, H){
            REP(j, W) out<<used[i][j]<<' ';
            out<<'\n';
        }
        out<<'\n';
    }
};


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


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

inline int next(void) {
	register int ret = 0;
	register int neg = false;
	register int bit = getchar();
	for (; bit < '0'; bit = getchar())
		if (bit == '-')neg ^= true;
	for (; bit >= '0'; bit = getchar())
		ret = ret * 10 + bit - '0';
	return neg ? -ret : ret;
}

int n, m;

int root;
int cmpk;

struct node {
	int id;
	int pos[2];
	int son[2];
	int min[2];
	int max[2];
	inline friend bool operator < 
		(const node &a, const node &b) {
			return a.pos[cmpk] < b.pos[cmpk];
	}
}tree[500005];

inline void update(int t) {
	for (int k = 0; k < 2; ++k) {
		tree[t].min[k] = tree[t].max[k] = tree[t].pos[k];
		for (int i = 0, s; i < 2; ++i)if (s = tree[t].son[i]) {
			if (tree[t].min[k] > tree[s].min[k])
				tree[t].min[k] = tree[s].min[k];
			if (tree[t].max[k] < tree[s].max[k])
				tree[t].max[k] = tree[s].max[k];
		}
	}
}

int build(int l, int r, int k) {
	int d = (l + r) / 2; cmpk = k;
	nth_element(tree + l, tree + d, tree + r + 1);
	tree[d].son[0] = l == d ? 0 : build(l, d - 1, k ^ 1);
	tree[d].son[1] = r == d ? 0 : build(d + 1, r, k ^ 1);
	return update(d), d;
}

inline void build(void) {
	for (int i = 1; i <= n; ++i) {
		tree[i].id = i - 1;
		tree[i].pos[0] = next();
		tree[i].pos[1] = next();
	}
	root = build(1, n, 0);
}

int st[2], ed[2], ans[500005], tot = 0;

inline bool judge(const node &t) {
	return t.pos[0] >= st[0]
		&& t.pos[0] <= ed[0]
		&& t.pos[1] >= st[1]
		&& t.pos[1] <= ed[1];
}

inline bool check(const node &t) {
	return t.min[0] <= ed[0]
		&& t.max[0] >= st[0]
		&& t.min[1] <= ed[1]
		&& t.max[1] >= st[1];
}

void query(int t) {
	if (judge(tree[t]))ans[tot++] = tree[t].id;
	if (tree[t].son[0] && check(tree[tree[t].son[0]]))query(tree[t].son[0]);
	if (tree[t].son[1] && check(tree[tree[t].son[1]]))query(tree[t].son[1]);
}

inline void query(void) {
	for (int i = 0; i < m; ++i, tot = 0) {
		st[0] = next();
		ed[0] = next();
		st[1] = next();
		ed[1] = next();
		tot = 0;
		query(root);
		sort(ans, ans + tot);
		for (int j = 0; j < tot; ++j)
			printf("%d\n", ans[j]);
		puts("");
	}
}

signed main(void) {
	n = next(); build();
	m = next(); query();
	//system("pause");
}

Measured memory_bytes: 20080
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][j] = max(dp[i+1][j], dp[i][k]+L[i][j])
print(max(dp[N]))


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

int main(){
	string str;
	cin >> str;
	if(str == "MON"){
		cout << 6 << endl;
	}
	if(str == "TUE"){
		cout << 5 << endl;
	}
	if(str == "WED"){
		cout << 4 << endl;
	}
	if(str == "THU"){
		cout << 3 << endl;
	}
	if(str == "FRI"){
		cout << 2 << endl;
	}
	if(str == "SAT"){
		cout << 1 << endl;
	}
	if(str == "SUN"){
		cout << 7 << endl;
	}
	return 0;
}

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

using namespace std;

int n;
vector<int> arr[100010];

void f(int x, int p, int d, int dis[])
{
    dis[x] = d;
    for(int y : arr[x])
        if(y != p)
            f(y, x, d + 1, dis);
}

int dis1[100010];
int disn[100010];

int main()
{
    int i;
    scanf("%d", &n);
    for(i = 0; i < n - 1; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        arr[x].push_back(y);
        arr[y].push_back(x);
    }

    f(1, 1, 0, dis1);
    f(n, n, 0, disn);

    int cnt1 = 0, cntn = 0;

    for(i = 1; i <= n; i++)
    {
        if(dis1[i] <= disn[i])
            cnt1++;
        else
            cntn++;
    }

    if(cnt1 > cntn)
        puts("Fennec");
    else
        puts("Snuke");

    return 0;
}

Measured memory_bytes: 12800
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
prev = -10
for i in A:
    ans += B[i-1]
    if i-prev==1:
        ans += C[prev-1]
    prev = i
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fastio
	ll n,t,i,j,x,k;
	cin>>n>>k;
	
	ll a[n],b[n],c;
	for(i=0;i<n;i++)
	cin>>a[i];
	
	for(i=0;i<n;i++)
	cin>>b[i];
	
	ll dp[n][5001];
	
	for(i=0;i<n;i++){
	    c=a[i];
	    dp[i][0]=0;
	    for(j=1;j<=5000;j++){
	       dp[i][j]=dp[i][j-1]+b[c-1];
	       c=a[c-1];
	    }
	}
	ll ans=-1e18;
	if(k<=5000){
	    for(i=0;i<n;i++)
	    ans=max(ans,*max_element(&dp[i][1],&dp[i][1]+k));
	}
	else{
	    vector<ll> cycle(n,1);
	    
	    for(i=0;i<n;i++){
	        c=a[i];
	        while(c!=i+1){
	            c=a[c-1];
	            ++cycle[i];
	        }
	    }
	    
	    ll mod,d;
	    for(i=0;i<n;i++){
	        d=k/cycle[i];
	        mod=k%cycle[i];
	        
	        ll l=-1e18,r=-1e18;
	        for(j=1;j<=mod;j++)
	        l=max(l,dp[i][j]);
	        for(j=1;j<=cycle[i];j++)
	        r=max(r,dp[i][j]);
	        
	        ans=max(ans,d*dp[i][cycle[i]]+l);
	        ans=max(ans,(d-1)*dp[i][cycle[i]]+r);
	        ans=max({ans,l,r});
	    }
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 199104
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int t = scan.nextInt();
		scan.close();

		int total = 1;


		while(true) {
			int a = x*total;
			if(n<=a) {
				break;
			}
			total++;
		}

		System.out.println(total*t);

	}

}


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

int main() {
  int x, y;
  cin >> x >> y;
  
  int count = 0;
  int num;
  int digits[5];
  for (int i = x; i <= y; i++) {
    num = i;
    for (int j = 0; j < 5; j++) {
      digits[j] = num % 10;
      num /= 10;
    }
    if (digits[0] == digits[4] && digits[1] == digits[3]) {
      count++;
    }
  }
  cout << count << endl;
}


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

const ll MOD = ll(1e9 + 7);
ll dp[2020][2020];
ll s[2020][2020];

ll modpow(ll x, ll y, ll m) {
	if(y == 0) return 1;
	ll res = modpow(x, y / 2, m);
	return res * res % m * (y & 1 ? x : 1) % m;
}

ll inv[2020];
ll modinv(ll x, ll m) {
	if(inv[x] != 0) return inv[x];
	return inv[x] = modpow(x, m - 2, m);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	for(int i = 1; i < 2020; i++) {
		inv[i] = modinv(i, MOD);
	}

	ll N, D, X;
	while(cin >> N >> D >> X, N) {
		X--;
		if(X == 0) {
			//cout << 0 << endl;
			//continue;
		}

		memset(dp, 0, sizeof dp);
		memset(s, 0, sizeof s);
		dp[0][0] = 1;
		for(int i = 0; i <= N; i++) {
			s[0][i + 1] = s[0][i] + dp[0][i];
		}

		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				int l = max(0LL, j - X);
				int r = j;
				dp[i][j] = (s[i - 1][r] - s[i - 1][l] + MOD) % MOD;
				s[i][j + 1] = (s[i][j] + dp[i][j]) % MOD;
			}
		}
		ll ans = 0;
		for(int i = 1; i <= min(N, D); i++) {
			if(dp[i][N] == 0) continue;
			ll comb = 1;
			for(ll j = 0; j < i; j++) {
				comb *= (D - j) % MOD;
				comb %= MOD;
			}
			for(ll j = 1; j <= i; j++) {
				comb *= inv[j];
				comb %= MOD;
			}
			ans += dp[i][N] * comb % MOD;
			ans %= MOD;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 66872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353
typedef vector<ll> vl;
typedef vector<vl> matrix;//A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Sortup(V) sort(V.begin(), V.end())
#define Sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll llpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}
bool bit(ll subset, ll Rsift){ return ((subset)>>(Rsift))&1; }

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

    // solution comes here

    ll N;
    cin >> N;
    vl a(N);
    rep(i, N) cin >> a[i];

    vl cnt(100100);
    rep(i, N) {
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        if(a[i]) cnt[a[i]-1]++;
    }

    ll ans=0;
    rep(i, 100010) chmax(ans, cnt[i]);
    cout << ans << nl;
}

Measured memory_bytes: 1792
import sys 

N = int(sys.stdin.readline())
K = int(sys.stdin.readline())
X = int(sys.stdin.readline())
Y = int(sys.stdin.readline())

#X* K + Y * (N-K)
# if N > K

#X * K
# if N < K

if N > K : 
    print X* K + Y *(N-K)
else:
    print X*N   

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

struct UnionFind{
    vector<ll> par;
    vector<ll> sizes;
    UnionFind(ll n) : par(n), sizes(n, 1) {
        rep(i,n) par[i] = i;
    }
    int find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return sizes[find(x)];
    }
};


ll a[100010];

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    UnionFind tree(n);

    rep(i, m){
        int x, y;
        cin >> x >> y;
        tree.unite(x, y);
    }

    if (m == n - 1) {
        cout << 0 << endl;
        return 0;
    }
    else if (n < 2*(n-m-1)){
        cout << "Impossible" << endl;
        return 0;
    }

    map<int, vector<ll>> mp;    
    rep(i, n) mp[tree.find(i)].push_back(a[i]);

    vector<multiset<ll>> vst;
    for(auto e : mp){
        multiset<ll> st;
        for(auto v : e.second) st.insert(v);
        vst.push_back(st);
    }

    ll ans = 0;

    int cnt = 0;

    multiset<ll> use;
    rep(i, n) use.insert(a[i]);

    int p = vst.size();

    for(auto s : vst){
        ans += *s.begin();
        use.erase(use.find(*s.begin()));
    }

    auto itr = use.begin();
    rep(i, 2*(n-m-1) - p){
        ans += *itr;
        itr++;
    }
    cout << ans << endl;

    return 0;
}


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

bool is_valid(int H, int W, vector<string> &A){
    vector<int> freq(26, 0);
    for (auto row : A){
        for (char a : row) ++freq[a - 'a'];
    }
    vector<int> type(4, 0);
    for (auto f : freq){
        ++type[f % 4];
    }
    int n1 = 0;
    int n2 = 0;
    if ((H & 1) and (W & 1)){
        n1 = 1;
        n2 = (H - 1) / 2 + (W - 1) / 2;
    }else if ((H & 1) and ((W % 2) == 0)){
        n1 = 0;
        n2 = W / 2;
    }else if (((H % 2) == 0) and (W & 1)){
        n1 = 0;
        n2 = H / 2;
    }else{
        n1 = 0;
        n2 = 0;
    }
    if (type[1] + type[3] > n1){
        return false;
    }else{
        n2 -= type[3];
    }
    if (type[2] > n2){
        return false;
    }
    return true;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    for (auto &row : A) cin >> row;
    if (is_valid(H, W, A)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 1;
    repd(i, 1, n) {
        if (s[i] != s[i - 1]) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, k; cin >> n >> k;
    ll zero = 0;
    ll half = 0;
    ll ans = 1;
    if(k % 2 == 1){
        for(int i = 1; i <= n; ++i){
            if(i % k == 0)zero++;
        }
        rep(i,3) ans *= zero;
    }else{
        for(int i = 1; i <= n; ++i){
            if(i % k == 0) zero++;
            if(i % k == k/2) half++;
        }
        ans = zero*zero*zero + half*half*half;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
INFTY = 1e6
N,M = map(int,input().split())
G = {}
for _ in range(M):
    a,b = map(int,input().split())
    if a not in G:
        G[a] = []
    G[a].append(b)
    if b not in G:
        G[b] = []
    G[b].append(a)
d = [INFTY for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
heap = [(0,1)]
d[1] = 0
while heap:
    cur = heapq.heappop(heap)
    hist[cur[1]] = 1
    for x in G[cur[1]]:
        if hist[x]==0:
            if d[x]>cur[0]+1:
                d[x] = cur[0]+1
                heapq.heappush(heap,(d[x],x))
if d[N]==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main(){
  string s;
  cin >> s;
  int count=0;
  int count2=0;
  if(s[0]!='A'){
    cout << "WA" << endl;
    return 0;
  }
  if(s[1]>='A' && s[1]<='Z')
    count2++;
  for(int i=2;i<s.size()-1;i++){
    if(s[i]=='C')
      count++;
    if(s[i]>='A' && s[i]<='Z')
      count2++;
  }
  if(s[s.size()-1]>='A' && s[s.size()-1]<='Z')
    count2++;
  if((count==1)&&(count2==1)){
    cout << "AC" << endl;
    return 0;
  }
  cout << "WA" << endl;
  return 0;

}

Measured memory_bytes: 256
S = input()
r_S = S[::-1]
devide = ["dream", "dreamer", "erase", "eraser"]
r_devide = [d[::-1] for d in devide]
string = r_S

while string != '':
  can = False
  for d in r_devide:
    if string[:len(d)] == d:
      can = True
      string = string[len(d):]
  if can == False:
    break

if can:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in2(a, b);
  if(a < 6)
    c = 0;
  else if(a < 13)
    c = b / 2;
  else
    c = b;
  out(c);
  memi;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define int long long int
using namespace std;

signed main()
{
	int n,k;
	while(cin>>n>>k,n){
	
	int a[100000];
	for(int i=0;i<n;i++)cin>>a[i];
	
	int s=0;
	for(int i=0;i<k;i++)s+=a[i];
	int ma=s;
	for(int i=k;i<n;i++)
	{
		s-=a[i-k];
		s+=a[i];
		ma=max(ma,s);
	}
	cout<<ma<<endl;}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int A, B;
    cin >> A >> B;
    int K = abs(A - B);
    if(K % 2 != 0) {
        printf("IMPOSSIBLE\n");
        return 0;
    }

    printf("%lld\n", min(A, B) + K / 2);

    return 0;
}


Measured memory_bytes: 256
#全点対最短路
def wf(d,v):
    for k in range(v):
        for i in range(v):
            for j in range(v):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]

l = [0 for _ in range(10)]
for i in a:
    for j in i:
        if j != -1:
            l[j]+=1

s = [i[1] for i in wf(c,10)]

ans = 0
for i in range(len(l)):
    if i != 1:
        ans+=s[i] * l[i]

print(ans)


Measured memory_bytes: 40284
// =====================================================================================
// 
//       Filename:  E.cpp
//        Created:  2017년 08월 06일 22시 04분 27초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
pair<int, int> even[400005];
pair<int, int> odd[400005];
int arr[200005];
int n;
int sz;
const int inf=0x3f3f3f3f;
void update(int idx, pair<int, int> val, pair<int, int> *tree){
	idx+=sz;
	while(idx){
		tree[idx]=min(tree[idx], val);
		idx/=2;
	}
}
pair<int, int> query(int a, int b, pair<int, int> *tree){
	pair<int, int> ret={inf, inf};
	a+=sz;
	b+=sz;
	while(a<=b){
		if(a&1)
			ret=min(ret, tree[a++]);
		if(!(b&1))
			ret=min(ret, tree[b--]);
		a/=2;
		b/=2;
	}
	return ret;
}
int loc[200005];
void calc(int le, int ri, priority_queue<pair<pair<int, int>, pair<int, int> > > &pq){
	if(le>=ri+1)
		return;
	if(le&1){
		int left=le/2;
		int right=ri/2;
		auto l=query(left, right-1, odd);
		auto r=query(l.second/2+1, right, even);
		pq.push({{-l.first, -r.first}, {le, ri}});
		return;
	}	
	int left=le/2;
	int right=ri/2;
	auto l=query(left, right, even);
	auto r=query(l.second/2, right, odd);
	pq.push({{-l.first, -r.first}, {le, ri}});
}
int main(){
	memset(even, 0x3f, sizeof(even));
	memset(odd, 0x3f, sizeof(odd));
	scanf("%d", &n);
	sz=1;
	while(sz<n/2)sz*=2;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d", &x);
		arr[i]=x;
		loc[x]=i;
		int idx=i/2;
		if(i&1)
			update(idx, {x, i}, odd);		
		else
			update(idx, {x, i}, even);
	}
	vector<pair<int, int> > ans;
	priority_queue<pair<pair<int, int>, pair<int, int> > >pq;
	calc(0, n-1, pq);
	while(!pq.empty()){
		int a=-pq.top().first.first;
		int b=-pq.top().first.second;
		int le=pq.top().second.first;
		int ri=pq.top().second.second;
		pq.pop();
		ans.push_back({a, b});
		calc(le, loc[a]-1, pq);
		calc(loc[a]+1, loc[b]-1, pq);
		calc(loc[b]+1, ri, pq);
	}
	for(int i=0;i<ans.size();i++)
		printf("%d %d ", ans[i].first, ans[i].second);
	printf("\n");
	return 0;
}



Measured memory_bytes: 10868
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int count = 0;

    for(int i = A; i <= B; i++){
        string s = to_string(i);
        if(s[0] == s[4] && s[1] == s[3]){
            count++;
        }
    
    }

    cout << count <<endl;


}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	s <- getLine
	let
		l = length s
		prefix = take ( l `div` 2 ) s
		suffix = drop ( l `div` 2 + 1 ) s
	putStrLn $ if isPal s && isPal prefix && isPal suffix
		then "Yes"
		else "No"

isPal s = s == reverse s

Measured memory_bytes: 508
N, P = map(int, input().split())
if N == 1:
  print(P)
else:
  A, n = [], N
  while n != 0:
    A = [n%2] + A[:]
    n //= 2
  M = int(round(P ** (1/N)))
  g = 1
  for i in range(1, M+1):
    t = 1
    for j in range(len(A)):
      if A[j] == 1:
        t *= i
      if j != len(A) - 1:
        t *= t
    if P % t == 0:
      g = i
  print(g)

Measured memory_bytes: 3188
use std::cmp::max;
use std::cmp::min;
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

const MAX_W: usize = 1_000_000_000;

struct Input {
    n: usize,
    w: usize,
    wv: Vec<Vec<usize>>,
}

fn read_input(cin_lock: &mut StdinLock) -> Input {
    let n = next_token(cin_lock);
    let w = next_token(cin_lock);
    let wv = (0..n)
        .map(|_| (0..2).map(|_| next_token(cin_lock)).collect())
        .collect();
    Input { n, w, wv }
}

fn solve(input: Input) {
    let sum_v = input.wv.iter().fold(0, |acc, wv| acc + wv[1]);

    let mut dp = vec![vec![MAX_W + 1; sum_v + 1]; 2];
    dp[0][0] = 0;

    for i in 0..input.n {
        let ci = i % 2;
        let ni = (i + 1) % 2;
        let w = input.wv[i][0];
        let v = input.wv[i][1];

        for j in 0..sum_v + 1 {
            dp[ni][j] = min(dp[ci][j], if j < v { MAX_W } else { dp[ci][j - v] + w })
        }
    }
    println!(
        "{}",
        dp[input.n % 2].iter().enumerate().fold(0, |max_v, (v, w)| {
            if *w > input.w {
                max_v
            } else {
                max(max_v, v)
            }
        })
    )
}

fn next_token<T: FromStr>(cin_lock: &mut StdinLock) -> T {
    cin_lock
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>()
        .ok()
        .unwrap()
}

fn main() {
    let cin = stdin();
    let mut cin_lock = cin.lock();
    let input = read_input(&mut cin_lock);
    solve(input);
}


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

int main()
{
    int x;
    scanf("%d",&x);
   for(int i=1; i<=360; i++)
   {
    if((x*i)%360==0)
    {
        printf("%d\n",i);
        break;
    }
   }
}

Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;
int main()
{
	string yn[2] = { "YES","NO" };
	int a, b, c,x=1;
	cin >> a >> b >> c;
	if (b - a == c - b) x = 0;
	cout << yn[x] << endl;
    return 0;
}

Measured memory_bytes: 256
// ABC 158-C
// 2020.3.7 bal4u

#include <stdio.h>

int main()
{
	int A, B, ans;

	scanf("%d%d", &A, &B);
	for (ans = 1; ans <= 1000; ++ans) {
		if ((ans*108/100-ans) == A && (ans*110/100-ans) == B) {
			printf("%d\n", ans);
			return 0;
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 200005
#define ll long long
#define pb push_back
using namespace std; 
int fa[N],n;
ll ans,a[N],m;
struct node
{
	int L,R;
	ll val;
	node(ll x,int y,int z){val=x,L=y,R=z;}
	bool operator < (const node &x) const
	{
		if(val!=x.val)return val<x.val;
		if(L!=x.L)return L<x.L;
		return R<x.R;
	}
};
int search(int x)
{
	if(fa[x]==x)return x;
	return fa[x]=search(fa[x]);
}
vector<node> v;
void solve(int l,int r)
{
	if(l==r)return;
	int mid=(l+r)>>1,min_l,min_r;
	ll mn=-1;
	for(int i=l;i<=mid;i++)
	{
		ll value=a[i]-m*(ll)i;
		if(mn==-1||mn>value)
		min_l=i,mn=value;
	}
	mn=-1;
	for(int i=mid+1;i<=r;i++)
	{
		ll value=a[i]+m*(ll)i;
		if(mn==-1||mn>value)
		min_r=i,mn=value;
		ll tmp=a[i]+a[min_l]+m*(ll)(i-min_l);
		v.pb(node(tmp,min_l,i));
	}
	for(int i=l;i<=mid;i++)
	{
		ll tmp=a[i]+a[min_r]+m*(ll)(min_r-i);
		v.pb(node(tmp,i,min_r));
	}
	solve(l,mid);
	solve(mid+1,r);
}
int main()
{
    for(int i=0;i<N;i++)
    fa[i]=i;
	scanf("%d%lld",&n,&m);
	for(int i=0;i<n;i++)
	scanf("%lld",a+i);
	solve(0,n-1);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		
		int x=search(v[i].L),y=search(v[i].R);
		if(x==y)continue;
		ans+=v[i].val;
		fa[x]=y;
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

  vector<int> acl(n), acr(n);
  for (int i = 1; i < n; i++) {
    acl[i] = acl[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C') {
      acl[i]++;
    }

    int j = n - 1 - i;
    acr[j] = acr[j + 1];
    if (s[j] == 'A' && s[j + 1] == 'C') {
      acr[j]++;
    }
  }

  int total = acl[n - 1];

  vector<int> ans(q);
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    ans[i] = total - acl[l] - acr[r];
  }

  rep(i, q) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 2176