akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

char c[8][10];

void rotate() {
  char _c[8][10];
  rep (i,8) fill(_c[i], _c[i] + 10, ' ');
  
  rep (i,8) rep (j,8) {
    double x = j - 3.5, y = i - 3.5;
    double tx = -y + 3.5, ty = x + 3.5;
    _c[(int)ty][(int)tx] = c[i][j];
  }
  
  rep (i,8) rep (j,8) c[i][j] = _c[i][j];
}

int main() {
  rep (i,8) scanf("%s", c[i]);
  const int l[3] = { 90, 180, 270 };
  rep (i,3) {
    printf("%d\n", l[i]);
    rotate();
    rep (j,8) puts(c[j]);
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np

N = int(input())
A = list(map(int, input().split()))
a = sorted(A)
res = list(np.cumsum(a))

ans = 0
idx = 1
for i in range(len(res)):
    num = res[i]
    if(idx <= i):
        idx = i+1
    while(num*2 >= a[idx]):
        num += a[idx]
        idx += 1
        
        if(idx >= len(res)-1):
            break
       
    if(idx >= len(res)-1):
        print(N-i)
        break

Measured memory_bytes: 38424
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

ll power(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

int main() {
    FAST;
    ll t, i, j, k, p, q,l,r, x, y, u, v, n, m;
    cin>>n;

    ll a=1,b=1,c=1;
    while(n--)
    {
      a = a * 10 % mod;
      b = b * 9 % mod;
      c = c * 8 % mod;
    }
	  cout << (a - 2*b + c + 2*mod) % mod << endl;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10628
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);
    for(int i=0; i<N; i++) {
        cin >> a[i] >> b[i];
    }
    for(int j=0; j<M; j++) {
        cin >> c[j] >> d[j];
    }

    for(int i=0; i<N; i++) {
        int ans;
        int m = INT32_MAX;
        for(int j=0; j<M; j++) {
            int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(dist < m) {
                m = dist;
                ans = j;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
h, w = map(int, input().split())
f = np.array([list(input()) for _ in range(h)])

f = f[~np.all(f=='.', axis=1), :]
f = f[:, ~np.all(f=='.', axis=0)]

print('\n'.join(''.join(row) for row in f))

Measured memory_bytes: 12544
import sys 
def same(eptuple):
    return eptuple[0] +1 == eptuple[1]
N = int(sys.stdin.readline())
plist = map(int, sys.stdin.readline().strip().split())
eplist = list(enumerate(plist))

if same(eplist[0]):
    flag =True
else:
    flag =False
count = 0
for i in xrange(1, N):
    if same(eplist[i]):
        if flag:
            count += 1
            flag = False
        else:
            flag =True
    else:
        if flag:
            count += 1
            flag = False                                                                                                                                                                                                              
        else:
            flag = False
if flag:
    count += 1
print count

Measured memory_bytes: 16052
if __name__ == '__main__':
    N=int(input())
    S=input()
    r=0
    l=0

    for s in S:
        if s=="(":
            r+=1
        else:
            if r>0:
                r-=1
            else:
                l+=1
    print("("*l+S+")"*r)


Measured memory_bytes: 38384
import math


# さいころの目を受け取り，勝つ確率を出力する
def win_p(number, k):
    if number > k - 1:
        return 1
    if number == 0:
        return 0
    log_n = math.log((k/number), 2)
    int_log = int(log_n)
    if int_log < log_n:
        int_log += 1
    return math.pow(0.5, int_log)


inp = input()
st_sp = inp.split()
n = int(st_sp[0])
k = int(st_sp[1])
sum_p = 0.0
for i in range(n):
    sum_p += win_p(i+1, k)
print(sum_p/n)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int d = 0;
      for (int k = 0; k < D; k++) {
        d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      int sd = sqrt(d);
      if (d == sd * sd) res++;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
n=int(input())
w=[input()]
check=True
for i in range (1,n):
    x = input()
    if x in w or w[i-1][len(w[i-1])-1]!=x[0]:
        check=False
    w.append(x)
if check:
    print('Yes')
else:
    print('No')

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

using namespace std;

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

    vector<int> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }
    
    int ans = accumulate(vt.begin(), vt.end(), 0) -
              *max_element(vt.begin(), vt.end()) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;
 
int main() {
    while(true) {
    	int h, w;
    	cin >> h >> w;
    	if(h==0 && w==0) {
    		break;
    	}
    	for(int i=0; i<h; i++) {
    		if(i==0 || i==h-1) {
    			for(int j=0; j<w; j++) {
	    			cout << "#";
	    		}
    		}else {
    			cout << "#";
    			for(int k=0; k<w-2; k++) {
    				cout << ".";
    			}
    			cout << "#";
    		}
    		cout << endl;
    	}
    	cout << endl;
    }
}


Measured memory_bytes: 2996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int index = sc.nextInt();
		int V = 0;
		int C = 0;
		int[] value = new int[index];
		int[] cost = new int[index];
		
		for(int i = 0;i<index;i++) {
			value[i] = sc.nextInt();
		}
		for(int i = 0;i<index;i++) {
			cost[i] = sc.nextInt();
		}
		for(int i = 0;i<index;i++) {
			if(value[i] > cost[i]) {
				V += value[i];
				C += cost[i];
			}
		}
		System.out.println(V-C);
		
	}

}


Measured memory_bytes: 23252
from collections import Counter

N = int(input())
S = list(input())

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

Measured memory_bytes: 9460
import sys
s=sys.stdin.readline
while 1:
 n=int(s())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=s().strip().split()
  d[k]=v
 print(''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s())))


Measured memory_bytes: 7112
#ifndef DEBUG 
	#pragma GCC optimize ("Ofast")
#endif
#include <bits/stdc++.h>

using namespace std;
using f64 = double;using i64=long long;using u64=unsigned long long;

#define hfor(var, s, e) for(int var=s; s<=var && var<e; ++var)//half-opened range
#define hfori(var, s, e) for(int var=e-1; s<=var && var<e; --var)//inversion
#define hforo(var, s, e) int var=s; for(; s<=var && var<e; ++var)//out declaration
#define hforoi(var, s, e) int var=e-1; for(; s<=var && var<e; --var)
#define cfor(var, s, e) hfor(var, s, (e)+1)//closed range
#define cfori(var, s, e) hfori(var, s, (e)+1)
#define cforo(var, s, e) hforo(var, s, (e)+1)
#define cforoi(var, s, e) hforoi(var, s, (e)+1)
#define rep(x) hfor(repi,0,x)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb pop_back
#define pf push_front
#define ef pop_front
#define fi first
#define se second
#define gcd __gcd

template<typename T> constexpr T inf() { return numeric_limits<T>::max() / 2; }
auto mri(auto it){ return make_reverse_iterator(it); }//*mri(it) == *prev(it)
auto rerase(auto& c, auto ri){ return next(mri(c.erase(prev(ri.base())))); }
auto accumulate(auto a, auto b, int c=0){ return std::accumulate(a,b,i64(c)); }
auto sum(auto a, auto b){return accumulate(a,b);}
int sz(const auto& x){ return (int)x.size(); }
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
#define random rd

const f64 pi=acos(-1), eps=1e-12;
const int prime=998244353;//1073741783 int(2e9+11) int(1e9+9)
const int mod=int(1e9+7);
auto ___=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), srand((int)time(0)), 0);
#define endl '\n'//not interactive?
//#define int i64//overflow?

