akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, T;
    cin >> n >> T;

    vl t(n);
    rep(i, n) {
        cin >> t[i];
    }

    ll ans = 0;
    rep(i, n-1) {
        ans += min(t[i+1] - t[i], T);
    }
    ans += T;
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)

int main() {
    ll n, k;
    cin >> n >> k;

    ll a = n % k;
    ll b = abs(a - k);

    ll ans = min(a, b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Edge{
		int from;
		int to;
		long cost;
		Edge(int from, int to, long cost){
			this.from=from;
			this.to=to;
			this.cost=cost;
		}
	}

	ArrayList<Edge> es;
	long INF = Long.MAX_VALUE;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		es = new ArrayList<>();

		for(int i=0; i<m; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			a--;b--;
			long c=sc.nextInt();
			c = -c;
			es.add(new Edge(a,b,c));
		}

		long dist[] = new long[n];
		for(int i=0; i<n; i++) {
				dist[i]=INF;
		}
		dist[0]=0;

		boolean negative[] = new boolean[n];
		for(int i=0; i<n-1; i++) {
			for(int j=0; j<es.size(); j++) {
				Edge e = es.get(j);
				if(dist[e.from] == INF) continue;
				if(dist[e.to] > dist[e.from] + e.cost) {
					dist[e.to] = dist[e.from]+ e.cost;
				}
			}
		}

		for(int i=0; i<es.size(); i++) {
			Edge e = es.get(i);
			if(dist[e.from] == INF) continue;
			if(dist[e.to] > dist[e.from] + e.cost) {
				dist[e.to] = dist[e.from] + e.cost;
				negative[e.to]=true;;
			}
			if(negative[e.from]) {
				negative[e.to]=true;
			}
		}
		if(negative[n-1]) {
			System.out.println("inf");
		}else {
			System.out.println(-dist[n-1]);
		}
		sc.close();
	}



}


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

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

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    static const double pi = 3.141592653589793;
    ll n;
    cin >> n;
    vll x(n), y(n);
    REP(i,n) cin >> x[i] >> y[i];

    ll xs, ys;
    double xp, yp, ans=0, tmp=0;
    REP(t,120){
        xp = cos(t*pi/60);
        yp = sin(t*pi/60);
        xs = 0;
        ys = 0;
        REP(i,n) if(xp*x[i]+yp*y[i]>0){
            xs += x[i];
            ys += y[i];
        }
        tmp = sqrt(xs*xs+ys*ys);
        if(ans<tmp) ans = tmp;
    }

    cout << fixed << setprecision(30);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<vector<int>> edge(N,vector<int>());
    if(N%2==0){
        // すべての頂点間に辺を張ると　N*(N-1)/2
        // 頂点番号が足してN+1になるペア間の辺を除く
        cout << N*(N-1)/2 - N/2 << endl;
        for(int i=1;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                if(i+j==(N+1)) continue;
                edge[i].push_back(j);
            }
        }
    }else{
        // 偶数の時と同じことをNを除いて行う
        // 最後にすべての頂点に対してNから辺を張ればOK
        cout << (N-1)*(N-2)/2 - (N-1)/2 + N-1 << endl;
        for(int i=1;i<=N-1;i++){
            for(int j=i+1;j<=N-1;j++){
                if(i+j==(N)) continue;
                edge[i].push_back(j);
            }
            edge[i].push_back(N);
        }
    }
    for(int i=1;i<N;i++){
        for(int j=0;j<edge[i].size();j++){
            cout << i << " " << edge[i][j] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	int a[n];
	REP(i,n) cin >> a[i];
	int num[100000] = {};
	REP(i,n) num[a[i]]++;
	int ans = 0;
	REP(i,99998) ans = max(ans, num[i] + num[i + 1] + num[i + 2]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long

int main()
{
    ll n;
    cin >> n;
    ll n3 = n / 3;
    ll n5 = n/5;
    ll n15 = n / 15;
    ll nsum = n * (n + 1) / 2;
    ll n3sum = 3 * n3 * (n3 + 1) / 2;
    ll n5sum = 5 * n5 * (n5 + 1) / 2;
    ll n15sum = 15 * n15 * (n15 + 1) / 2;
    cout << nsum - n3sum - n5sum + n15sum << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
set<int> s;
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int x, y;
		scanf("%d%d",&x,&y);
		if(x == 0)
		{
			s.insert(y);
			printf("%d\n",s.size());
		}
		if(x == 1) printf("%d\n",s.count(y));
		if(x == 2) s.erase(y);
		if(x == 3)
		{
			int l, r;
			l = y;
			scanf("%d",&r);
			set<int>::iterator it, it2;
			it = s.lower_bound(l);
			it2 = s.upper_bound(r);
			for(; it!=it2; it++) printf("%d\n",*it);
		}
	}
	return 0;
}


Measured memory_bytes: 12584
N = int(input())
A = [int(x) for x in input().split()]
plus = [x for x in A if x > 0]
minus = [x for x in A if x <= 0]
plus.sort()
minus.sort()
minA = minus.pop() if minus else plus.pop(0)
M = sum(plus) - sum(minus)
M += -minA if plus else minA
print(M)
xy = minA
for i in range(N - 1):
  if len(plus) > 1:
    y = plus.pop()
    print('{} {}'.format(xy, y))
    xy -= y
  elif len(plus) == 1:
    x = plus.pop()
    print('{} {}'.format(x, xy))
    xy = x - xy
  else:
    y = minus.pop()
    print('{} {}'.format(xy, y))
    xy -= y

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<int> maxshape(h,0);
    vector<int> minshape(h,w);
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            if(s[j] == '#') {
                minshape[i] = min(minshape[i], j);
                maxshape[i] = max(maxshape[i], j);
            }
        }
    }

    bool ans = true;
    rep(i, h-1) {
        if(minshape[i+1] < maxshape[i]) {
            cout << "Impossible" << endl;
            return 0;
        }
    }

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


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}
	
	int u, v, last;
}edge[MAXN*2];

