akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

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


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

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

#define MOD ((ll)1e+9 + 7)



//cout<<fixed<<setprecision(10);
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll k=pow(10,18);
    ll ans=1;
    sort(a.begin(),a.end(),greater<ll>());
    if(a[n-1]==0){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        if(k/ans<a[i]){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 4036
#include<stdio.h>
#include<math.h>
int main(void)
{
	int n;
	int i,j;
	double x[5],y[5];
	double xx,yy;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<4;j++){
			scanf("%lf %lf",&x[j],&y[j]);
		}
		if(x[0]-x[1]==0 || x[2]-x[3]==0){
			if(x[0]-x[1]==0 && x[2]-x[3]==0){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else {
			xx=(y[0]-y[1])/(x[0]-x[1]);
			yy=(y[2]-y[3])/(x[2]-x[3]);
//			printf("%lf %lf\n",xx,yy);
			xx=xx-yy;		
			if(xx<0.0000001 && xx>-0.0000001){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}	
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int l = 0;
  for(int i = 0;i > -1;i++){
    if(S.substr(l, 7) == "dreamer" && S.substr(l+5, 5) != "erase"){
      l += 7;
    }
    else if(S.substr(l, 5) == "dream"){
      l += 5;
    }
    else if(S.substr(l, 6) == "eraser" && S.substr(l+5, 5) != "erase"){
      l += 6;
    }
    else if(S.substr(l, 5) == "erase"){
      l += 5;
    }
    else{
      cout << "NO" << endl;
      break;
    }
    
    if(l == S.size()){
      cout << "YES" << endl;
      break;
    }
  }
}

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

#define ll long long

using namespace std;

int main(){
 int n,ans=0;
 string a,b,c;
 cin>>n>>a>>b>>c;
 for(int i=0;i<n;++i){
   if(a[i]==b[i]){
     if(a[i]==c[i]) continue;
     else ans++;
   }else if(b[i]==c[i]){
     ans++;
   }else if(c[i]==a[i]){
     ans++;
   }else{
     ans+=2;
   }
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
city, ID = [[] for _ in range(N+1)], [0 for _ in range(M)]
for i in range(M):
    P, Y = map(int, input().split())
    city[P].append([Y,i])
for i in range(1, N+1):
    city[i].sort()
    for j in range(len(city[i])):
        ID[city[i][j][1]] = str(i).zfill(6) + str(j+1).zfill(6)
for x in ID:    print(x)

Measured memory_bytes: 39036
//21
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

char gc(int h,int l){
  static const char* bc[]={"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
  return bc[h][l%strlen(bc[h])];
}

int main(){
  for(string s;cin>>s;){
    s+='0';
    int b=s[0]-'0';
    int p=0;
    for(int i=1;i<s.size();i++){
      if(s[i]=='0'){
	if(b!=-1){
	  cout<<gc(b,p);
	  b=-1;
	  p=0;
	}else{
	  cout<<' ';
	}
      }else{
	if(b!=s[i]-'0'){
	  if(b!=-1){
	    cout<<gc(b,p);
	  }
	  b=s[i]-'0';
	  p=0;
	}else{
	  p++;
	}
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
		int N,Flg;
    	string S;
    	cin >> N >> S;
    	Flg = 0;
    	if (N%2 == 0 ){
    		for (int i=0; i<N/2; i++){
    			if(S.at(i) != S.at(i+N/2)){
    				Flg = 1;
    			}
    		}
    	}
    	else {
    		Flg = 1;
    	}
    	
    	if(Flg == 0){
    		cout << "Yes" << endl;
    	}
    	else {
    		cout << "No" << endl;
    	}
    	
    	
    	
    	
    	
    }

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  map = new Array(5).fill(0);
  for(var i=0;i<3;i++){
    tmp= input[i].split(" ");
    map[parseInt(tmp[0])]++;
    map[parseInt(tmp[1])]++;
  }
  var ans ="YES";
  for(var i=1;i<map.length;i++){
    if(map[i]==3){
      ans="NO";
    }else if(map[i]==0){
      ans="NO";
    }
  }

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int N;
  cin>>N;
  int a[N],b[N],c[N];
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  int dp[N+1][4];
  dp[0][1]=0;
  dp[0][2]=0;
  dp[0][3]=0;
  
  for(int i=1;i<N+1;i++){
    dp[i][1] = max(dp[i-1][2]+a[i-1],dp[i-1][3]+a[i-1]);
    dp[i][2] = max(dp[i-1][3]+b[i-1],dp[i-1][1]+b[i-1]);
    dp[i][3] = max(dp[i-1][1]+c[i-1],dp[i-1][2]+c[i-1]);
  }
  
  int ans;
  ans=max(dp[N][1],dp[N][2]);
  ans=max(ans,dp[N][3]);
  cout<<ans<<endl;
}

Measured memory_bytes: 2944
import sys
input = sys.stdin.readline

n = int(input()) #odd
p = list(map(float,input().split()))

#dp[i][j] = i枚まで投げた時の表がj枚出た時の確率。

dp = [[0]*(n+1)for i in range(n+1)]
dp[0][0] = 1
dp[1][0] = 1-p[0]
for i in range(1,n):
    dp[i+1][0] =  dp[i][0] *(1-p[i]) 


for i in range(n):
    for j in range(n):
        dp[i+1][j+1] =  dp[i][j+1] * (1-p[i]) + dp[i][j] * p[i]

ans = 0

for i in range(n//2+1,n+1):
    ans += dp[n][i] 

print(ans)

Measured memory_bytes: 345864
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
  k+=(s*int(S[a-i-1]))
  k%=mod
  s*=10
  s%=mod
  if k in c:
    c[k]+=1
  else:
    c[k]=1
for i in c:
  ans+=c[i]*(c[i]-1)//2
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int main(){
  LL n;
  cin >> n;
  LL ans=0;
  for(LL i=1;i<sqrt(n);i++){
    if(n%i==0){
      if(i<n/i-1) ans+=n/i-1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,max=0,sum=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<=100;i++){
		max=a*i;
		if(max%b==c){
			sum=1;
			break;
		}
	}
	if(sum==1) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
/*
ID: varunra2
LANG: C++
TASK: codechef
*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

#define EPS 1e-9
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()

typedef pair<int, int> PII;
typedef vector<int> VI;

const double pi = acos(-1.0);
typedef long int int32;
typedef long long int int64;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef unsigned long int uint32;
typedef unsigned long long int uint64;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;

#define watch(x) cerr << (#x) << " is " << (x) << endl
#define printvii(v)                                    \
  cerr << (#v) << "=";                                 \
  for_each(v.begin(), v.end(), [](PII i) -> void {     \
    cerr << "(" << i.first << "," << i.second << "),"; \
  });                                                  \
  cerr << endl;
#define printvi(v)                                                       \
  cerr << (#v) << "=";                                                   \
  for_each(v.begin(), v.end(), [](int i) -> void { cerr << i << ","; }); \
  cerr << endl;

int main(int argc, char const *argv[]) {

  priority_queue<ll> q;

  ll n;
  ll m;
  cin >> n >> m;

  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    q.push(x);
  }

  while(m) {
    m--;
    int x = q.top();
    q.pop();
    x /= 2;
    q.push(x);
  }

  ll ret = 0;

  while(!q.empty()) {
    int x = q.top();
    q.pop();
    ret += x;
  }

  cout << ret << endl;
     

  return 0;
}


Measured memory_bytes: 1400
A, B, K = map(int, input().split())

l1 = [x for x in range(A, min(A + K, B + 1))]
l2 = [x for x in range(max(B - K + 1, A),B + 1)]
ans = sorted(list(set(l1 + l2)))
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int H, W, h, w;
    cin>>H>>W>>h>>w;
    int ans = H*W;
    ans -= h*W + w*H;
    ans += h*w;
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	int A[100000];
	int sum = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		sum += abs(A[i] - (i==0?0:A[i-1]));
	}
	sum += abs(A[N-1]);

	for(int i=0; i<N; i++){
		int tmp = 0;
		tmp -= abs(A[i] - (i==0?0:A[i-1]));
		tmp -= abs(A[i] - (i==N-1?0:A[i+1]));
		tmp += abs((i==0?0:A[i-1]) - (i==N-1?0:A[i+1]));
		cout << sum + tmp << endl;
	}

	return 0;
}



Measured memory_bytes: 1664
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define int long long 
const long long MAX = 1e17;
using namespace std;

struct Edge {
	int to;
	int cost;
};


bool saiki(int now, int num, bool istate, vector<int> &tate, vector<int> &yoko,
	vector<bool> &tated, vector<bool> &yokod, vector<vector<Edge>> &tateedge, vector<vector<Edge>> &yokoedge, pair<int, int> &minpair) {
	if (istate) {
		if (tated[now]) {
			if (tate[now] != num) {
				return false;
			}
			return true;
		}
		tated[now] = true, tate[now] = num;
		minpair.first = min(minpair.first, num);
		for (auto &t : tateedge[now]) {
			if (!saiki(t.to, t.cost - num, false, tate, yoko, tated, yokod, tateedge, yokoedge, minpair))
				return false;
		}
		return true;
	}
	else {
		if (yokod[now]) {
			if (yoko[now] != num) {
				return false;
			}
			return true;
		}
		yokod[now] = true, yoko[now] = num;
		minpair.second = min(minpair.second, num);
		for (auto &t : yokoedge[now]) {
			if (!saiki(t.to, t.cost - num, true, tate, yoko, tated, yokod, tateedge, yokoedge, minpair))
				return false;
		}
		return true;

	}
}


signed main() {
	int R, C;
	cin >> R >> C;
	int N;
	cin >> N;
	vector<int> r(N), c(N), a(N);
	for (int i = 0; i < N; i++) {
		cin >> r[i] >> c[i] >> a[i];
		r[i]--, c[i]--;
	}
	vector<vector<Edge>> tateedge(R), yokoedge(C);
	vector<int> tate(R), yoko(C);
	vector<bool> tated(R, false), yokod(C, false);


	for (int i = 0; i < N; i++) {
		tateedge[r[i]].push_back({ c[i], a[i] });
		yokoedge[c[i]].push_back({ r[i], a[i] });
	}
	bool res = true;
	for (int i = 0; i < R; i++) {
		pair<int, int> minp{ MAX,MAX };
		if (tated[i] || tateedge[i].empty())
			continue;
		if (!saiki(i, -100, true, tate, yoko, tated, yokod, tateedge, yokoedge, minp)) {
			res = false;
			break;
		}
		if (minp.first + minp.second < 0) {
			res = false;
			break;
		}
	}
	cout << (res ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 26624
#include <cstdio>
#include <cstring>
#define EPS (1e-13)
#define MAX(A,B)((A)>=(B)?(A):(B))
double dp[1000001];
int main() {
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<=1000000;i++) dp[i]=0;
		dp[1]=1;
		for(int i=2;i<=n;i++) {
			double p=1.0,win=0.5;
			for(int j=1;j<i && EPS<p;j++) {
				double Not=p*(1-win);
				dp[i]+=Not*(j+dp[MAX(0,i-j-1)]);
				p*=win; win/=2;
			}
			dp[i]+=p*i;
		}
		printf("%lf\n",dp[n]);
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<string> a(n);
  for(int i = 0 ; i < n; i++){
    cin >> a[i];
  }
  int ans = 0;
  sort(a.begin(),a.end());
  for(int i = 0; i < n-1; i++){
    if(a[i] != a[i+1]) ans++;
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 9596
const MOD = 10**9+7
const N = 10**5+1000

let fac = [...new Array(N)].fill(0)
let ifac = [...new Array(N)].fill(0)
const mul = (a,b) => ((a>>16)*b%MOD*65536+(a&65535)*b)%MOD;

const factorization = (n) => {
    let primes= []
    for(let i=2; i*i<=n; i++) {
        let exponent = 0
        while(n%i===0) {
            n /= i
            exponent++
        }
        if(exponent) {
            primes.push({p:i, e:exponent})
        }
    }
    
    if(n!==1) {
        primes.push({p:n, e:1})
    }
    return primes
}


const mpow = (x, n) => {
    ans = 1;
    let _x = x
    while(n != 0){
        if(n & 1) ans = mul(ans,_x);
        _x = mul(_x,_x);
        n = n >> 1;
    }
    return ans;
}

const comb = (n, r) => {
    if(n == 0 && r == 0) return 1;
    if(n < r || n < 0) return 0;
    // const tmp = ifac[n-r] % MOD * ifac[r] % MOD;
    const tmp = mul(ifac[n-r],ifac[r])
    return mul(tmp,fac[n])
}

const init = () => {
    fac[0] = 1;
    ifac[0] = 1;
    for(let i=0; i<N; i++){
        fac[i+1] = mul(fac[i],(i+1)); // n!(mod M)
        // ifac[i+1] = mul(ifac[i],mpow(i+1, MOD-2)); // k!^{M-2} (mod M) ←累乗にmpowを採用
        ifac[i+1] = mpow(fac[i+1], MOD - 2)
    }
}

const main = (arg) => {
    let [n, m] = arg.split(" ").map(Number)
    let factors = factorization(m)
    let ans = 1
    init(n)
    Object.keys(factors).forEach(f=>{
        let a = (factors[f].e+n-1)%MOD
        let b = factors[f].e
        if(2*b >a) b = a-b
        ans = mul(ans,comb(a, b))
        //ans %= MOD
        // console.log(ans)
    })
    console.log(ans)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 37500
#include<bits/stdc++.h>
#define maxn 3050
#define I2 500000004
#define modu 1000000007
using namespace std;
typedef long long LL;

int n,m;
int a[maxn];

LL dp[maxn][maxn];

void init()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
            dp[i][j]=a[i]>a[j];
}

LL gx[maxn],lx[maxn];
LL gy[maxn],ly[maxn];

void solve()
{
        // for (int i=1;i<=n;++i)
        //     for (int j=1;j<=n;++j)
        //         printf("%lld%c",dp[i][j]," \n"[j==n]);
        // cout<<endl;
    
    LL F=1;
    while (m--)
    {
        F=F*2%modu;
        int x,y;
        scanf("%d%d",&x,&y);
        for (int i=1;i<=n;++i)
        {
            gx[i]=dp[x][i],lx[i]=dp[i][x];
            gy[i]=dp[y][i],ly[i]=dp[i][y];
        }

        int xy=dp[x][y],yx=dp[y][x];
        dp[x][y]+=yx,dp[y][x]+=xy;

        for (int i=1;i<=n;++i)
        {
            if (i==x||i==y) continue;

            dp[x][i]+=gy[i],dp[i][x]+=ly[i];
            dp[y][i]+=gx[i],dp[i][y]+=lx[i];

            dp[x][i]%=modu,dp[i][x]%=modu;
            dp[y][i]%=modu,dp[i][y]%=modu;
        }
        
        dp[x][y]=dp[x][y]*I2%modu;
        dp[y][x]=dp[y][x]*I2%modu;
        for (int i=1;i<=n;++i)
            if (i!=x&&i!=y)
            {
                dp[x][i]=dp[x][i]*I2%modu;
                dp[i][x]=dp[i][x]*I2%modu;
                dp[y][i]=dp[y][i]*I2%modu;
                dp[i][y]=dp[i][y]*I2%modu;
            }

        // for (int i=1;i<=n;++i)
        //     for (int j=1;j<=n;++j)
        //         printf("%lld%c",dp[i][j]," \n"[j==n]);
        // cout<<endl;
    }

    LL ans=0;
    for (int i=1;i<=n;++i)
        for (int j=i+1;j<=n;++j)
            ans=(ans+dp[i][j]*F)%modu;
    printf("%lld\n",ans);
}

int main()
{
    init();
    solve();
    return 0;
}

Measured memory_bytes: 71936
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int i,N,sum,k,s;
int A[200000];
cin >> N;
sum=0;
A[0]=0;
for(i=1;i<=N;i++){
cin >> A[i];
}
A[N+1]=0;
for(i=0;i<=N;i++){
	sum += abs(A[i+1]-A[i]);
}
	s = sum;
for(k=1;k<=N;k++){
	if(A[k-1]<=A[k] && A[k]<=A[k+1]){
		cout << sum << endl;}
	else if(A[k+1]<=A[k] && A[k]<=A[k-1]){
cout << sum <<endl;
}else{
sum -= 2*min(abs(A[k-1]-A[k]),abs(A[k]-A[k+1]));
cout << sum << endl;
sum = s;
}
}
}

Measured memory_bytes: 1664
_ = input()
a_list = list(map(int, input().split()))

min_2_factor = 30
for a in a_list:
	a_2_factor = 0
	current_a = a
	while True:
		if current_a % 2 == 0:
			a_2_factor += 1
		else:
			min_2_factor = min(min_2_factor, a_2_factor)
			break
		current_a = current_a / 2
	# print(a, a_2_factor)

print(min_2_factor)

Measured memory_bytes: 3060
// Library
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "YES" : "NO")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

#define F1 first
#define S2 second
#define PB push_back
#define MP make_pair


// Global Tables

//ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>>& v)
{
    ull i, j; 
    for(i = 0; i < v.size(); i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            cout << v[i][j];
            if(j == v[i].size()-1)
            {
                cout << endl;
            }
            else
            {
                cout << " ";
            }
        }
    }
}

void PrintVector(vi& v)
{
    ull i;
    for(i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if(i == v.size()-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PrintArr(int* a, ull N)
{
    ull i;
    for(i = 0; i < N; i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PreProcessTables()
{
    ull i, j;
    for(i = 0; i < SZA; i++)
    {
        for(j = 0; j < SZB; j++)
        {
            break;
        }
        break;
    }
}

void TC(int t)
{
    string S;
    cin >> S;
    if(S.size() > 0 && S[S.size()-1] == 's')
    {
        S.push_back('e');
        S.push_back('s');
    }
    else
    {
        S.push_back('s');
    }
    cout << S << endl;
}

// Main

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    PreProcessTables();

    int T = 1, t;
    //cin >> T;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	int n;
	vector<int> x;
	ull all_sum = 0;
	cin >> n;
	x.pb(0);
	rep (i, n)
	{
		int xi;
		cin >> xi;
		x.pb(xi);
		all_sum += abs(x[i] - x[i + 1]);
	}
	all_sum += abs(x[n]);
	x.pb(0);

	for (int i = 1; i <= n; i++)
	{
		cout << all_sum
			- abs(x[i - 1] - x[i])
			- abs(x[i] - x[i + 1])
			+ abs(x[i - 1] - x[i + 1]) << endl;
	}

	return 0;
}


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

using namespace std;

int main(){
	typedef long long ll;
	ll h;
	cin>>h;
	h/=2;
	ll count = 1, i = 0;
	while(h >=1){
		h/=2;
		i++;
		count += pow(2, i);
	}

	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll ans = 0;

    {
        ll left = a.back(), right = a.back();
        ll tmp = 0;
        ll li = 0, ri = a.size() - 1;
        while(li < ri){
            if(li + 2 <= ri){
                tmp += abs(left - a.at(li)) + abs(right - a.at(li + 1));
                left = a.at(li);
                right = a.at(li + 1);
                li += 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(li)), abs(right - a.at(li)));
                li += 1;
                break;
            }
            if(li + 2 <= ri){
                tmp += abs(left - a.at(ri - 1)) + abs(right - a.at(ri - 2));
                left = a.at(ri - 1);
                right = a.at(ri - 2);
                ri -= 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(ri - 1)), abs(right - a.at(ri - 1)));
                ri -= 1;
                break;
            }
        }
        ans = max(ans, tmp);
    }

    {
        ll left = a.front(), right = a.front();
        ll tmp = 0;
        ll li = 1, ri = a.size();
        while(li < ri){
            if(li + 2 <= ri){
                tmp += abs(left - a.at(ri - 1)) + abs(right - a.at(ri - 2));
                left = a.at(ri - 1);
                right = a.at(ri - 2);
                ri -= 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(ri - 1)), abs(right - a.at(ri - 1)));
                ri -= 1;
                break;
            }
            if(li + 2 <= ri){
                tmp += abs(left - a.at(li)) + abs(right - a.at(li + 1));
                left = a.at(li);
                right = a.at(li + 1);
                li += 2;
            }else if(li + 1 <= ri){
                tmp += max(abs(left - a.at(li)), abs(right - a.at(li)));
                li += 1;
                break;
            }
        }
        ans = max(ans, tmp);
    }

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


Measured memory_bytes: 1400
import sys
N = int(input())
p = list(map(int,input().split()))
l = [0]*3
a = 0
for i in range(1,N+1):
    if p[i-1] != i:
        l[a] = i-1
        a += 1
        if a==3:
            print("NO")
            sys.exit()
temp = p[l[0]]
p[l[0]] = p[l[1]]
p[l[1]] = temp
for i in range(1,N+1):
    if p[i-1] != i:
        print("NO")
        sys.exit()
print("YES")

Measured memory_bytes: 3064
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,d-abs(x-cx)-abs(y-cy))!=h:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)


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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	string s;
	cin>>s;
	long long cnt=0;
	for(auto a:s){
		cnt+=a-'0';
	}

	if(cnt%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

template<typename T>
bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return 1;
	}
	return 0;
}

template<typename T>
bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return 1;
	}
	return 0;
}


Measured memory_bytes: 3748
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))

t1 = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            t1 += 1

A.sort()
t2 = 0
lst = 0
for i in range(1, N):
    if A[i - 1] < A[i]:
        t2 += i
        lst = i
    elif A[i - 1] == A[i]:
        t2 += lst

ans = (t1 * K + t2 * K * (K - 1) // 2) % (10 ** 9 + 7)

print(ans)




Measured memory_bytes: 9176
s = input()
N = len(s)
left_white=[]
for i in range(N):
    if (i%2) == 0:
        left_white.append(1)
    else:
        left_white.append(0)
left_black=[]
for i in range(N):
    if (i%2) == 0:
        left_black.append(0)
    else:
        left_black.append(1)
count_w = 0
for i in range(N):
    if int(s[i]) != left_white[i]:
        count_w = count_w+1
count_b = 0
for i in range(N):
    if int(s[i]) != left_black[i]:
        count_b += 1
print(min(count_w,count_b))

Measured memory_bytes: 4852
from collections import deque

def bfs(maze, visited, sy, sx, dot_num):
    q = deque([[sy, sx]])
    visited[sy][sx] = 0
    cnt = 1
    while q:
        y, x = q.popleft()
        # 全てのマスを探索したら終了
        if dot_num == cnt:
            visited_1dim = [0] * H*W
            for i in range(H):
                for j in range(W):
                    visited_1dim[i*W + j] = visited[i][j]
            return max(visited_1dim)
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if 0 <= new_y <= H-1 and 0 <= new_x <= W-1:
                if maze[new_y][new_x] == "." and \
                    visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    q.append([new_y, new_x])
                    cnt += 1
                    
H, W = map(int, input().split())
maze = [input() for i in range(H)]

# 道の数
maze_1dim = [0] * H*W
for y in range(H):
    for x in range(W):
        maze_1dim[y*W + x] = maze[y][x]
dot_num = maze_1dim.count(".")

# スタート地点を全て探索
ans = 0
for y in range(H):
    for x in range(W):
        visited = [[-1]*W for j in range(H)]
        if maze[y][x] == ".":
            ans = max(ans, bfs(maze, visited, y, x, dot_num))
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n, totalCnt = 0;
	cin>>n;
	string s;
	cin>>s;
	ll r, g, b;
	r=g=b=0;
	for(int i=0; i<n;i++)
	{
		if(s[i]=='R') 
			r++;
		else if(s[i]=='G') 
			g++;
		else	
			b++;
	}
	totalCnt = r*g*b;
	int sum = (int)('R')+(int)('G')+(int)('B');
	for(int i=0; i<n;i++)
	{
		for(int j=i+1; j<n;j++)
		{
			int k = 2*j - i;
			if(k<n && ((int)s[i]+(int)s[j]+(int)s[k])==sum)
				totalCnt--;
		}
	}
	cout<<totalCnt<<"\n";
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

template <class myType>
myType GCD(myType x, myType y)
{
    myType t;
    while(y > 0)
    {
        t = x % y;
        x = y;
        y = t;
    }
    return x;
}

int main()
{
  long long a, b;
  cin>>a>>b;

  long long res = a*b;
  cout<<res/GCD(a, b)<<endl;
  return 0;
}

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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		char s[] = fs.next().toCharArray();
		int len = s.length;
		int ans = 0;
		for(int i=0;i<len;i++) {
			if(i%2==0) {
				if(s[i]=='p')ans--;
			}
			else {
				if(s[i]=='g')ans++;
			}
		}
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

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





Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char c[50];
	int i;
	int t;
	for(i=1;i<=50;i++) cin>>c[i];
	for(i=1;i<=50;i++){if ((c[i]<'A')||(c[i])>'Z'){t=i-9;break;}}
	for(i=1;i<=t;i++) cout<<c[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0;
    char x,y,z;
    string s;

    cin>>s;
    x=s[0];
    y=s[1];
    z=s[2];
    if(x=='a'&&(y=='b'&&z=='c'))
    {


        cout<<"Yes"<<endl;

    }
   else if(x=='a'&&(y=='c'&&z=='b'))
    {
        cout<<"Yes\n"<<endl;
    }

   else if(x=='b'&&(y=='a'&&z=='c'))
    {


        cout<<"Yes\n";

    }
    else if(x=='b'&&(y=='c'&&z=='a'))
    {


        cout<<"Yes\n";
    }
    else if(x=='c'&&(y=='a'&&z=='b'))
    {


        cout<<"Yes\n";
    }
   else if(x=='c'&&(y=='b'&&z=='a'))
    {


        cout<<"Yes\n";
    }

    else
    {


        cout<<"No\n";
    }








    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=(n/(a+b))*a;
	if(n%(a+b)>a)ans+=a;
	else ans+=n%(a+b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){

  long long n,ans;
  string str,str2;
  
  cin >> n;

  while(n--){

    cin >> str;
    str2 = str;

    for(int i=0;i<7;i++){
      for(int j=i+1;j<8;j++){
	if(str[i]<str[j]) swap(str[i],str[j]);
	if(str2[i]>str2[j]) swap(str2[i],str2[j]);
      }
    }

    cout << atoi(str.c_str())-atoi(str2.c_str()) << endl;
  }

  return (0);
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int N,B[100000],ans,tmp;
    cin >> N;
    REP(i,N-1){
        cin >> B[i];
    }
    B[N-1] = INF;

    ans=0;
    REP(i,N){
        if(i>0 && B[i-1] < B[i]){
            tmp = B[i-1];
        }
        else{
            tmp = B[i];
        }
        ans += tmp;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(k+1,0);
    ll ans = 0;
    for(int i=k;i>=1;i--){
        ll val = 0;
        ll x = i;
        a.at(i) = modpow(k/i,n,mod);
        x += i;
        while(x<=k){
            a.at(i) = (a.at(i) - a.at(x))%mod;
            if(a.at(i)<0) a.at(i)+=mod;
            x+=i;
        }
    }
    //for(int i=1;i<=k;i++){
    //    cout << a.at(i) << endl;
    //}
    for(int i=1;i<=k;i++){
        ans = (ans+((a.at(i)*i)%mod))%mod;
    }
    cout << ans << endl;
    return 0;

}    

Measured memory_bytes: 3988
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	long long n, y;
	cin >> n >> y;
	y /= 1000;//考えやすくする
	y -= n;//1000円札をn枚入れる
	if (y < 0) {
		cout << "-1 -1 -1" << endl;
		return 0;
	}
	int ichiman_en = 0, gosen_en = 0;
	//10000円札に交換すると+9000円,5000円札に交換すると+4000円
	//まず10000円札に交換する分を考える。
	while (y % 4 != 0) {
		y -= 9;
		ichiman_en++;
		if (y < 0) {
			cout << "-1 -1 -1" << endl;
			return 0;
		}
	}
	//10000円札x4と5000円札x9はやる事は同じで枚数が10000円札に交換するほうが少ない
	ichiman_en += (y / 36) * 4;
	y %= 36;
	//あとは5000円札で決済
	gosen_en += y / 4;
	y %= 4;
	assert(y == 0);//y=0でないとおかしい
	if (ichiman_en + gosen_en <= n) {
		cout << ichiman_en << " " << gosen_en << " " << n - ichiman_en - gosen_en << endl;
		return 0;
	}
	else {
		cout << "-1 -1 -1" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-04
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<int,int> cnt;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x-1]++;
        cnt[x]++;
        cnt[x+1]++;
    }
    
    int ans = 0;
    for (auto i : cnt) {
        ans = max(ans, i.second);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8040
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n,n){
		bool dia[41][41]={};
		for(int i=0,x,y;i<n;i++){
			cin>>x>>y;
			dia[y][x]=1;
		}
		int mo;
		cin>>mo;
		string di="NESW";
		int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
		for(int i=0,num,x=10,y=10;i<mo;i++){
			char direction;
			cin>>direction>>num;
			for(int j=0;j<4;j++){
				if(direction==di[j]){
					for(int k=0;k<num;k++){
						x+=dx[j];
						y+=dy[j];
						if(dia[y][x]==true){
							dia[y][x]=false;
							n--;
						}
					}
					break;
				}
			}
		}
		if(n==0)cout<<"Yes\n";
		else cout<<"No\n";
	}
}

Measured memory_bytes: 1180
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n;
	long long prev = 0;
	long long sol = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		long long input;

		scanf("%lld", &input);
		
		if (input < prev)
		{
			sol += prev - input;

			input = prev;
		}

		prev = input;
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,cap;
    cin>>n>>cap;
    ll w[n+1],v[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][cap+1],i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=cap;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else
            {
                ll inc=-1,exc;
                exc=dp[i-1][j];
                if(j-w[i]>=0)
                    inc=v[i]+dp[i-1][j-w[i]];
                dp[i][j]=max(inc,exc);
            }
        }
    }
    cout<<dp[n][cap]<<"\n";
}


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

using pdd = pair<double, double>;

double solve(vector<double> x, vector<double> r) {
    const int n = x.size();
    auto check = [&] (double h) {
        vector<pdd> ps(n);
        for(int i = 0; i < n; ++i) {
            double x1 = x[i], x2 = x[i];
            if(h <= r[i]) {
                x1 -= sqrt(r[i] * r[i] - h * h);
                x2 += sqrt(r[i] * r[i] - h * h);
            }
            ps[i] = make_pair(x1, x2);
        }
        sort(begin(ps), end(ps));
        double lx = -1e9, rx = -2e9;
        for(int i = 0; i < n; ++i) {
            if(rx < ps[i].first) {
                if(rx - lx >= 2 * h) return true;
                lx = ps[i].first, rx = ps[i].second;
            } else {
                rx = max(rx, ps[i].second);
            }
        }
        return rx - lx >= 2 * h;
    };
    double lb = 0, ub = 2e5;
    for(int lp = 0; lp < 60; ++lp) {
        const auto mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    return lb * 2;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<double> x(n), r(n);
        for(int i = 0; i < n; ++i) {
            cin >> x[i] >> r[i];
        }
        cout << fixed << setprecision(10) << solve(move(x), move(r)) << endl;
    }
}



Measured memory_bytes: 4588
import sys
from itertools import permutations

n = int(sys.stdin.readline().rstrip())
p, q = [tuple(map(int, sys.stdin.readline().split())) for _ in range(2)]

def main():
    perms = list(permutations(range(1, n+1)))
    return abs(perms.index(p) - perms.index(q))

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 8052
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll r; cin>>r;
    cout<<3*r*r<<endl;
}




Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int N,K,i,answer=1;
	
	scanf("%d %d",&N,&K);
	
	for(i=0; i < N-1; i++){
		answer *= K-1;
	}
	
	answer *= K;
	
	printf("%d",answer);
	
	return 0;
}

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

using namespace std;

using ll = long long;

int main()
{
    ll N, K; cin >> N >> K;

    ll tmp = N % K;
    ll ans;

    if (tmp == 0) ans = tmp;
    else if (tmp < abs(tmp - K)) ans = tmp;
    else ans = abs(tmp - K);
    //else if (N < K) ans = N;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

struct BIT{
    ll N;
    vector<ll> dat;
    void initialize(ll _n){N=_n+1;dat.resize(N+1);rep(i,N+1)dat[i]=0;}
    ll sum(ll i){ll s=0;while(i>=0)s+=dat[i],i=(i&(i+1))-1;return s;}
    ll sum_between(ll i,ll j){return i<=j?sum(j)-sum(i-1):0;}
    void add(ll i,ll x){while(i<=N)dat[i]+=x,i|=i+1;}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin>>N;
    vector<int> A(N), AS(N);
    rep(i,N) cin>>A[i],AS[i]=A[i];
    sort(all(AS));
    
    int ub=N, lb=0;
    BIT bit;
    ll border=((N*(N+1)/2)+1)/2;
    while(ub-lb>1){
        int mid=(ub+lb)/2, midn=AS[mid];
        bit.initialize(2*N+1);
        int sum=0;
        bit.add(N,1);
        ll result=0;
        rep(i,N){
            sum+=A[i]>=midn?1:-1;
            result+=bit.sum(sum+N);
            bit.add(sum+N,1);
        }
        if(result>=border) lb=mid;
        else ub=mid;
    }
    cout1(AS[lb]);
}

Measured memory_bytes: 2560
#include<vector>
#include<string>
#include<iostream>
#include<numeric>
using namespace std;
int main(){
	int n,i=0,j,c;
	string s;
	vector<string>v;
	for(cin>>n;i<n;i++)cin>>s,v.push_back(s);
	vector<string>a=v;
	for(i=0;i<n;i++)for(j=0;j<n-i-1;j++)if(a[j][1]>a[j+1][1])s=a[j],a[j]=a[j+1],a[j+1]=s;
	string sorted=accumulate(a.begin(),a.end(),string(),[](string x,string y){return x+" "+y;}).substr(1);
	cout<<sorted<<endl;
	cout<<"Stable"<<endl;
	a=v;
	for(i=0;i<n;i++){
		for(c=i,j=i+1;j<n;j++)if(a[j][1]<a[c][1])c=j;
		if(c>i)s=a[i],a[i]=a[c],a[c]=s;
	}
	string sorted2=accumulate(a.begin(),a.end(),string(),[](string x,string y){return x+" "+y;}).substr(1);
	cout<<sorted2<<endl;
	cout<<(sorted==sorted2?"Stable":"Not stable")<<endl;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

vector<P> g1[114514], g2[114514];
ll d1[114514], d2[114514], unko[114514];

int main() {
	IOS();
	ll n, m, s, t;
	cin >> n >> m >> s >> t;
	ll ans = INF;
	Fill(d1, INF);
	Fill(d2, INF);
	for (int i = 0; i < m; ++i) {
		ll a, b, x, y;
		cin >> x >> y >> a >> b;
		g1[x].push_back(P(a, y));
		g1[y].push_back(P(a, x));
		g2[x].push_back(P(b, y));
		g2[y].push_back(P(b, x));
	}
	d1[s] = d2[t] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty()) {
		P a		= que.top();
		ll from = a.second;
		que.pop();
		for (auto i : g1[from]) {
			ll to = i.second;
			if (d1[to] > d1[from] + i.first) {
				d1[to] = d1[from] + i.first;
				que.push(P(d1[to], to));
			}
		}
	}
	que.push(P(0, t));
	while (!que.empty()) {
		P a		= que.top();
		ll from = a.second;
		que.pop();
		for (auto i : g2[from]) {
			ll to = i.second;
			if (d2[to] > d2[from] + i.first) {
				d2[to] = d2[from] + i.first;
				que.push(P(d2[to], to));
			}
		}
	}

	for (int i = n; i > 0; --i) {
		ans			= min(ans, d1[i] + d2[i]);
		unko[i - 1] = 1e15 - ans;
	}

	for (int i = 0; i < n; ++i) { dump(unko[i]); }
}

Measured memory_bytes: 20600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	ll H, W;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = INF;
	for (int i = 0; i < 2; i++) {
		for (int j = 1; j < H; j++) {
			ll area[3];
			area[0] = j * W;
			if ((H - j) % 2 == 0 || W % 2 == 0) {
				area[1] = area[2] = (H - j)*W / 2;
			}
			else {
				area[1] = ((H - j)*W + min(H - j, W)) / 2;
				area[2] = ((H - j)*W - min(H - j, W)) / 2;
			}
			sort(area, area + 3);
			ans = min(ans, area[2] - area[0]);
		}
		swap(H, W);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256