signed main(){
	int n;
	cin>>n;
	int a[100000];
	set<int> s;
	hfor(i,0,n){
		cin>>a[i];
		s.insert(a[i]);
	}
	if(s.size()>3){
		cout<<"No"<<endl;
		return 0;
	}
	
	int b[100000]={*s.begin(), s.size()<2?*s.begin():*next(s.begin()), };
	hfor(i,2,n)
		b[i]=b[i-1]^b[i-2];
	if((b[n-1]^b[n-2])!=b[0] || (b[n-1]^b[0])!=b[1]){
		cout<<"No"<<endl;
		return 0;
	}
	sort(a,a+n);
	sort(b,b+n);
	hfor(i,0,n)
		if(a[i]!=b[i]){
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int X; cin >> X;
    int ans = 0;
    ans += X / 500 * 1000;
    ans += (X % 500) / 5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    cout << t + s << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	long long int a, s[200001], k;
	s[0]=0;
	scanf("%d %lld", &n, &k);
	for(int i=1; i<=n; i++){
		scanf("%lld", &a);
		a=a-k;
		s[i]=s[i-1]+a;
	}
	queue<long long int> s1[200001];
	for(int i=0; i<=n; i++){
		s1[i].push(s[i]);
	}
	long long int ans=0;
	int n1=n+1;
  queue<long long int> s2[100001];
	while(n1!=1){
	
	for(int i=0; i<(n1+1)/2; i++){
		while(!s1[2*i].empty() || !s1[2*i+1].empty()){
			if(s1[2*i].empty()){
				while(!s1[2*i+1].empty()){
					s2[i].push(s1[2*i+1].front());
					s1[2*i+1].pop();
				}
			}else if(s1[2*i+1].empty()){
				while(!s1[2*i].empty()){
					s2[i].push(s1[2*i].front());
					s1[2*i].pop();
				}
			}else{
				long long int x=s1[2*i].front(), y=s1[2*i+1].front();
				if(x<=y){
					s2[i].push(x);
					s1[2*i].pop();
				}else{
					s2[i].push(y);
					ans=ans+s1[2*i].size();
					s1[2*i+1].pop();
				}
			}
		}
	}
	n1=(n1+1)/2;
	for(int i=0; i<n1; i++){
		while(!s2[i].empty()){
			s1[i].push(s2[i].front());
			s2[i].pop();
		}
	}
	}
	long long int N=(long long int)n;
	ans=N*(N+1)/2-ans;
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    int a, b, c, x ,y;
    long int sum = 20000000000;
    cin >> a >> b >> c >> x >> y;

    for(int i=0;i<=100000;i++){
        if(sum > 2*c*i+a*max(0, x-i)+b*max(0, y-i)){
            sum = 2*c*i+a*max(0, x-i)+b*max(0, y-i);
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3640
while(true) do
    h,w=gets.split.map(&:to_i)
    if h==0&&w==0 then break end
    i=0
    h.times{
        w.times{
            if i%2==0
                printf("#")
            else
                printf(".")
            end
            i+=1
        }
        puts ""
        if w%2==0 then i+=1 end
    }
    puts ""
end


Measured memory_bytes: 6888
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long
#define endl '\n'
const int N = 100001;
int n, k, a[501], b[501];
int sum = 0;
vector<int> dv;
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	int ans = 1;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
		sum += a[i];
	}
	int lm = *max_element(a + 1, a + n + 1);
	for(int i = 1 ; i <= sqrt(sum) ; i ++){
		if(sum % i != 0) continue;
		dv.push_back(i);
		if(i * i != sum) dv.push_back(sum/i);
	}
	//cout << "sum: " << sum << endl;
	sort(dv.begin(), dv.end());
	reverse(dv.begin(), dv.end());
	for(int D: dv){
		//cout << "solve " << D << endl;
		for(int i = 1 ; i <= n ; i ++)
			b[i] = a[i]%D;
		sort(b + 1, b + n + 1);
//		cout << "b: \n";
//		for(int i = 1 ; i <= n ; i ++)
//			cout << b[i] << " ";
//		cout << endl;
		int cost = 0;
		int L = 1, R = n;
		bool solve = false;
		int K = k;
		while(L <= R){
//			cout << "L R K: " << L << " " << R << " " << K << endl;
//			for(int i = 1 ; i <= n ; i ++)
//				cout << b[i] << " ";
//			cout << endl;
			if(L == R) {
				if(b[L] == b[R] && b[L] == 0) cout << D;
				return 0;
			}
			if(b[L] == 0) {
				L ++; continue;
			} 
			if(b[R] == 0) {
				R --; continue;
			}
			if(b[L] < (D - b[R])){
				if(b[L] <= K){
					//cout << "drop left " << b[L] << endl;
					K -= b[L];
					b[R] += b[L];
					b[L] = 0;
				}
				else break;
			}
			if(D - b[R] <= b[L]){
				if(D - b[R] <= K){
					K -= (D - b[R]);
					b[L] -= (D - b[R]);
					b[R] = 0;
				}
				else break;
			}
		}
	}
	
}


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

int main(){
	int a,b,c,od=0,ans=0;
	cin>>a>>b>>c;
	od+=a%2+b%2+c%2;
	if(od==1){
		if(a%2!=1){
			a++;
		}
		if(b%2!=1){
			b++;
		}
		if(c%2!=1){
			c++;
		}
		ans++;
	}else if(od==2){
		if(a%2==1){
			a++;
		}
		if(b%2==1){
			b++;
		}
		if(c%2==1){
			c++;
		}
		ans++;
	}
	cout<<ans+(max(max(a,b),c)*3-a-b-c)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
// D - Alice&Brown

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	ll X, Y;
	cin >> X >> Y;

	string ans;

	if (abs(X - Y) <= 1) ans = "Brown";
	else ans = "Alice";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin>>N>>A>>B;
  
  if((N*A)>B){
      cout<<B<<endl;
  }
  
  else if((N*A)<B){
      cout<<N*A<<endl;
  }
  
  else{
      cout<<B<<endl;
  }
  
  
}

Measured memory_bytes: 3528
def check(N, d):
    numList = d
    numList.sort()
    
    if N % 2 != 0:
        print(0)
    else:
        print(numList[int(len(numList)/2)] - numList[int(len(numList)/2-1)])

N = int(input())
d = [int(i) for i in input().split()]
check(N, d)

Measured memory_bytes: 16040
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i++)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
int main(){
    int a[4];
    rep(i,0,4)cin>>a[i];
    bool one=false,sev=false,nin=false,fou=false;
    rep(i,0,4){
        if(a[i]==1)one=true;
        if(a[i]==7)sev=true;
        if(a[i]==9)nin=true;
        if(a[i]==4)fou=true;
    }
    if(one&&sev&&nin&&fou)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = input()

dp = [-1] * (N + M + 1)
dp[N] = 0
pos = N

while pos > 0:
    dist = dp[pos]
    tmp = pos

    for i in range(1, M + 1):
        if pos - i < 0:
            break
        if S[pos - i] == "0":
            dp[pos - i] = dist + 1
            tmp = pos - i
    if pos == tmp:
        break
    pos = tmp

if dp[0] == -1:
    print(-1)
    exit()

ans = []
cnt = dp[0]
pos = 0
while cnt > 0:
    for i in range(1, M + 1):
        if dp[pos + i] + 1 == cnt:
            ans.append(i)
            pos += i
            cnt -= 1
            break

print(*ans, sep=" ")


Measured memory_bytes: 51056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
const int N=7;
int dic[N],w,dic2[N];
string s;
int e=0,n=0;
bool ans = false;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	FOR(i,1,7)cin>>dic[i];
	FOR(i,1,7)cin>>dic2[i];
	s = "EEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEESESEEEESEEEESEEEESEEEES";
	FOR(i,0,s.size()){
		if(s[i]=='E'){
			w=dic[1];
			dic[1]=dic[4];
			dic[4]=dic[6];
			dic[6]=dic[3];
			dic[3]=w;
		}else if(s[i]=='W'){
			w=dic[1];
			dic[1]=dic[3];
			dic[3]=dic[6];
			dic[6]=dic[4];
			dic[4]=w;
		}else if(s[i]=='N'){
			w=dic[1];
			dic[1]=dic[2];
			dic[2]=dic[6];
			dic[6]=dic[5];
			dic[5]=w;
		}else{
			w=dic[1];
			dic[1]=dic[5];
			dic[5]=dic[6];
			dic[6]=dic[2];
			dic[2]=w;
		}
		FOR(i,1,7){
			if(dic[i]!=dic2[i])break;
			if(i==6)ans = true;
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3236
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <deque>
using namespace std;
#define ll long long
#define F first
//#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pii pair<pi,int>
#define sqr(x) ((x)*(x))
#define FOR for(int i=0;i<n;i++)for(int j=0;j<m;j++)
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    int a[n+1][n+1];
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)a[i][j]=0;
    for(int i=0;i<m;i++){int l,r;cin>>l>>r;a[l][r]++;}
    int b[n+1][n+1];
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)b[i][j]=0;
    for(int j=1;j<=n;j++){
        b[j][j]=a[j][j];
        for(int i=j-1;i>=1;i--)b[i][j]=b[i+1][j]+a[i][j];}
    int ans[n+1][n+1];
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)ans[i][j]=0;
    for(int i=1;i<=n;i++){
        ans[i][i]=a[i][i];
        for(int j=i+1;j<=n;j++)ans[i][j]=ans[i][j-1]+b[i][j];}
    while(q--){
        int p,q;
        cin>>p>>q;
        cout<<ans[p][q]<<"\n";}}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N{}; cin >> N;
  vector<ui> vc(N);
  boost::for_each(vc, [](auto& v){ cin >> v; });

  auto m = boost::max_element(vc);
  auto ans = boost::accumulate(vc, 0U);
  ans -= *m / 2;
  cout << ans << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

