akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
double solve(const vector<vector<int> > &graph, int ver) {
  int n = graph.size();
  if (graph[ver].size() == 1) return LINF;
  vector<double> dp(n, LINF);
  dp[n - 1] = 0;
  for (int i = n - 2; i >= 0; --i) {
    double sum = 0, mx = 0;
    for (int e : graph[i]) {
      sum += dp[e] + 1;
      mx = max(mx, dp[e] + 1);
    }
    if (i == ver) {
      dp[i] = (sum - mx) / (graph[i].size() - 1);
    } else {
      dp[i] = sum / graph[i].size();
    }
  }
  return dp[0];
}

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int> > graph(n);
  while (m--) {
    int s, t; cin >> s >> t; --s; --t;
    graph[s].emplace_back(t);
  }
  double ans = n - 1;
  REP(i, n - 1) ans = min(ans, solve(graph, i));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Segment():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)
        if self.p1.x == self.p2.x:
            self.a = float('inf')
            self.b = None
        else:
            self.a = (self.p1.y - self.p2.y)/(self.p1.x - self.p2.x)
            self.b = self.p1.y - self.a*self.p1.x

    def is_intersect(self, seg):
        a = (seg.p1.x - seg.p2.x) * (self.p1.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p1.x)
        b = (seg.p1.x - seg.p2.x) * (self.p2.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p2.x)
        c = (self.p1.x - self.p2.x) * (seg.p1.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p1.x)
        d = (self.p1.x - self.p2.x) * (seg.p2.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p2.x)
        e = (self.p1.x - seg.p1.x)*(self.p2.x - seg.p2.x)
        f = (self.p1.x - seg.p2.x)*(self.p2.x - seg.p1.x)
        g = (self.p1.y - seg.p1.y)*(self.p2.y - seg.p2.y)
        h = (self.p1.y - seg.p2.y)*(self.p2.y - seg.p1.y)
        return a*b <= 0 and c*d <= 0 and (e <= 0 or f <= 0) and (g <= 0 or h <= 0)

    def cross_point(self, seg):
        if self.is_intersect(seg) == False: return None
        if self.a == float('inf'):
            return self.p1.x, seg.a * self.p1.x + seg.b
        elif seg.a == float('inf'):
            return seg.p1.x, self.a * seg.p1.x + self.b
        else:
            x = -(self.b - seg.b)/(self.a - seg.a)
            y = seg.a * x + seg.b
            return x, y

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Segment(x0, y0, x1, y1), Segment(x2, y2, x3, y3)
    x, y = line1.cross_point(line2)
    print('%.8f %.8f'%(x, y))


Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
long int n;
int main()
{
    cin>>n;
    long long a[n+2];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    a[0]=a[1];
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<a[i-1])
        {
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 5120
using System;

namespace ABC
{
    class ABC075B
    {
        private static int Width = 0;
        private static int Height = 0;
        private static char[] SList = null;
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            Height = int.Parse(str[0]);
            Width = int.Parse(str[1]);
            SList = new char[Height * Width];
            for(int h = 0; h < Height; ++h)
            {
                var fieldstr = Console.ReadLine();
                for (int w = 0; w < Width; ++w) {
                    SList[getMasuIdx(w, h)] = fieldstr[w];
                }
            }

            for (int h = 0; h < Height; ++h)
            {
                for (int w = 0; w < Width; ++w)
                {
                    int ans = countBomb(w, h);
                    if(ans != -1) {
                        SList[getMasuIdx(w, h)] = (char)(ans + '0');
                    }
                }
            }

            for (int h = 0; h < Height; ++h)
            {
                for (int w = 0; w < Width; ++w)
                {
                    Console.Write("{0}", SList[getMasuIdx(w, h)]);
                }
                Console.WriteLine();
            }

        }

        private static int getMasuIdx(int w, int h)
        {
            return h * Width + w;
        }


        private static int countBomb(int targetW, int targetH)
        {
            int cnt = 0;
            {//調べたところ自体が爆弾なら
                int masuIdx = getMasuIdx(targetW, targetH);
                if(SList[masuIdx] == '#') { return -1; }
            }
            for (int h = -1; h <= 1; ++h) {
                if(targetH + h < 0 || Height <= targetH + h)
                {
                    continue;
                }
                for (int w = -1; w <= 1; ++w)
                {
                    if (targetW + w < 0 || Width <= targetW + w)
                    {
                        continue;
                    }
                    int masuIdx = getMasuIdx(targetW + w, targetH + h);
                    if(SList[masuIdx] == '#')
                    {
                        cnt++;
                    }
                }
            }
            return cnt;
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <list>
//#include <cmath>
#include <random>
#include <algorithm>

using std::cout;
using std::cerr;
using std::cin;
using std::endl;

using std::vector;
using std::list;
using std::string;

void funcA()
{
	string S;
	string T;
	cin >> S;
	cin >> T;
	int x = 0;
	if (S[0] == T[0]) {
		x++;
	}
	if (S[1] == T[1]) {
		x++;
	}
	if (S[2] == T[2]) {
		x++;
	}
	cout << x << endl;
}

void funcB()
{
	int A;
	int B;
	cin >> A;
	cin >> B;
	int C = 1;

	int cnt = 0;
	while (C < B) {
		C += (A - 1);
		cnt++;
	}
	cout << cnt << endl;

}
void func()
{
	int N;
	vector<int> H;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int h;
		cin >> h;
		H.push_back(h);
	}

	int cnt_max = 0;
	int cnt = 0;
	for (int i = 0; i < N-1; ++i) {
		if (H[i] >= H[i + 1]) {
			cnt++;
			if (cnt >= cnt_max) {
				cnt_max = cnt;
			}
		}
		else {
			cnt = 0;
		}
	}
	cout << cnt_max;


}

int main() {
	func();

}




Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
using namespace std ;
using ll = long long ;

int main(){
    ll n ; cin >> n ;
    ll ans = 0 ;
    for(int i=0;i<n;i++){
        ll a ; cin >> a ;
        ans += a ;
    }
    cout << ans -n << endl ;
}


Measured memory_bytes: 256
q,h,s,d=map(int,input().split())
n=int(input())
h=min(h,2*q)
s=min(s,2*h)
if 2*s<=d:
    print(n*s)
else:
    if n%2==0:
        print(d*(n//2))
    else:
        print(d*(n//2)+s)


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

int main() {
    ll a, b, k;
    cin >> a >> b >> k;

    if (a >= k) {
        cout << a -k << " " << b << endl;
        return 0;
    }
    k -= a;

    if (b >= k) {
        cout << "0" << " " << b - k;
    }
    else
        cout << "0" << " " << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    goods, weight_limit = map(int, input().split())
    good_info = [tuple(map(int, input().split())) for _ in range(goods)]
    dp = [[0 for _ in range(weight_limit + 1)] for _ in range(goods + 1)]
    for i in range(goods):
        for j in range(weight_limit + 1):
            if j >= good_info[i][0]:
                dp[i + 1][j] = max(dp[i][j], dp[i][j - good_info[i][0]] + good_info[i][1])
            else:
                dp[i + 1][j] = dp[i][j]
    print(dp[goods][weight_limit])


if __name__ == '__main__':
    main()



Measured memory_bytes: 171912
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;

ll Abs(ll x){
    if(x < 0) return -x;
    return x;
}

int main() {
    ll x, y;
    while(scanf("%lld %lld", &x, &y) != EOF) {
        long long temp = Abs(x - y);
        if(temp <= 1) printf("Brown\n");
        else printf("Alice\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int n;
    int cnt=0;
    cin >> n;
    int a[n] ={0};
    string s[n];
    string t[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
        t[i] = s[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(s[i] == t[j]){
                a[i]++;
            }
        }
    }
    int m;
    cin >> m;
    string u[m];
    for(int i = 0;i<m;i++){
         cin >> u[i];
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            if(s[j] == u[i]){
                a[j]--;
            }
        }   
    }
    int maxa = 0;
    for(int i = 0;i < n; i++){
         if(maxa < a[i])
            maxa = a[i];
    }
    cout << maxa;
}

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

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

    vector<char> s(n);
    int r = 0, w = 0;
    for (int i = 0; i < n; i++){
        cin >> s[i];

        if (s[i] == 'R')
            r += 1;
        else
            w += 1;
    }

    int ans = 0;
    for (int i = 0; i < r; i++){
        if (s[i] == 'W')
            ans += 1;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int>a(A), b(B), x(M), y(M),c(M);
	rep(i, A) {
		cin >> a[i];
	}
	rep(i, B) {
		cin >> b[i];
	}
	int res1 = 1010101;
	rep(i, M) {
		cin >> x[i] >> y[i] >> c[i];
		res1 = min(res1, a[x[i]-1] + b[y[i]-1] - c[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int res2 = a[0] + b[0];
	int ans = min(res1, res2);
	cout << ans << endl;
	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto gcd = [](long long int x, long long int y) -> long long int {
		long long int s;
		while((s = x % y) != 0){
			x = y;
			y = s;
		}
		return y;
	};
	long long int ans;
	cin >> ans;
	for(auto i = 1; i < n; ++i){
		long long int t;
		cin >> t;
		auto g = gcd(ans, t);
		ans = ans / g * t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int cmp(string a, string b){
    for(int i=0;i<min(a.size(), b.size());i++){
        if(a[i]==b[i])
            continue;
        else if(a[i]<b[i])
            return 1;
        else 
            return 0;
    }
    if(a.size()<b.size())
        return 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    t = 1;
    while(t--){
        int n, l;
        cin>>n>>l;
        string st[n];
        for(int i=0;i<n;i++)
            cin>>st[i];
        sort(st, st+n, cmp);
        string str;
        for(int i=0;i<n;i++)
            str += st[i];
        cout<<str<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 510000;
int trans(string s){
    if(s == "Vacant") exit(0);
    else if(s == "Male") return 0;
    else return 1;
}
signed main(void){
    int n; cin>>n;
    ios::sync_with_stdio(false);
    int cnt = 0;
    int l = 0,r = n;
    int first; //0男1女
    cout<<0<<endl;
    cout.flush();
    cnt++;
    string tmp;
    cin>>tmp;
    first = trans(tmp);
    while(abs(l-r)>1){
        int mid = (l+r)/2;
        cnt++;
        assert(cnt<=20);
        cout<<mid<<endl;
        cout.flush(); 
        cin>>tmp;
        int now = trans(tmp);
        bool ok = true;
        if(mid%2){
            if(now != first) ok = true;
            else ok = false;
        }else{
            if(now==first) ok = true;
            else ok = false;
        }
        if(ok) l = mid;
        else r = mid;
    }
}


Measured memory_bytes: 852
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: u64);
    let mut ans: u64 = 0;
    for i in 1 as u64 ..= n {
        let first = i;
        let last = n / i * i;
        let count = (last - first) / i + 1;
        ans += (first + last) * count / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
# coding: utf-8
# Here your code !
n,k=[int(x) for x in input().split()]
x=[0]*n
y=[0]*n
for i in range(n):
   x[i],y[i]=[int(x) for x in input().split()]
from itertools import product
ans=float("inf")
for xmax,xmin,ymax,ymin in product(x,x,y,y):
    if xmax<=xmin or ymax<=ymin or (xmax-xmin)*(ymax-ymin)>=ans:
        continue
    if len([0 for xi,yi in zip(x,y) if xmin<=xi<=xmax and ymin<=yi<=ymax])>=k:
        ans=(xmax-xmin)*(ymax-ymin)
print(ans)

Measured memory_bytes: 64220
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}


int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int h, a;

signed main() {
	cin >> h >> a;
	cout << (h - 1) / a + 1 << endl;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
    ll a, b;
    cin >> a >> b;
    if(a<=9&&b<=9){
        cout << a*b<< endl;
    }
    else{
        cout<<"-1"<<endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,vis[maxn],c1,c2,ans;
vector <int> mp[maxn];

inline void dfs(int u)
{
	vis[u]=1; if(u<=100000) c1++; else c2++;
	for(int i=0;i<mp[u].size();i++)
	{
		int v=mp[u][i];
		if(!vis[v]) dfs(v);
	}
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();
		mp[x].push_back(y+100000);
		mp[y+100000].push_back(x);
	}
	for(int i=1;i<=100000;i++) if(!vis[i]) c1=0,c2=0,dfs(i),ans+=c1*c2;
	cout<<ans-n<<endl;
	return 0;
}

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

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

    int a[n];
    int ev = 0;
    int od = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];

        if(a[i] % 2 == 0){
            ev++;
        }else{
            od++;
        }
    }

    int ans = 1;
    for(int i = 0; i < n; i++){
        if(a[i] % 2 == 0){
            ans *= 2;
        }
    }

    cout << pow(3, n) - ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int dup = 0;
  int c=a[0];
  for(int i=1; i<n; i++) {
    if(c==a[i]) {
      dup++;
    } else {
      c=a[i];
    }
  }
  if(dup%2==0) {
    cout << (n-dup) << endl;
  } else {
    cout << (n-dup-1)<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	t := make([]int, 3)
	for _, v := range s {
		t[v-'a']++
	}
	if t[0] == 1 && t[1] == 1 && t[2] == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, D;
ll X[20][20];
bool ok[101010];
ll ans;
int main(){
	cin >> N >> D;
	for(ll i=1; i*i<=101010; i++){
		ok[i*i]=true;
	}
	REP(i,0,N){
		REP(j,0,D){
			cin >> X[i][j];
		}
	}
	REP(i,0,N){
		REP(j,i+1,N){
			ll sum=0;
			REP(k,0,D){
				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			if(ok[sum]) ans++;
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 384
def is_all_lighting(switch_patten, s_info_list, p_list):
    for i in range(len(s_info_list)):
        s_info = s_info_list[i]
        on_count = 0
        for s in s_info['s_list']:
            on_count += switch_patten // (2 ** (s - 1)) % 2
        if on_count % 2 != p_list[i]:
            return False
    return True


N, M = list(map(int, input().split()))
s_info_list = list()

for _ in range(M):
    val_list = list(map(int, input().split()))
    s_info_list.append({
        'k': val_list[0],
        's_list': val_list[1:]
    })
p_list = list(map(int, input().split()))

count = 0

for pattern in range(2 ** N):
    count += 1 if is_all_lighting(pattern, s_info_list, p_list) else 0

print(count)


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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0;
    for(long int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ans=a[n-1];
    long int p=n-2;
    for(long int i=n-2;i>=0,p>0;i--){
        if(p>=2){
            ans+=2*a[i];
        } else {
            ans+=a[i];
        }
        p-=2;
    }
    
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5228
N, K = map(int, input().split())
S = input()

count = len(S) - 1
mismatch = 0
for idx in range(len(S) - 1):
	if(S[idx] != S[idx+1]):
		mismatch += 1
mismatch = max(0, mismatch - 2 * K)
print(count - mismatch)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  double sum;
  sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    double x;
    string s;
    cin >> x >> s;
      if (s == "JPY") {
      sum += x;
    }
    else if (s == "BTC") {
      sum += x * 380000.0;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "math"
)

const inf = math.MaxInt32
 
func min(nums ...int) int {
    if len(nums) == 0 {
        panic("funciton min() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}
  
func main() {
  var n int
  fmt.Scan(&n) 
  dp := make([]int, n+1)
 
  for i := range dp {
    dp[i] = inf
  }

  dp[0] = 0

  for i := 1; i <= n; i++ {
    
    for j := 1; j <= i; j*=6 {
      dp[i] = min(dp[i], dp[i-j]+1)
    }

    for k := 1; k <= i; k*=9 {
      dp[i] = min(dp[i], dp[i-k]+1)
    }
  }
  fmt.Println(dp[n])
}

Measured memory_bytes: 1280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author palayutm
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            out.println(n / 3);
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream out) {
            super(out);
        }

        public OutputWriter(Writer out) {
            super(out);
        }

        public void close() {
            super.close();
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

int64_t solve(long long n, long long a, long long b) {
    if(a > b) swap(a, b);
    if((b-a)%2 == 0) {
        return  (b-a) / 2;

    }
    else {
        if(b-a == 1) return a;
        else {
            return a + (b-a-1) /2;
        }
    }
}

int main() {
#ifdef gsdt
    freopen("input.txt", "r", stdin);
#endif
    int64_t n, a, b; cin>>n>>a>>b;
    int64_t res = solve(n, a, b);
    a = n+1-a;
    b = n+1-b;
    res = min(res, solve(n, a, b));
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll add(ll a,ll b){
  return (a+b)%mod;
}

string s;
int t[2005];

ll n;
ll A[26][2005];
ll B[26][2005];


ll mem2[2005][2005];
set<ll> T[26];

ll Counting(int l,int r){
  ll res=0;
  for(int i=0;i<26;i++){
    set<ll> :: iterator it = T[i].lower_bound(l);
    if(it != T[i].end() &&  *it <= r)res++;
  }
  return res;
}

ll solve2(int l,int r){
  if(mem2[l][r]!=-1)return mem2[l][r];

  
  ll res= Counting(l,r);
  for(int i=0;i<26;i++){
    int nl=B[i][l];
    int nr=A[i][r];

    
    if(nl+1<=nr-1){
      res=add(res, solve2(nl+1,nr-1) );
    }
  }
  return mem2[l][r]=res;
}

ll mem[2005][2005];

ll solve(int l,int r){
  if(mem[l][r]!=-1)return mem[l][r];
  if(l+1==r)return (t[l]==t[l+1]?2:1);
  
  ll res=1;
  for(int i=0;i<26;i++){
    int nl=B[i][l];
    int nr=A[i][r];
    if(nl==nr){
      continue;
    }
    if(nl+1==nr){
      res++;
      continue;
    }
    if(nl+1<=nr-1){
      res=add(res, solve(nl+1,nr-1) );
    }
  }
  return mem[l][r]=res;
}
int main(){
  memset(mem,-1,sizeof(mem));
  memset(mem2,-1,sizeof(mem2));
  cin>>s;
  
  n=s.size();
  
  for(int i=0;i<n;i++){
    t[i+1]=s[i]-'a';

    T[ t[i+1] ].insert(i+1);
  }
  
  for(int i=0;i<26;i++){
    A[i][0]=-1;
    for(int j=1;j<=n;j++){
      if(i==t[j])A[i][j]=j;
      else A[i][j]=A[i][j-1];
    }
  }

  for(int i=0;i<26;i++){
    B[i][n+1]=n+1;
    for(int j=n;j>=1;j--){
      if(i==t[j])B[i][j]=j;
      else B[i][j]=B[i][j+1];
    }
  }

  cout<< ( solve(1,n) + solve2(1,n) + mod - 1 ) %mod <<endl;
  //cout<< solve(1,n) <<endl;
  //cout<< solve2(1,n) <<endl;
  return 0;
}



Measured memory_bytes: 66948
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	b, _ := strconv.Atoi(sc.Text())

	sum := a + b
	if sum%2 != 0 {
		fmt.Println("IMPOSSIBLE")
		return
	}

	fmt.Println(sum / 2)
	return

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long ans,n,k,num1,num2;
int main(){
	cin>>n>>k;
	num1=n/k;
	ans+=num1*num1*num1;
    if(k%2==0) num2=n/(k/2)-n/k;
    ans+=num2*num2*num2;
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
const ll maxn=500005;
const ll mod=1e9+7;


int main(){
	fast;
	string n;
	cin>>n;
	int sum=0;
	for(char c : n){
		sum+=c-'0';
	}
	if(sum%9==0)
		cout<<"Yes";
	else
		cout<<"No";
}




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

long double to_degree(const long double x) {
    return x * 180 / M_PI;
}

int main() {
    long double a, b, x;
    std::cin >> a >> b >> x;

    std::cout << std::fixed << std::setprecision(10);

    const long double v0 = a * a * b / 2;

    if(x > v0) {
        const long double theta = std::atan2(2 * (a * a * b - x), a * a * a);
        std::cout << to_degree(theta);
    } else {
        const long double theta = std::atan2(a * b * b, 2 * x);
        std:: cout << to_degree(theta);
    }

    return 0;
}


Measured memory_bytes: 512
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int ans[502][502];

void solve(vector<int>&v,int base) {
	if (v.size() == 1)return;
	REP(i, v.size()) {
		for (int j = i + 1; j < v.size(); j += 2) {
			ans[v[i]][v[j]] = base;
		}
	}
	vector<int>v1, v2;
	REP(i, v.size()) {
		if (i % 2 == 0) {
			v1.pb(v[i]);
		}
		else {
			v2.pb(v[i]);
		}
	}
	solve(v1, base + 1);
	solve(v2, base + 1);
}

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

	int N; cin >> N;
	vector<int>v;
	REP(i, N) {
		v.pb(i);
	}
	solve(v, 1);

	REP(i, N - 1) {
		FOR(j, i + 1, N) {
			pe(ans[i][j]);
		}cout << endl;
	}
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define vi vector<int>
#define iii pair<int,pair<int,int>>
#define INF 1<<30

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,d,x;
	ll A[101];
	cin>>n>>d>>x;
	ll X=x;
	for (int i = 0; i < n; ++i)
	{
		cin>>A[i];
		X+=((d-1)/A[i]+1);
	}
	cout<<X;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int num;
  int t_prev, x_prev, y_prev;
  int t, x, y;
  int length;
  bool ans = true;
  
  cin >> num;
  t_prev = x_prev = y_prev = 0;
  
  for (int i = 0; i < num; i++) {
  	cin >> t >> x >> y;
    length = abs(x - x_prev) + abs(y - y_prev);
    if (length > t - t_prev ||
        ((length % 2) == 0 && ((t - t_prev) % 2) != 0) ||
        ((length % 2) != 0 && ((t - t_prev) % 2) == 0)) {
      ans = false;
      break;
    }
    else {
      x_prev = x;
      y_prev = y;
      t_prev = t;
    }
  }
  if (ans == true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
    	int k = sc.nextInt();

        if (10>n) {
        	int r = 100 * (10 - n);
        	k = r + k;
        }
    	System.out.println(k);
    }
}

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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<vector<pair<int,int>>> graph(N);
	for(int i=0;i<N-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		graph.at(a-1).push_back(make_pair(b-1,c));
		graph.at(b-1).push_back(make_pair(a-1,c));
	}
	int Q,K;
	cin >> Q >> K;
	K--;
	vector<int> x(Q),y(Q);
	for(int i=0;i<Q;i++){
		cin >> x.at(i) >> y.at(i);
		x.at(i)--;
		y.at(i)--;
	}

	vector<long long> dif(N,1e18);
	dif.at(K)=0;
	queue<int> V;
	V.push(K);
	while(!V.empty()){
		int v=V.front();
		V.pop();
		for(int i=0;i<graph.at(v).size();i++){
			int aa=graph.at(v).at(i).first;
			int cc=graph.at(v).at(i).second;
			if(dif.at(aa)!=1e18)	continue;
			dif.at(aa)=dif.at(v)+cc;
			V.push(aa);
		}
	}

	for(int i=0;i<Q;i++){
		cout << dif.at(x.at(i)) + dif.at(y.at(i)) << endl;
	}

	return 0;
}


Measured memory_bytes: 9588
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        uf.union(a,b)
    print(uf.group_count() - 1)
main()

Measured memory_bytes: 13092
#include<stdio.h>

int main(void)
{
        int a[3],tmp,sum;
        int i,j;

        scanf("%d%d%d",&a[0],&a[1],&a[2]);

        for(i=1;i<3;i++){
                for(j=2;j>=i;j--){
                        if(a[j]>a[j-1]){
                                tmp = a[j];
                                a[j] = a[j-1];
                                a[j-1] = tmp;
                        }
                }
        }

        sum = 0;
        sum = a[0] - a[1];
        sum +=a[1]-a[2];

        printf("%d\n",sum);
        return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC051
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string output = input.Replace(',', ' ');
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 2648
n=int(input())
s=input()
s1=s[:n]
s2=s[n:][::-1]
dic1={}
dic2={}
for i in range(2**n):
  r1=''
  r2=''
  b1=''
  b2=''
  flag=format(i,'b')
  l=len(flag)
  if l!=n:
    flag='0'*(n-l)+flag
  for j in range(n):
    if flag[j]=='0':
      r1+=s1[j]
      r2+=s2[j]
    else:
      b1+=s1[j]
      b2+=s2[j]
  if (r1,b1) not in dic1:
    dic1[(r1,b1)]=1
  else:
    dic1[(r1,b1)]+=1
  if (r2,b2) not in dic2:
    dic2[(r2,b2)]=1
  else:
    dic2[(r2,b2)]+=1
ans=0
for i in dic1.keys():
  if i in dic2:
    ans+=dic1[i]*dic2[i]
print(ans)

Measured memory_bytes: 170872
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  char[] s;
  cin.scan(s);
  size_t N = s.length;
  size_t M = (N - 1) / 2;
  size_t L = (N + 3) / 2;

  char[] t = s[0 .. M];
  char[] u = s[L - 1 .. $];


  auto s_r = s.dup;
  s_r.reverse;
  auto t_r = t.dup;
  t_r.reverse;
  auto u_r = u.dup;
  u_r.reverse;
  if (s == s_r && t == t_r && u == u_r) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
def read_input():
    s = input()
    t = input()
    return s, t


# s<tをチェックする
def greater_check(s, t):
    if len(s) < len(t):
        if s == t[:len(s)]:
            return True

    for i in range(min(len(s), len(t))):
        if s[i] < t[i]:
            return True

    return False

def submit():
    s, t = read_input()

    sc = [c for c in s]
    tc = [c for c in t]

    sc.sort()
    tc.sort(reverse=True)

    if greater_check(''.join(sc), ''.join(tc)):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    submit()

Measured memory_bytes: 38256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int i,l=0;
			int sum[] = new int [2000];
			int ave[] = new int [2000];

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int score[] = new int [n];
			int j=0,k=0;

			for(i=0;i<n;i++){
				score[i] = sc.nextInt();
				sum[l]+=score[i];
			}
			for(i=0;i<n;i++){
				if(score[i]>=score[j]){
					j=i;
				}
				if(score[i]<=score[k]){
					k=i;
				}
			}
			sum[l]-=score[j];
			sum[l]-=score[k];
			ave[l] = sum[l]/(n-2);
			l++;
		}
		for(i=0;i<l;i++){
			System.out.printf("%d\n",ave[i]);
		}
	}
}

Measured memory_bytes: 21128
import sys,math
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

a,b = iin()
print(math.ceil((b-1)/(a-1)))

Measured memory_bytes: 3060
N = int(input())
PX = PY = PT = 0

for _ in range(N):
  T,X,Y = map(int,input().split())
  if abs(X-PX)+abs(Y-PY)>T-PT or (X+Y-PX-PY)%2 != (T-PT)%2:
    print("No")
    exit()
  else:
    PX = X
    PY = Y
    PT = T
    
print("Yes")

Measured memory_bytes: 74204
#include<stdio.h>

int main(){
	
	int ns,we,h,i,j,k,l,tmp;
	int dice[6]={},muki[2][4]={{0,1,5,4},{0,3,5,2}};
	char cmd[101]={};
	for(h=0;h<6;h++)scanf("%d",&dice[h]);
	scanf("%s",cmd);
	
	for(h=0;h<100;h++){
		ns=0;
		we=0;
		if(cmd[h]=='N')ns=1; if(cmd[h]=='S')ns=-1;
		if(cmd[h]=='E')we=1; if(cmd[h]=='W')we=-1;
		if(ns!=0 || we!=0){
			k=we*we;
			l=ns;
			if(l==0)l=we;
			for(i=0;i<3;i++){
				j=i;
				if(l==-1)j=3-i;
				tmp=dice[muki[k][j]];
				dice[muki[k][j]]=dice[muki[k][j+l]];
				dice[muki[k][j+l]]=tmp;
			}
		}
	}
	
	printf("%d\n",dice[0]);
	
    return 0;

}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
inline int gi() {
  char ch=getchar(); int q=0,x=0;
  while(ch<'0'||ch>'9') q=(ch=='-'?1:q),ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int main(){
  long long a,b,c; cin>>a>>b>>c;
  cout<<min(a+2*b+1,b+c);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, m, j = 1, a[31], b[31], c[100];

int main(){
	char s;
	while(cin >> n >> s >> m, n+m){
		a[n] = m;
		b[m]++;
	}
	for(int i = 30;i >= 0;i--){
		if(b[i]){c[i] = j;j++;}
	}
	while(cin >> n){
		cout << c[a[n]] << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(a:i64 b:i64));
    std::cmp::max(a + b, std::cmp::max(a - b, a * b)).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "-13 3\n" => "-10\n",
    test2: "1 -33\n" => "34\n",
    test3: "13 3\n" => "39\n",
}


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

struct StCoord
{
  StCoord() : m_nx(0), m_ny(0), m_nHigh(0) { }

  int m_nx;
  int m_ny;
  int m_nHigh;
};

void fnInput(vector<StCoord>& rvoCoord)
{
  int nCoordSiz;
  cin >> nCoordSiz;
  rvoCoord.resize(nCoordSiz);

  for (StCoord& roCoord : rvoCoord)
    cin >> roCoord.m_nx >> roCoord.m_ny >> roCoord.m_nHigh;
}

int fnCenterHigh(StCoord oCenter, StCoord oCoord)
{
  return  abs(oCenter.m_nx - oCoord.m_nx) 
        + abs(oCenter.m_ny - oCoord.m_ny) + oCoord.m_nHigh;
}

bool fnCenterCheck(StCoord& roCenter, const vector<StCoord>& cnrvoCoord)
{
  int nCenterHigh = 0;

  for (int i = 0; i < cnrvoCoord.size(); ++i)
    if ( cnrvoCoord[i].m_nHigh )
      if ( !nCenterHigh )
        nCenterHigh = fnCenterHigh(roCenter, cnrvoCoord[i]);
      else
        if (nCenterHigh != fnCenterHigh(roCenter, cnrvoCoord[i]))
          return false;

  for (int i = 0; i < cnrvoCoord.size(); ++i)
    if ( !cnrvoCoord[i].m_nHigh )
      if (nCenterHigh <= fnCenterHigh(roCenter, cnrvoCoord[i]));
      else
        return false;

  roCenter.m_nHigh = nCenterHigh;
  return true;
}

void fnCenterCoord(const vector<StCoord>& cnrvoCoord)
{
  StCoord oCenter;
  bool bCenter = false;
  oCenter.m_nx = -1;

  while ( !bCenter       &&
          oCenter.m_nx < 101 )
  {
    ++oCenter.m_nx;
    oCenter.m_ny = -1;

    while ( !bCenter       &&
            oCenter.m_ny < 101 )
    {
      ++oCenter.m_ny;
      bCenter = fnCenterCheck(oCenter, cnrvoCoord);
    }
  }

  cout << oCenter.m_nx << " " << oCenter.m_ny << " " << oCenter.m_nHigh;
}
  
int main()
{
  vector<StCoord> voCoord;
  
  fnInput(voCoord);
  fnCenterCoord(voCoord);

  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N + 2, 0);
  for (ll i = 1; i < N + 1; i++)
  {
    cin >> A.at(i);
  }

  ll S = 0;
  for (ll i = 0; i < N + 1; i++)
  {
    S += abs(A.at(i + 1) - A.at(i));
  }

  for (ll i = 1; i < N + 1; i++)
  {
    ll d0 = abs(A.at(i + 1) - A.at(i));
    ll d1 = abs(A.at(i) - A.at(i - 1));
    ll d2 = abs(A.at(i + 1) - A.at(i - 1));
    ll ans = S - d0 - d1 + d2;
    cout << ans << endl;
  }
}

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

int main()
{
	int N;
	long long int * a;
	long long int sum=0, min;
	cin >> N;
	a = new long long int[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum -= 2 * a[0];
	min = abs(sum) ;
	for (int i = 1; i < N - 1 ; i++) {
		sum -= 2 * a[i];
		if (min > abs(sum))min = abs(sum);
	}
	cout << min;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  long double full = a * a * b;
  long double ans;
  if (full / 2 <= x) {
    ans = atan(2 * (full - x) / (a * a * a));
  } else {
    ans = PI / 2 - atan(2 * x / (a * b * b));
  }
  printf("%.9Lf\n", ans * 180 / PI);

  return 0;
}



Measured memory_bytes: 256