int n;
int ke, la[MAXN];
int deg[MAXN];
bool dp[MAXN];
bool isl[MAXN];
int lev[MAXN], fa[MAXN];
AR(int) ar[MAXN];

void init ();
void input ();
void work ();

void dfs ( int now, int nf, int nl )
{
	lev[now] = nl;
	fa[now] = nf;
	for ( int i = la[now]; ~i; i = edge[i].last ) if ( edge[i].v ^ nf ) dfs ( edge[i].v, now, nl+1 );
}



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	int u, v;
	INIT ( la, -1 );
	lp ( i, 1, n ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
		++deg[u], ++deg[v];
	}
}

void work ()
{
	// main work
	
	if ( n == 2 ){
		cout << "Second" << endl;
		return;
	}
	
	lpi ( i, 1, n ) if ( la[edge[i].v] == -1 ) isl[i] = true;
	
	lpi ( i, 1, n ){
		if ( deg[i] > 1 ){
			dfs ( i, -1, 1 );
			break;
		}
	}
	
	lpi ( i, 1, n ) ar[lev[i]].PB ( i );
	
	int c0, c1;
	lpd ( i, n, 0 ){
		for ( auto x : ar[i] ){
//			cerr << x << endl;
			if ( !isl[x] ){
				c0 = c1 = 0;
				for ( int j = la[x]; ~j; j = edge[j].last ){
					if ( edge[j].v ^ fa[x] ){
						if ( dp[edge[j].v] ) ++c1;
						else ++c0;
					}
				}
				if ( c0 > 1 ){
					cout << "First" << endl;
					return;
				}
				dp[x] = c0 ? true : false;
			}
		}
	}
	
	cout << ( dp[ar[1][0]] ? "Second" : "First" ) << endl;
}

Measured memory_bytes: 7296
N = int(input())
tmp = input().split()
X = [0]*N
for n in range(N):
    X[n] = int(tmp[n])

souwa = [0]*100
for p in range(100):
    tairyoku = 0
    for n in range(N):
        tairyoku += (X[n]-p+1)**2
    souwa[p] = tairyoku

min_value = min(souwa)
min_index = souwa.index(min_value)

print(souwa[min_index])

Measured memory_bytes: 3064
#a,b = (int(i) for i in input().split())
def kouyaku(a,b):
    if a<b:
        temp = a
        a = b
        b = temp
    if b == 0:
        return a
    r = a%b
    if r == 0:
        return b
    else:
        return kouyaku(b,r)