long long gcd(long long a,long long b){
	ll c;
	while(a%b){
		c = b;
		b = a%b;
		a = c;
	}
	return b;
}
int main(void){
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N);
	bool ok = 0;
	long long max = 0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		max = std::max(max,a[i]);
		if(a[i]==K)ok = 1;
	}
	long long sum = a[0];
	for(int i=0;i<N;i++){
		sum = gcd(sum,a[i]);
	}
	if(K<=max){
		if(K%sum == 0)ok = 1;
	}
	if(ok)cout << "POSSIBLE" << endl;
	else cout <<"IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
ll calc(ll a){
    a++;
    ll res=0;
    for(int i=0;i<50;i++){
        ll loop=(1ll<<(i+1));
        ll cnt=(a/loop)*(loop/2);
        cnt+=max(0ll,(a%loop)-(loop/2));
        if(cnt%2==1) res+=1ll<<i;
    }
    return res;
}
int main(){
    ll a,b;cin >> a >> b;
    ll ans=calc(b)^calc(a-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def kuku()
	a = [1,2,3,4,5,6,7,8,9]
	b = [1,2,3,4,5,6,7,8,9]
	c = Array.new(9).map{Array.new(9)}
	9.times do |i|
		9.times do |j|
			c[i][j] = a[i] * b[j]
			puts "#{i + 1}x#{j + 1}=#{c[i][j]}"
		end
	end
end

kuku()

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
   return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}

ll ff(ll x){
  return x * (x+1) / 2;
}

int main(){
  ll n;

  cin>>n;

  ll l =0;
  ll r= 1000000000;

  while(l<=r){
    //cout <<r<<l<<endl;
    if(ff((l+r)/2)>n){
      r=(l+r)/2;
    }
    else l=(r+l)/2;
    if(ff(l)<n && ff(l+1)>n){
      cout << l+1<<endl;
      return 0;
    }
    if(ff(l)==n && ff(l+1)>=n){
      cout << l<<endl;
      return 0;
    }

  }
  cout<<l<<endl;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector <long long> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,e,t;
        cin>>b>>e>>t;
        swap_ranges(a.begin()+b,a.begin()+e,a.begin()+t);
    }
    int j;
    for(j=0;j<n-1;j++)
    {
        cout<<a[j]<<" ";
    }
    cout<<a[j]<<endl;
    return 0;
}



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

int main() {
    long mod = 1e9+7;
    int H, W;
    cin>>H>>W;
    string a[H];
    for(int i=0;i<H;++i){
        cin>>a[i];
    }
    int ans[H][W];
    ans[0][0] = 1;
    bool kabe = false;
    for(int i=1;i<H;++i){
        if(a[i][0] == '#') kabe = true;
        if(kabe)ans[i][0] = 0;
        else ans[i][0] = 1;
    }
    kabe = false;
    for(int j=1;j<W;++j){
        if(a[0][j] == '#') kabe = true;
        if(kabe)ans[0][j] = 0;
        else ans[0][j] = 1;
    }
    for(int i=1;i<H;++i){
        for(int j=1;j<W;++j){
            if(a[i][j] == '#')ans[i][j] = 0;
            else ans[i][j] = (ans[i-1][j] + ans[i][j-1])%mod;
        }
    }
    cout<<ans[H-1][W-1]%mod<<endl;
}


Measured memory_bytes: 5248
while True:
    n=input()
    if n==0:
        break
    s=map(float,raw_input().split())
    m=sum(s)/len(s)
    bunsan=0
    for i in range(n):
        bunsan+=(s[i]-m)**2
    bunsan=bunsan/n
    hensa=bunsan**(0.5)
    print hensa