if __name__ == "__main__":
    a,b = (int(i) for i in input().split())
    s = kouyaku(a,b)
    if s == 1:
        print(1)
        exit()
    ans = 1
    t = s
    for i in range(2, int(t**0.5)+1):
        if s == 1: 
            break
        if s%i == 0:
            ans += 1
            while s%i == 0:
                s = s/i
    if s>int(t**0.5):
        ans += 1
    print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n, x, t;
	cin >> n >> x >> t;

	int ans = n / x * t;

	if (n % x != 0) {
		ans += t;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    int h, w;
    
    while(1){
        cin >>h >>w;
        if((h == 0) &&(w == 0)){
            break;
        }
        for(int i = 1;i <= h;i++){
            for(int j = 1;j <= w;j++){
                if(i % 2 == 1){
                    if(j % 2 == 1){
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                }else {
                   if(j % 2 == 1){
                        cout << ".";
                    } else {
                        cout << "#";
                    } 
                }
            }
            cout << endl; 
        }
        cout <<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define mn 100005
#define inf 4444444444444444444
#define mod (ll) 1000000007
#define base 31
#define fi first
#define se second
#define pii pair <int, int>
#define pb push_back
#define mp make_pair

//int t, ntest;
int n, k, ans;
int a[55], dp[55][55][2505];

void input(){
	cin>>n>>k;
	for (int i=1; i<=n; i++) {
		cin>>a[i];
	}
}

// i so dau tien, chon j so, tong la t
int d (int i, int j, int t){
	if (j>i) return 0;
	if (j<0 || i<0 || t<0) return 0;
	if (t==0){
		if (j==0) return 1;
		return 0;
	}
	if (j==0 && t!=0) return 0;
	if (dp[i][j][t]<inf) return dp[i][j][t];
	return dp[i][j][t]=d(i-1, j, t)+d(i-1, j-1, t-a[i]);
}

void output(){

}

void solve(){
	for (int i=1; i<=n; i++){
		for (int j=1; j<=n; j++){
			for (int t=1; t<=2500; t++){
				dp[i][j][t]=inf;
			}
		}
	}
	for (int i=1; i<=n; i++){
		ans+=d(n, i, k*i);
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
//	cin>>t;
//	for (ntest=1; ntest<=t; ntest++){
		input();
		solve();
		output();
//	}
}

//mtrang_149


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

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int n = r * 100 + 10 * g + b;
    if(n % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 500;
int field[N + 5][N + 5];

const int MULTI = 2300;

void hora(int tc) {
	int R, C, r, c;
	cin>>R>>C>>r>>c;
	ll total = 0;
	for(int i = 1;i <= R;i++) {
		for(int j = 1;j <= C;j++) {
			if(i % r == 0 && j % c == 0) field[i][j] = -(r * c - 1) * MULTI - 1;
			else field[i][j] = MULTI;
			total += field[i][j];
		}
	}
	if(total > 0) {
		cout<<"Yes"<<endl;
		for(int i = 1;i <= R;i++) {
			for(int j = 1;j <= C;j++) {
				if(j != 1) cout<<" ";
				cout<<field[i][j];
			}
			cout<<endl;
		}
	} else cout<<"No"<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 2560
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

a,b,c = getlist()
m = max([a,b,c])
print(10*m + a+ b+ c -m)

Measured memory_bytes: 3316
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
//const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll MOD = 998244353;
ll modpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return res % MOD;
}
ll factorial[201000];
ll invfactorial[201000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD; 
	return ret;
}
int main(void){

    factorial[0] = 1;

    for (int i = 1; i < 201000; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (int i = 0; i < 201000; i++){
        ll x, y;
        ll g = extGCD(factorial[i], MOD, x, y);
        while (x < 0) x += MOD;
        x %= MOD;
        invfactorial[i] = x;
    }

    ll n, m, k;
    cin >> n >> m >> k;

    ll sample = (m % MOD) * modpow(m - 1, n - 1);
    ll ans = sample % MOD;
    for(ll i = 1; i <= k; i++){
        ll tmp = m * modpow(1, i) * modpow(m - 1, n - i - 1);
        tmp %= MOD;
        tmp *= nCrM(n - 1, i);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    //cout << sample % MOD << endl;
    cout << ans << endl;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    string graph[h];
    for (int i = 0; i < h; i++) {
        cin >> graph[i];
    }
    pair<int, int> current;
    while (current != make_pair(h - 1, w - 1)) {
        graph[current.first][current.second] = '.';
        if (current.first + 1 < h && graph[current.first + 1][current.second] == '#') {
            current.first++;
        } else if (current.second + 1 < w && graph[current.first][current.second + 1] == '#') {
            current.second++;
        } else {
            break;
        }
    }
    graph[h - 1][w - 1] = '.';
    bool result = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (graph[i][j] == '#') {
                result = false;
            }
        }
    }
    if (result) {
        cout << "Possible";
    } else {
        cout << "Impossible";
    }
    return 0;
}

Measured memory_bytes: 256
n,W=map(int,input().split())
w_list=[]
v_list=[]
dp=[]
for i in range(n):
    w,v=map(int,input().split())
    w_list.append(w)
    v_list.append(v)
for i in range(n):
    dp_sub=[]
    for j in range(W+1):
        dp_sub.append(-1)
    dp.append(dp_sub)
dp_sub=[]
for j in range(W+1):
    dp_sub.append(0)
dp.append(dp_sub)
for i in range(n):
    i_=n-1-i
    for j in range(W+1):
        if w_list[i_]<=j:
            dp[i_][j]=max(dp[i_+1][j],dp[i_+1][j-w_list[i_]]+v_list[i_])
        else:
            dp[i_][j]=dp[i_+1][j]
print(dp[0][W])




Measured memory_bytes: 142540
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

#define N 100000
int main(void){
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans=0;
    vector<int>::iterator it;
    for(int i=0;i<n;i++){
        it=lower_bound(a.begin(),a.end(),b[i]);
        ll x,y;
        x=it-a.begin();
        it=upper_bound(c.begin(),c.end(),b[i]);
        y=c.end()-it;
        //cout<<x<<" "<<y<<endl;
        ans+=x*y;
        
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 404, mod = (119<<23)+1, lg = 19;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vi a(n);
	for(auto &i : a) cin >> i;
	int ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < i; j++) ans += a[j]*a[i];cout << ans;
	return 0;
}


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

int main(){
    int n,n2,m=0;
    cin >> n;
    n2=n;
    while(n>0){
        m=m+n%10;
        n=n/10;
    }
    if(n2%m==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
m=list(map(int,input().split()))
k=sum(l)
for i in range(n):
    if l[i]+l[i+1]<=m[i]:
        l[i]=0
        l[i+1]=0
    elif l[i]>=m[i]:
        l[i]-=m[i]
    else:
        l[i+1]=l[i]+l[i+1]-m[i]
        l[i]=0
print(k-sum(l))

Measured memory_bytes: 82020
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

//----------------------------------------



int main(void)
{
	int k, x;
	cin >> k >> x;

	int up = min(1000000, x + k - 1);
	int down = max(-100000, x - k + 1) ;



	for (int i = down; i <= up; i++)
	{
		cout << i << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    in_file     freopen("input.txt", "r", stdin)
#define    out_file    freopen("output.txt", "w", stdout)
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    sp          fixed<<setprecision
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    fora(i,n)   for(int (i)=0; (i) < (n); (i)++)


int Int(){int x;scanf("%d", &x);return x;}

#define    Int         Int()
#define    mx          100010

void dhimanda();
int main()
{
    //fast;
    //in_file;
    //out_file;
    int t=1;
    //t=Int;
    forr(i,1,t){
        //printf("Case %d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    double n;
    cin >> n ;
    cout << sp(2) << 2*pi*n <<endl;
}

// Contact : chessdhiman@gmail.com


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
const int N=1e4;
    int n,s;
	int a[N];
int main()
{
  cin>>n;
  n*=2;
  for (int i=0;++i<=n;) cin>>a[i];
  sort(a+1,a+n+1);
  for (int i=1;i<=n;i+=2) s+=a[i];
  cout<<s;
  return 0;
}




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

typedef long long ll;
#define vi vector<int>
#define mii map<int,int>

int main() {
	int N,A;
	cin >> N;
	mii m;
	for(int i=0;i<N-1;i++){
		cin >> A;
		m[A]++; 
	}
	for(int i=1;i<=N;i++) {
		cout << m[i] << "\n";
	}
}


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

int main(){
	int n;
    ll sum;
  vector<ll> abc(3);
  cin >> n >> abc[0] >> abc[1] >> abc[2];
  sum = abc[0] + abc[1] + abc[2];
  
  vector<string> s(n);
  bool can = true;
  vector<char> res(n);
  rep(i, n){ cin >> s[i];}
  
  if(sum != 1 && sum != 2 ){
  rep(i, n){
    int m = s[i][0] - 'A';
    int l = s[i][1] - 'A';

    if(abc[m]==0 && abc[l]==0){ can = false; break;}
    if(abc[m]==0){
        res[i] = s[i][0];
        abc[m] += 1, abc[l] -= 1;}
    else if(abc[l]==0){
              res[i] = s[i][1];
        abc[m] -= 1, abc[l] += 1;}
    else if(abc[m]==1){
        res[i] = s[i][0];
        abc[m] += 1, abc[l] -= 1;}
    else if(abc[l]==1){
              res[i] = s[i][1];
        abc[m] -= 1, abc[l] += 1;}
    else{
        res[i] = s[i][0];
        abc[m] += 1, abc[l] -= 1;}
   	}
  }
  if(sum == 1 || sum == 2 ){
    rep(i, n){
    int m = s[i][0] - 'A';
    int l = s[i][1] - 'A';
	if(abc[m]==0 && abc[l]==0){ can = false; break;}
    if(abc[l]==0){
              res[i] = s[i][1];
        abc[m] -= 1, abc[l] += 1;}
    else if(abc[m]==0){
        res[i] = s[i][0];
        abc[m] += 1, abc[l] -= 1;}
    else{
    	if(i != n-1){
          if(s[i] == s[i+1]){
                       res[i] = s[i][0];
          			   abc[m] += 1, abc[l] -= 1;}
          else{   
         			int m_1 = s[i+1][0] - 'A';
        		    int n_1 = s[i+1][1] - 'A';
			int d = m + l + m_1 + n_1 - 3;
            res[i] = char(d + 'A');
            abc[d] += 1, abc[m+l-d] -= 1;
          }}
 		if(i == n-1){
                       res[i] = s[i][0];
          			   abc[m] += 1, abc[l] -= 1;}
        }

    }}

  if(can){ cout << "Yes" << endl;
    rep(i, n){ cout << res[i] << endl;}}
  else{ cout << "No" << endl;}
      
    return 0;    
}

Measured memory_bytes: 6368
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
lst1.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if lst1[i]+lst1[j] > lst1[k] and lst1[i] != lst1[j] and \
                lst1[i] != lst1[k] and lst1[j] != lst1[k]:
                ans += 1
"""import itertools

for i,j,k in itertools.combinations([i for i in range(n)],3):
    if lst1[i] + lst1[j] > lst1[k]:
        ans += 1"""
print(ans)

Measured memory_bytes: 68112
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    X = I()

    i = 0
    while i**5<X:
        i += 1
    
    B = -(i-1)
    while True:
        A = int((B**5+X)**0.2)
        if A**5==B**5+X:
            break
        B += 1

    print(A, B)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,n,K=1,X;cin>>N;n=N;
  while(n>9){n/=10;K++;}X=n+1;
  for(long long int i=1;i<K;i++)X*=10;
  if(N==X-1)cout<<n+9*K-9<<endl;
  else cout<<n+9*K-10<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

Graph G;
vector<bool> seen;
vector<int> dp;
vector<bool> val;

int dfs(int v) {
    if(seen[v]) {
        if(val[v] == false)
            return -1;
        return dp[v];
    }
    seen[v] = true;
    dp[v] = 1;
    for(auto nextv : G[v]) {
        int tmp = dfs(nextv);
        if(tmp == -1)
            return -1;
        dp[v] = max(dp[v], tmp + 1);
    }
    val[v] = true;
    return dp[v];
}

int main() {
    int N, ans = 0;
    cin >> N;
    Graph A(N, vector<int>(N - 1));
    int vsize = N * (N - 1) / 2;
    G.resize(vsize);
    seen.resize(vsize);
    dp.resize(vsize);
    val.resize(vsize);

    vector<vector<int>> num(N, vector<int>(N));
    int n = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            if(i < j) {
                num[i][j] = n;
                n++;
            }
        }
    }

    int a = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N - 1; ++j) {
            cin >> A[i][j];
            A[i][j]--;
            if(i < A[i][j])
                A[i][j] = num[i][A[i][j]];
            else
                A[i][j] = num[A[i][j]][i];
            if(j > 0)
                G[A[i][j]].push_back(A[i][j - 1]);
        }
    }
    for(int i = 0; i < vsize; ++i) {
        int tmp = dfs(i);
        if(tmp == -1) {
            ans = -1;
            break;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 37632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
bool prime(ll n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
signed main() {
	string s;
	cin >> s;
	if (s[5] == '0' && (s[6] == '4' || s[6] == '3' || s[6] == '2' || s[6] == '1'))puts("Heisei");
	else puts("TBD");
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define ll long long
int main() {
    int n;
    cin>>n;
    int ar[n];
    int a[n];int a2[n];
    int c=0;
    REP(i,n)
    cin>>ar[i];
    REP(i,n)
    cin>>a[i];
    REP(i,n-1)
    cin>>a2[i];
    REP(i,n)
   c+=a[ar[i]-1];
   REPS(i,n-1)
   {
       if(ar[i]==ar[i-1]+1)
       c+=a2[ar[i-1]-1];
   }
   cout<<c<<endl;
}

Measured memory_bytes: 3632
N=int(input())
l=[int(x) for x in input().rstrip().split()]
rate=[False]*8
cnt=0
for i in l:
    if 8<=i//400:
        cnt+=1
        continue

    rate[i//400]=True


if sum(rate)==0:
    print(1,cnt)
else:
    print(sum(rate),sum(rate)+cnt)


Measured memory_bytes: 3060
import java.security.SecureRandom;
import java.sql.Array;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       long x=sc.nextLong();
        long k=sc.nextLong();
        long d=sc.nextLong();
        x=Math.abs(x);
        if (x/d>=k) System.out.println((x-k*d));
        else{
            k-=x/d;
            x-=(x/d)*d;
            if (k%2==0){
                System.out.println(x);
            }
            else{
                System.out.println(Math.abs((x-d)));
            }
        }
    }

}

Measured memory_bytes: 35688
# coding: utf-8

A, B, C, X, Y = map(int, input().split())

ans = 0

pt1 =(A*X)+(B*Y)
pt2 = 2*C*max(X,Y)
pt3 = 2*C*min(X,Y)+((A*(X-Y)) if X>Y else B*(Y-X))

print(min(pt1,pt2,pt3))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define input(x) x; cin >> x;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
  int input(a);
  int input(b);
  if(!(a % 3) || !(b % 3) || !((a + b) % 3)){
    p("Possible");
  }else p("Impossible");
}

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

int main()
{
    int H = 0;
    int W = 0;
    while(1)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
            break;
        else
        {
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                    cout << "#";
                cout << endl;
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

using namespace std;

int main(void){
    int M[2], D[2];
    cin >> M[0] >> D[0];
    cin >> M[1] >> D[1];
    
    if((M[0] + 1 == M[1]) || (M[0] == 12 && M[1] == 1)) cout << 1;
    else cout << 0;

    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> uft;

ll parent(ll w){return uft[w]==w?w:uft[w]=parent(uft[w]);}

void merge(ll a,ll b){uft[parent(a)]=parent(b);}

int main(){
    ll n,m;
    cin>>n>>m;
    uft.resize(n);
    ll ans=n;
    for(int i=0;i<n;i++){uft[i]=i;}
    for(int i=0;i<m;i++){
        ll u,v,a;
        cin>>u>>v>>a;
        u--; v--;
        if(parent(u)!=parent(v)){
            ans--;
            merge(u,v);
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,ans=0;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    cin>>v[i];
    for(int i=1;i<n-1;i++){
      if((v[i]>v[i+1]&&v[i]<v[i-1])||(v[i]<v[i+1]&&v[i]>v[i-1]))
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t)(M));
    long[] B = new long[](cast(size_t)(M));
    foreach (i; 0 .. cast(size_t)(M))
    {
        A[i] = input.front.to!long;
        input.popFront;
        B[i] = input.front.to!long;
        input.popFront;
    }

    solve(N, M, A, B);
}

void solve(long N, long M, long[] A, long[] B)
{
    auto uf = UnionFind(N);
    A[] -= 1;
    B[] -= 1;
    foreach (i; 0 .. M)
    {
        uf.unite(A[i], B[i]);
    }
    long ans;
    foreach (i; 0 .. N)
    {
        ans = ans.max(uf.size(i));
    }
    writeln(ans);
}

struct UnionFind
{
    alias T = long;
    T[] rank, parent, sizes;
    this(T n)
    {
        rank = new T[](n);
        sizes = new T[](n);
        sizes[] = 1;
        parent = iota!T(n).array();
    }

    T find(T x)
    {
        return (this.parent[x] == x) ? x : (this.parent[x] = this.find(this.parent[x]));
    }

    void unite(T x, T y)
    {
        T rx = this.find(x), ry = this.find(y);
        if (rx == ry)
            return;
        this.sizes[rx] = this.sizes[ry] = this.sizes[rx] + this.sizes[ry];
        if (this.rank[rx] == this.rank[ry])
            this.parent[rx] = ry, this.rank[ry]++;
        else if (this.rank[rx] < this.rank[ry])
            this.parent[rx] = ry;
        else
            this.parent[ry] = rx;
    }

    T size(T x)
    {
        return this.sizes[this.find(x)];
    }
}


Measured memory_bytes: 25704
n,k=map(int,input().split())
s=input()
if s[k-1]=='A':
  s=s[:k-1]+'a'+s[k:]
elif s[k-1]=='B':
  s=s[:k-1]+'b'+s[k:]
else:
  s=s[:k-1]+'c'+s[k:]
print(s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  string s;
  cin >> n >> s;
  int a = 0, b = 0;
  rep(i,n) if (s[i] == 'R') a++;
  int ans = max(a,b);
  rep(i,n) {
    if (s[i] == 'R') a--;
    else b++;
    int now = max(a,b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long A,B;
	cin>>A>>B;
	
	
     if(A%2==0&&B%2==0)
	cout<<(A+B)/2;
     else if(A%2!=0 && B%2!=0)
     	cout<<(A+B)/2;
     else
     cout<<"IMPOSSIBLE";
     

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
inline ll Function(ll n,ll m)
{
    if(n==1){
        if(m<2)return 1;
        return m-2;
    }
    if(m==1){
        if(n<2)return 1;
        return n-2;
    }
    return n*m-2*(m+n-2);
}

int main()
{
    ll n,m;
    while (scanf("%lld%lld",&n,&m)!=EOF) {
        printf("%lld\n",Function(n,m));
    }
    return 0;
}

Measured memory_bytes: 256
class Stack(object):
    def __init__(self, _max):
        if type(_max) == int:
            self._array = [None for i in range(0, _max)]
            self._next = 0

    def push(self, value):
        if self.isFull():
            raise IndexError
        self._array[self._next] = value
        self._next += 1

    def pop(self):
        if self.isEmpty():
            raise IndexError
        self._next -= 1
        value = self._array[self._next]
        self._array[self._next] = None
        return value

    def isEmpty(self):
        return self._next <= 0

    def isFull(self):
        return self._next >= len(self._array)


def calculator(exp):
    stack = Stack(100)
    ope = ["+", "-", "*"]
    for item in exp:
        if item in ope:
            val1 = stack.pop()
            val2 = stack.pop()
            if item == "+":
                stack.push(val2 + val1)
            elif item == "-":
                stack.push(val2 - val1)
            elif item == "*":
                stack.push(val2 * val1)
            else:
                raise ValueError
        else:
            stack.push(int(item))
    return stack.pop()


if __name__ == "__main__":
    exp = input().split()
    print(calculator(exp))

Measured memory_bytes: 7828
from copy import deepcopy
N = int(input())
X = [int(i) for i in input().split()]
x = deepcopy(X)
X.sort()
if N%2 == 0:
    for i in x:
        if i <= X[N//2 - 1]:
            print(X[N//2])
        else:
            print(X[N//2 - 1])
else:
    for i in x:
        if i < X[N//2]:
            print((X[N//2] + X[N//2 + 1])/2)
        elif i == X[N//2 -1]:
            print((X[N//2 - 1] + X[N//2 + 1])/2)
        else:
            print((X[N//2 - 1] + X[N//2])/2)

Measured memory_bytes: 32628
#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)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	ll a,b,c;
	cin>>a>>b>>c;
	ll t=0;

	if(a==b&&b==c&&a%2==0)cout<<"-1"<<endl;
	else if(a==b&&b==c&&a%2>0)cout<<"0"<<endl;
	else{
		while(a%2==0&&b%2==0&&c%2==0){
			ll a2=(b+c)/2,b2=(a+c)/2,c2=(a+b)/2;
			t++;
			a=a2;
			b=b2;
			c=c2;
		}
		cout<<t<<endl;
	}
	return 0;

}


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

int main(){
	int a , b;
	char op;
	while(1){
		cin >> a >> op >> b;
		if (op=='?') break;
		switch (op){
			case '+':
			cout << a+b << endl;
			break;
			case '-':
			cout << a-b << endl;
			break;
			case '*':
			cout << a*b << endl;
			break;
			case '/':
			cout << a/b << endl;
		}
	}
	return 0;
}

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

const int INF = 1e5;

int N, A, B, C; 
vector<int> l;

int calc(vector<int> v){
    int ans = 0;
    vector<int> abc(3,0);
    for(int i=0; i<v.size(); i++){
        for(int j=0; j<3; j++){
            if(v[i] == j){
                ans += (abc[j] ? 10 : 0);
                abc[j] += l[i];
            }
        }
    }

    if(!abc[0] || !abc[1] || !abc[2]) return INF;

    return ans + abs(abc[0]-A) + abs(abc[1]-B) + abs(abc[2]-C);
}

int dfs(int depth, vector<int> v){
    if(depth == N) return calc(v);
    
    int minmp = INF;
    for(int i=0; i<4; i++){
        v[depth] = i;
        minmp = min(minmp, dfs(depth+1, v));
    }

    return minmp;
}

int main() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    for(int i=0; i<N; i++) cin >> l[i];

    vector<int> v(N,-1);
    cout << dfs(0, v) << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
if 'S' in s and 'N' not in s:print('No')
elif 'N' in s and 'S' not in s:print('No')
elif 'E' in s and 'W' not in s:print('No')
elif 'W' in s and 'E' not in s:print('No')
else:print('Yes')

Measured memory_bytes: 3060
//12
#include<iostream>

using namespace std;

int main(){
  for(char s[100001];cin>>s,s[0]!='#';){
    int v[2]={};
    for(int i=0;i<2;i++){
      int l[2]={-1,-1};
      int p=i;
      for(int j=0;s[j];j++){
	int n=(s[j]-'1')%3;
	if(l[p]!=-1&&(p==1&&l[1]<n||p==0&&l[0]>n)){
	  v[i]++;
	}else{
	  p=!p;
	}
	l[p]=n;
      }
    }
    cout<<((v[0]<v[1])?v[0]:v[1])<<endl;
  }
  return 0;
}

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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    string s; cin >> s;
    int n = s.size();

    int sum = 0;
    for (int i = 0; i < n; i++) 
        sum += s[i] - '0';
    
    cout << (sum % 9 ? "No" : "Yes") << endl;


    return 0; 
}



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

using namespace std;
using ll = long long;



int main()
{
    int n,k;
    string s;
    cin >> n >> s >> k;
    char t = (s[k - 1]);
    for(auto &i : s)i = (i == t ? t : '*');
    cout << s << endl;
}

Measured memory_bytes: 256
def A():
    nums = [int(n) for n in input().split()]
    if sum(nums) >= 22:
        print('bust')
    else:
        print('win')

def B():
    S = input()
    hugs = 0
    for i in range(len(S)//2):
        if S[i] != S[len(S)-i-1]:
            hugs += 1
    print(hugs)
    
B()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    vector<ll> rui(s.size());
    if(s[0] == 'p')rui[0] = 1;
    else rui[0] = 0;

    rep(i, s.size()-1){
        rui[i+1] = rui[i];
        if(s[i+1] == 'p')rui[i+1]++;
    }

    ll ans = 0;
    ll g_p = 0;
    rep(i, s.size()){
        if(s[i] == 'g'){
            if(g_p > rui.back() - rui[i]){
                ans++;
                g_p--;
            }
            else{
                g_p++;
            }
        }
        else {
            g_p--;
            if(g_p < 0){
                ans--;
                g_p = 0;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
    int k, x;
    cin >> k >> x;

    int left, right;
    if (x - k + 1 > -1000000) {
        left = x - k + 1;
    } else {
        left = -1000000;
    }
    
    if (x + k - 1 < 1000000) {
        right = x + k - 1;
    } else {
        right = 1000000;
    }

    for (int i = left; i <= right; i++) {
        printf("%d ", i);
    }
    printf("\n");
}

Measured memory_bytes: 256
inputs = [int(s) for s in input().split()]
n = inputs[0]
l = inputs[1]

if l >= 0:
    taste = int(n*l + n*(n+1)/2 - n - l)
elif -l >= n:
    taste = int(n*l + n*(n+1)/2 - n - (l + n - 1))
else:
    taste = int(n*l + n*(n+1)/2 - n)

print(taste)


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
int N,i,a,b,c,d,t,R;
int dis(int x,int y)
{
	return abs(x/i-y/i)+abs(x%i-y%i);
}
int main()
{
	scanf("%d%d%d%d%d",&N,&a,&b,&c,&d);
	for(i=1,R=999;i<=N;i++)
	{
	t=dis(a-1,b-1)+dis(c-1,d-1);
		R=R<t?R:t;
	}
	printf("%d\n",R);
	return 0;
}

Measured memory_bytes: 596