Measured memory_bytes: 4776
#include <stdio.h>

int main(void)
{
        int a,b,x,y,i;

        scanf("%d%d",&a,&b);

        x=0;y=0;
        for(i=1;i<1010;i++){
                x=i*0.08;
                y=i*0.1;
                if(x==a && y==b) {
                        printf("%d",i);
                        return 0;
                }
        }

        printf("-1");
        return 0;
}



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


int main() {

	int a, b;
	int coin = 0;

	cin >> a >> b;


	for (int i = 0; i < 2; i++) {
		if (a - b > 0) {
			coin += a;
			a--;
		}
		else {
			coin += b;
			b--;
		}
	}

	cout << coin << endl;


	return 0;
}

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

int main(){
    int tmp,a,b,result=0,min=10;
    for(int i=0;i<5;i++){
        cin >> tmp;
        a = tmp/10;
        b = tmp%10;
        if(b==0){
            result += a*10;
        }else{
            result += a*10+10;
        }
        if(b!=0 && b<min){
            min=b;
        }
    }
    result -= 10-min;
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

type pair struct {
	key int
	val int
}
type pairlist []pair

func (p pairlist) Len() int           { return len(p) }
func (p pairlist) Less(i, j int) bool { return p[i].val > p[j].val }
func (p pairlist) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func sortMapByValue(m map[int]int) pairlist {
	pl := make(pairlist, len(m))
	i := 0
	for k, v := range m {
		pl[i] = pair{k, v}
		i++
	}
	sort.Sort(pl)
	return pl
}

func f(a []int) (pair, pair) {
	if len(a) == 0 {
		panic("hoge")
	}

	m := make(map[int]int)
	for _, aa := range a {
		m[aa]++
	}
	sorted := sortMapByValue(m)

	var x, y pair
	if len(sorted) == 1 {
		x, y = sorted[0], pair{-1, 0}
	} else {
		x, y = sorted[0], sorted[1]
	}
	return x, y
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	vo := make([]int, 0, n/2)
	ve := make([]int, 0, n/2)
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			vo = append(vo, ri())
		} else {
			ve = append(ve, ri())
		}
	}
	odd_1, odd_2 := f(vo)
	evn_1, evn_2 := f(ve)
	cost := -1
	if odd_1.key != evn_1.key {
		cost = len(vo) - odd_1.val + len(ve) - evn_1.val
	} else {
		tmp1 := len(vo) - odd_1.val + len(ve) - evn_2.val
		tmp2 := len(vo) - odd_2.val + len(ve) - evn_1.val
		cost = smaller(tmp1, tmp2)
	}
	fmt.Println(cost)
}


Measured memory_bytes: 6784
#include<iostream>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll mod=1e9+7;
    ll arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    ll suf[n];
    ll sum=0;
    for(int i=n-1; i>=0; i--) {
        suf[i]=sum%mod;
        sum+=arr[i];
    }
    ll ans=0;
    for(int i=0; i<n; i++)
        ans+=(arr[i]*suf[i])%mod;
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 6760
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    h = h +(m/60);
    double ans = a*a + b*b - 2*a*b*cos((M_PI*m/30)-(M_PI*h/6));
    ans = pow(ans,0.5);
    cout<<setprecision(10);
    cout<<ans;
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 4372
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int p = partition(a, 0, a.length - 1);
        printArray(a, p);
    }

    private static int partition(int[] a, int left, int right) {
        int partition = a[right];
        int i = left;
        for (int j = left; j < right; j++) {
            if (a[j] <= partition) {
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                i++;
            }
        }
        int tmp = a[i];
        a[i] = a[right];
        a[right] = tmp;
        return i;
    }

    private static void printArray(int/*or long*/[] array, int p) {
        if (array.length == 0) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            if (i == p) {
                sb.append("[").append(array[i]).append("]");
            } else {
                sb.append(array[i]);
            }
            if (i != array.length - 1) {
                sb.append(" ");
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 69028
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;

int main()
{
    int N;
    ll ans = 3*1e9;
    cin >> N;

    vector <ll> a(N, 0), s(N, 0);

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

    for (int i = 0; i < N-1; i++) {
        ans = min(ans, abs(s[N-1] - 2*s[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
};
int n,m;
main()
{
	while(cin>>n>>m,n)
	{
		vector<pair<int,pair<int,int> > >E;
		for(int i=0;i<m;i++)
		{
			int s,t,c;cin>>s>>t>>c;
			E.push_back(make_pair(c,make_pair(s,t)));
		}
		sort(E.begin(),E.end());
		UF uf(n+1);
		int ans,cnt=0;
		for(int i=0;i<m;i++)
		{
			if(uf.unite(E[i].second.first,E[i].second.second))
			{
				cnt++;
				if(cnt==n/2)ans=E[i].first;
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<int> v;

int main(void){
	int n,m,i;
	cin >> n >> m;
	i=1;
	while(i*i<=m){
		if(m%i==0){
			v.push_back(i);
			v.push_back(m/i);
		}
		++i;
	}
	sort(v.begin(),v.end());
	i = 0;
	while(true){
		if(v[i]>=n){
			cout << (m/v[i]) << endl;
			return 0;
		}
		++i;
	}
	return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>

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

using namespace std;

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

int h,w,c;

struct Panel{ int a[8][8]; };
struct Point{ int x,y; };

int count(const Panel &pnl){
	int ans=1;
	bool visited[8][8]={}; visited[0][0]=true;

	queue<Point> qu; qu.push((Point){0,0});
	while(!qu.empty()){
		Point p=qu.front(); qu.pop();
		rep(i,4){
			Point q={p.x+dx[i],p.y+dy[i]};
			if(0<=q.y && q.y<h && 0<=q.x && q.x<w
			&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==c){
				visited[q.y][q.x]=true;
				ans++;
				qu.push((Point){q.x,q.y});
			}
		}
	}

	return ans;
}

int dfs(Panel pnl,int depth){
	if(depth==5) return count(pnl);

	int ans=0;
	char prev=pnl.a[0][0];
	for(int cc=1;cc<=6;cc++){
		Panel tmp=pnl;

		pnl.a[0][0]=cc;
		bool visited[8][8]={}; visited[0][0]=true;
		queue<Point> qu; qu.push((Point){0,0});
		while(!qu.empty()){
			Point p=qu.front(); qu.pop();
			rep(i,4){
				Point q={p.x+dx[i],p.y+dy[i]};
				if(0<=q.y && q.y<h && 0<=q.x && q.x<w
				&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==prev){
					visited[q.y][q.x]=true;
					pnl.a[q.y][q.x]=cc;
					qu.push((Point){q.x,q.y});
				}
			}
		}

		ans=max(ans,dfs(pnl,depth+1));

		pnl=tmp;
	}

	return ans;
}

int main(){
	for(;scanf("%d%d%d",&h,&w,&c),h;){
		Panel pnl;
		rep(i,h) rep(j,w) scanf("%d",&pnl.a[i][j]);

		printf("%d\n",dfs(pnl,0));
	}

	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    ll A;
    string Bd;
    cin >> A >> Bd;
    ll B = (Bd[0] - '0') * 100 + (Bd[2] - '0') * 10 + (Bd[3] - '0');
    ll res = A * B / 100;
    cout << res << endl;
    return 0;
}


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

int main(){
    int H,W;
    cin>>H>>W;
    
    while(H!=0&&W!=0){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i%2==0&&j%2==0)||(i%2!=0&&j%2!=0)) cout<<"#"<<flush;
                else cout<<"."<<flush;
            }
            cout<<endl;
        }
        cout<<endl;
        cin>>H>>W;
    }
    
}


Measured memory_bytes: 3096
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let n = read_line().into_bytes();
    for i in 0..n.len() {
        if n[i] != n[n.len() - 1 - i as usize] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll H, W;

int main() {
   cin >> H >> W;
   ll ans = 1e18;

   if (H % 3 == 0 || W % 3 == 0) ans = 0;

   for (int k = 0; k < 2; k++) {
      for (int h1 = 1; h1 < H; h1++) {
         int h2 = H - h1;
         ll a = h1 * W;
         ll b = h2 * (W / 2);
         ll c = h2 * ((W + 1)/ 2);
         // printf("%lld\n", abs(max({a, b, c}) - min({a, b, c})));

         ll d = abs(h1 * W - (h1+1)*W);

         ans = min(ans, max({a, b, c}) - min({a, b, c}));
         ans = min(ans, d);
      }
      swap(H, W);
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;

struct lamp{
    int p;
    int k;
    int* s;
};

const long long mod = 1e9+7;

int main(){
	int n, sum, max;
    sum = 0;
    max = 0;
    int* l;
    cin >> n;
    l = new int[n];
    for(int i = 0; i < n; i++){
        cin >> l[i];
        sum += l[i];
        if(max < l[i]) max = l[i];
    }

    if(sum - max <= max) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final long MOD=1000000007;//998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int N=sc.nextInt();
		long[] A=sc.nextLongArray(N);
		long max=0;
		long count=0;
		for (int i = 0; i < A.length; i++) {
			if (max>A[i]) {
				count+=max-A[i];
				A[i]=max;
			}
			max=Math.max(max, A[i]);
		}
		System.out.println(count);
 	}
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		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;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 35884
A,B,C,X,Y = map(int,input().split())

a = max([X,Y])
s = 0

for i in range(0,2*a+1,2):
    x = X-i/2 if X-i/2 > 0 else 0
    y = Y-i/2 if Y-i/2 > 0 else 0
    S = A*x + B*y + C*i
    if s == 0:
        s = S
    else:
        if s > S:
            s = S
        else:
            continue

print(int(s))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;
short int result = 0;
short int *color; /*
    0 - black
    1 - grey
    2 - white
*/

vector<short int> *g; // Graph

void DFS(short int v){
    int node;
    color[v] = 1;

    for(short int i = 0; i < g[v].size(); i++){
        node = g[v].at(i);

        if(color[node] == 1){
            result = 1;
        }
        if(color[node] == 2){
            DFS(node);
        }
    }
    color[v] = 0;

};


int main() {

    short int E; // number of transitions
    short int s, t; // transitions
    short int V; // number of nodes

    // get properties of Graph
    cin >> V >> E;

    color = new short int[V];
    g = new vector<short int>[V];


    // fill Graph
    for(short int i = 0; i < E; i++){
        cin >> s >> t;
        g[s].push_back(t);
    }
    for(short int i = 0; i < V; i++){
        color[i] = 2;
    }
    for(short int i = 0; i < V; i++){
        if(color[i] == 2){
            DFS(i);
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3132
def rec(n, p, m)
  return 1 if p == 0
  if p % 2 == 0
    tmp = rec(n, p / 2, m)
    return tmp * tmp % m
  end
  n * rec(n, p - 1, m) % m
end
x, y = gets.chomp.split(' ').map(&:to_i)
xy = x + y
mod = (1e+9 + 7).to_i
if xy % 3 != 0
  puts 0
else
  n = xy / 3
  if !(x >= n && x <= 2 * n && y >= n && y <= 2 * n)
    puts 0
  else
    r = x - n
    arr = Array.new(n)
    arr[0] = 1
    (1...n).each do |i|
      arr[i] = arr[i - 1] * (i + 1) % mod
    end
    arr.unshift(1)
    a = arr[n]
    b = arr[n - r]
    c = arr[r]
    bc = (b * c) % mod
    puts (a * rec(bc, mod - 2, mod)) % mod
  end
end


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if(a1 <= a3 && a3 <= a2 || a2 <= a3 && a3 <= a1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256