akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);

    int a = s.nextInt();
    int b = s.nextInt();

    if(a < b){
      System.out.println(0);
    }else if(a >= b){
      System.out.println(10);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main() 
{
	int a,b;
	cin >> a >> b;
	
	if ( a < b )
cout << "a < b" << endl;
	else if ( a > b )
cout << "a > b" << endl;
	else
cout << "a == b" << endl;

	return 0;
}


Measured memory_bytes: 3080
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var output = 0;
  for(var i = 0; i < N - 1; i++){
    for(var j = i + 1; j < N; j++){
      output += list[i] * list[j];
    }
  }
  myout(output);
}

Main(myin());


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

D = {}

for _ in range(M):
  a,b = map(int, input().split())
  if not b in D.keys():
    D[b] = a
  elif a > D[b]:
    D[b] = a

th = 0
count = 0
D = sorted(D.items(), key=lambda x: x[0])
for (e,s) in D:
  if ((th < s) or (e < th)):
    th = e - 1
    #print(s,e,th)
    count += 1
print(count)


Measured memory_bytes: 15600
#include<iostream>
using namespace std;
int main(){
	int n,m,i,x,k,a=0,b=0;
	cin >> n >> m >> x;
	for(i=0;i<m;i++)
	{
	    cin >> k;
	    if(k>x)
            a++;
        else
            b++;
	}
	if(a>b)
        a=b;
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int a[4005], s[4005][3];

int main()
{
    //freopen("a.in", "r", stdin);
    int n;
    scanf("%d\n", &n);
    for(int i = 1; i <= n; i++)
    {
        char c = getchar();
        switch(c)
        {
            case 'R':
                a[i] = 0;
                break;
            case 'G':
                a[i] = 1;
                break;
            default:
                a[i] = 2;
                break;
        }
    }
    for(int i = n; i; i--)
    {
        s[i][0] = s[i + 1][0];
        s[i][1] = s[i + 1][1];
        s[i][2] = s[i + 1][2];
        s[i][a[i]]++;
    }
    long long ans = 0;
    for(int i = 1; i < n; i++)
    for(int j = i + 1; j < n; j++)
    {
        if(a[i] == a[j]) continue;
        int k = 3 - a[i] - a[j];
        ans += 1LL * s[j + 1][k];
        if(2 * j - i <= n && a[2 * j - i] == k)
            ans--;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
int BIT[MAX_N];
int n;

int sum(int i)
{
	int res = 0;
	while(i > 0)
	{
		res += BIT[i];
		i -= i & -i;
	}
	return res;
}

void add(int i, int x)
{
	while(i <= n)
	{
		BIT[i] += x;
		i += i & -i;
	}
}

int main()
{
	int q;
	cin >> n >> q;
	rep(i,q)
	{
		int c,x,y;
		cin >> c >> x >> y;
		if (c == 0) add(x,y);
		else cout << sum(y) - sum(x-1) << endl;
	}
	return 0;
}


Measured memory_bytes: 3476
from sys import stdin

def solve(s):
    cnt = 0
    for i, color in enumerate(s):
        if i == 0:
            continue
        if s[i - 1] == color:
            s[i] = '0' if color == '1' else '1'
            cnt = cnt + 1
    return cnt


def main():
    s = list(stdin.readlines()[0])
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> C(M + 1);
    for (int i = 0; i < N; i++) {
        int K; cin >> K;
        while (K--) {
            int A; cin >> A;
            C[A]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < C.size(); i++) {
        if (C[i] == N) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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;
}

int main(void){
    int N,K; cin >> N >> K;
    vector<ll> h(N+110,0); for(int i = 0; i < N; i++) cin >> h.at(i);
    vector<ll> dp(N+1000,INF);
    
    dp[0] = 0;
    for(int i = 0; i <= N; i++){
        //cout << dp[i] << endl;
        for(int k = 1; k <= K; k++){
            chmin(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
        }
    }
    cout << dp[N-1] << endl;
}

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

int main(void){
    long long a,b,c;
    cin >> a >> b >> c;
    cout << ((4LL * a * b < (c-a-b) * (c-a-b) && (c-a-b >= 0)) ? "Yes" : "No") << endl;
    return 0;
}


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

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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int K, X;
  cin >> K >> X;
  if(500*K>=X)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" <<endl;
  }
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
    int n;
      cin >> n;
    
   pii a[n];
    f(i,n) cin >> a[i].F >> a[i].S;
 
  int res = abs(a[1].F - a[0].F) + abs(a[0].S - a[1].S);  
 
  sort(a,a+n); 
    
  set<int> mn,mx;
    
  mn.insert(a[0].F + a[0].S);
  mx.insert(a[0].F - a[0].S);
   
   for(int i=1;i<n;i++)
   {
       int temp = a[i].F - a[i].S - (*mx.begin());
       temp = max(temp, a[i].F + a[i].S - (*mn.begin()));
       res = max(res,temp);
       
  mn.insert(a[i].F + a[i].S);
  mx.insert(a[i].F - a[i].S);
   }
    
   cout << res << '\n'; 
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 25432
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String str = in.nextLine();
	in.close();
    String ans = "Good";
    if (str.charAt(0) == str.charAt(1) || str.charAt(1) == str.charAt(2) || str.charAt(2) == str.charAt(3)) {
      ans = "Bad";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    string s;cin>>s;
    if(s=="AAA"||s=="BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int c[13] = {13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    if(c[a - 1] > c[b - 1]){
        cout << "Alice" << endl;
    }else if(c[b - 1] > c[a - 1]){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//<(") 
#define ll long long  
using namespace std;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
 
const ll mod = 1e9 + 7;
const ll siz = 1e5 + 10;
const ll base = 32;
const ll MAXX = 1e9;

ll n;
vector<ll> hold;
ll cnt[siz];
ll val[siz][2];

ll pre[siz];

ll qPow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	ll sub = qPow(a, b / 2);
	if (b % 2 == 0) {
		return sub * sub % mod;
	}
	return (a * (sub * sub % mod)) % mod; 
}

void setup() {
	pre[0] = 1;
	for (ll i = 1; i < siz; i++) {
		pre[i] = (pre[i - 1] * i) % mod;
	}
}

ll cal(ll a, ll b) {
	if (a < b) {
		return 0;
	}
	return (((pre[a] * qPow(pre[b], mod - 2)) % mod) * qPow(pre[a - b], mod - 2)) % mod;
}

ll dunno[siz];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	setup();
	cin >> n;
	hold.resize(n + 1);
	for (ll i = 0; i <= n; i++) {
		cin >> hold[i];
	}
	ll needVal;
	ll need;
	for (ll i = 0; i <= n; i++) {
		cnt[hold[i]]++;
		if (cnt[hold[i]] > 1) {
			need = n - i;
			needVal = hold[i];
			break;
		}
		dunno[hold[i]] = i;
	}
	for (ll i = 1; i <= n + 1; i++) {
		ll ans = cal(n + 1, i);
		ans = (ans - (cal(dunno[needVal] + need, i - 1)) + mod * mod) % mod;
		cout << ans << '\n';
	}
	return 0;
}  	 	   		  		 		 	  			  		

Measured memory_bytes: 6276
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	int n,k;
	int sum=0;
    scanf("%d%d",&n,&k);
		int a[55]={0};
		int j,i;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		for(j=n-1;j>=n-k;j--)
		{
			sum=sum+a[j];
		}
		cout<<sum<<"\n";
	
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1e18
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second



int main() {
	fastio;

	ll N;
	cin>>N;
	vector<ll> A(N),B(N);

	for(ll i=0;i<N;i++) {
		cin>>A[i]>>B[i];
	}

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

 
	if(N%2) {
		N--;
		ll ans = B[N/2]-A[N/2]+1;
		cout<<ans<<endl;
	} else {
		ld a = (ld)(A[N/2]+A[(N/2)-1])/2.0;
		ld b = (ld)(B[N/2]+B[(N/2)-1])/2.0;
		ll ans = (ll)2*(b-a)+1;
		cout<<ans<<endl;
	}

}



Measured memory_bytes: 6340
X = int(input())

price = [100,101,102,103,104,105]
dp = [[0]*100001 for _ in range(6)]

dp[0][0] = 1
for i in range(100,100001):
    dp[0][i] = dp[0][i-100]

for i in range(1,6):
    for j in range(price[i]):
        dp[i][j] = dp[i-1][j]
    for j in range(price[i],100001):
        dp[i][j] = max(dp[i-1][j],dp[i][j-price[i]])

print(dp[-1][X])


Measured memory_bytes: 13536
//#include <bits/stdint.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

int main(){
  int k, a, b;
  cin >> k >> a >> b;
  bool ans=false;
  FOR(i,a,b+1){
    if(i%k==0){
      ans=true;
      break;
    }
  }
  if(ans){
    cout << "OK" << endl;
  }else cout << "NG" << endl;
}

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

int main() {
  vector<char> s(4);
  for (char& c : s) {
    cin >> c;
  }

  sort(s.begin(), s.end());

  if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int inp[200];
    for (int i = 0; i < n; i++) cin >> inp[i];
    int cnt = 0;
    bool F_odd=false;
    while(1){
        for(int i=0;i<n;i++){
            if(inp[i]%2==1) F_odd=true;
            else inp[i]/=2;
        }
        if(F_odd) break;
        else cnt++;
    }
    cout << cnt << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 100005;

vector<int> to[MAX];
bool seen[MAX];
int n, color[MAX], c = 0;

void dfs(int u, int c) {
  if (seen[u]) return;
  seen[u] = true;
  color[u] = c;
  for (int v: to[u]) {
    dfs(v, c);
  }
}

int main() {
  int n, m, s, t, q;
  cin >> n >> m;
  rep(i, m) {
    cin >> s >> t;
    to[s].push_back(t);
    to[t].push_back(s);
  }

  rep(i, n) {
    seen[i] = false;
    color[i] = -1;
  }

  rep(i, n) {
    dfs(i, c);
    c++;
  }

  cin >> q;
  rep(i, q) {
    cin >> s >> t;
    if (color[s] != -1 && color[s] == color[t]) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  
  return 0;
}


Measured memory_bytes: 12116
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  int A, B;
  cin >> A >> B;

  if(!(A%3)) {
    cout << "Possible" << endl;
  } else if(!(B%3)) {
    cout << "Possible" << endl;
  } else if(!((A+B)%3)) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b;
    cin >> a >> b;
    if((a > 8) || (b > 8)){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;

  int sum2=0;
  for (int i=1; i<=N; i++){
    int j = i, sum1 = 0;
    while (j>=1){
      sum1 += j % 10;
      j /= 10;
    }
    if (sum1>=A && sum1<=B){
      sum2 += i;
    }
  }
  cout << sum2 << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int *arr=new int[2*n];
    for(int i=0;i<2*n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+2*n);
    int sum=0;
    for(int i=0;i<2*n-1;i+=2)
    {
        sum=sum+(min(arr[i+1],arr[i]));
    }
    cout<<sum<<endl;



    return 0;
}


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

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

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

#define int long long
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; }

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

	int ans = 0;
	int n = s.size();
	for(int i = 0;i < n;i++){
		ans += s[i] == 'g' ? 1 : -1;
	}
	cout << ans/2 << endl;

	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string w;
    cin >> w;
    sort(w.begin(), w.end());
    if(w.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    while(w.size()) {
        if(w.back() != w[w.size() - 2]) {
            cout << "No" << endl;
            return 0;
        }
        w.pop_back();
        w.pop_back();
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::io::Error;
use std::io::Read;

#[derive(Debug)]
struct Input {
    a: Vec<u32>,
    k: u32,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();
    let c: u32 = iter.next().unwrap().parse().unwrap();
    let d: u32 = iter.next().unwrap().parse().unwrap();
    let e: u32 = iter.next().unwrap().parse().unwrap();
    let k: u32 = iter.next().unwrap().parse().unwrap();
    let input = Input {
        a: vec![a, b, c, d, e],
        k: k,
    };
    Ok(input)
}

fn handle_output(input: Input) -> Result<String, Error> {
    for i in 0..5 {
        for j in i + 1..5 {
            if input.a[j] - input.a[i] > input.k {
                return Ok(":(".to_string());
            }
        }
    }
    Ok("Yay!".to_string())
}

fn main() {
    let mut input_str = String::new();
    let stdin = stdin();
    stdin.lock().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}

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


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

    int a = N % 10;
    if (a == 3) {
        cout << "bon";
    } else if (a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon";
    } else {
        cout << "hon";
    }

    cout << endl;

    return 0;
}

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

int main() {
    int input = 0;
    
    cin >> input;
    
    int nCnt = 0;
    for(int i = 1; i <= input; i++){
        if(i % 2){
            nCnt++;
        }
    }
    cout << (float) nCnt / input;
    
	return 0;
}


Measured memory_bytes: 256
S = input()
l = len(S)
L = [0] * l
flag = 0
tmp_ind = 0
for ii in range(l):
    if S[ii] == 'L':
        if flag == 1:
            tmp_ind -= 1
        else:
            flag = 1
            tmp_ind = -1
        L[ii] = tmp_ind
    else:
        flag = 0

flag = 0
for ii in range(1, l + 1):
    if S[-ii] == 'R':
        if flag == 1:
            tmp_ind += 1
        else:
            flag = 1
            tmp_ind = 1
        L[-ii] = tmp_ind
    else:
        flag = 0

ret = [0] * l
for ii in range(l):
    n = L[ii]
    if n > 0:
        ret[ii + n - n % 2] += 1
    else:
        ret[ii + n + n % 2] += 1

print (' '.join(map(str, ret)))


Measured memory_bytes: 14452
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = string_to_int(inputs[0])
    s_sum = deque([0])
    for s in S:
        s_sum.append(s_sum[-1] + s)
    s_sum.popleft()

    min_diff = None
    for i in range(len(s_sum)):
        front = s_sum[i]
        back = s_sum[-1] - front
        d = abs(front - back)
        if min_diff is None or min_diff > d:
            min_diff = d
    return min_diff


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 27780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

	if (k * 500 >= x)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
A = list(input())
B = list(input())
C = list(input())
owner = "a"
while True:
    if owner == "a":
        if len(A):
            owner = A[0]
            del A[0]
        else:
            break
    elif owner == "b":
        if len(B):
            owner = B[0]
            del B[0]
        else:
            break
    else:
        if len(C):
            owner = C[0]
            del C[0]
        else:
            break
if   owner == "a":
    print("A")
elif owner == "b":
    print("B")
else:
    print("C")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 100000

#define ll long long int



int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k]){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}

}


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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}


int main() {
	int N, Q;
	cin >> N >> Q;
	map<int, int> row, column;
	ll ans = (ll)(N-2)*(N-2);
	row.insert(make_pair(1111111, -188));
	column.insert(make_pair(1111111, -188));
	for (int i=0;i<Q;i++) {
		int num, x;
		cin >> num >> x;
		if (num == 1) {
			if ((row.size() == 1) || ((row.lower_bound(x)--) == row.begin())) {
			// if (row.lower_bound(x) == row.end()) {
				int len = N-2;
				if (column.size() != 1) {
					len = (*column.begin()).first-2;
				}
				ans -= len;
				row.insert(make_pair(x, len));
			} else {
				ans -= (*(--row.lower_bound(x))).second;
			}
		} else { // num == 2
			// if (column.lower_bound(x) == column.begin()) {
			if ((column.size() == 1) || ((column.lower_bound(x)--) == column.begin())) {
			// if (column.lower_bound(x) == column.end()) {
				int len = N-2;
				if (row.size() != 1) {
					len = (*row.begin()).first-2;
				}
				ans -= len;
				column.insert(make_pair(x, len));
			} else {
				ans -= (*(--column.lower_bound(x))).second;
			}
		}
		// cout << ans << endl;
	}

	cout << ans << endl;
}


Measured memory_bytes: 12776
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//INT_MAXなど
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/

signed main(){
  int res = 0;
  int N, A, B;
  cin >> N >> A >> B;

  string S;
  cin >> S;

  int total = 0;
  int total_b = 0;
  for (auto c : S) {
    if (c == 'a') {
      if (total < A + B) {
        cout << "Yes" << endl;
        total++;
      } else {
        cout << "No" << endl;
      }
    } else if (c == 'b') {
      if (total < A + B && total_b < B) {
        cout << "Yes" << endl;
        total++;
        total_b++;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3672
N = int(input())
Ls = list(map(lambda x: int(x), input().split(" ")))

Ls.sort()

result = 0
for i in range(len(Ls)-2):
    for j in range(i+1, len(Ls)-1):
        if Ls[i] == Ls[j]:
            continue
        for k in range(j+1, len(Ls)):
            if Ls[j] == Ls[k]:
                continue
            if Ls[i] + Ls[j] > Ls[k]:
                result += 1


print(result)

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

def digit_sum(a, b):
    ab_sum = 0
    for i in range(1, len(str(a))+1):
        ab_sum += a % 10
        a = a // 10
    
    for i in range(1, len(str(b))+1):
        ab_sum += b % 10
        b = b // 10
    
    return ab_sum

min_sum = float("inf")
for i in range(1, (N//2)+1):
    a = i
    b = N - i
    if digit_sum(a, b) < min_sum:
        min_sum = digit_sum(a, b)

print(min_sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define light ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define REPE(i,a,b) for(ll i = a; i <= b; i++)
#define REPR(i,a,b) for(ll i = a; i >= b; i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
const double pi = 2*acos(0.0);
const int INF = 1e9+1;
const int MOD = 1e9+7;
const int MOD1 = 998244353;

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}

bool compare(const pair<int,int> &i, const pair<int,int> &j) {
   return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void test() {
	string s;
   cin >> s;
   ll sum = 0;
   for(char c : s) {
      sum += (c-'0');
   }

   cout << (sum % 9 == 0 ? "Yes" : "No");
}

int main() {
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   light;
   cout.precision(15);
   cout << fixed;

   int t = 1;
   //cin >> t;
   for(int i = 1; i <= t; i++) {
      //cout << "Case #" << i << ": ";
      test();
   }
   return 0;
}


Measured memory_bytes: 3788
#include <iostream>

int main() {
	long long int H, W;
	std::cin >> H >> W;
	long long int sol = H * W;
	if (H == 1 || W == 1) std::cout << "1\n";
	else {
		if (sol % 2 == 0) std::cout << sol / 2 << '\n';
		else std::cout << sol / 2 + 1 << '\n';
	}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int n;
    cin>>n;
    int ans;
    int d[n];for(int i=0;i<n;i++){cin>>d[i];for(int j=0;j<i;j++)ans+=d[i]*d[j];}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=1000000007;
int n,a[105];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
pii operator *(const pii &a,const pii &b){
	int sum=2ll*(a.fi+a.se)*(b.fi+b.se)%mo;
	return pii(2ll*a.fi*b.fi%mo,sum);
}
pii F(int l,int r,int v){
	if (l==r)
		return pii(power(2,a[l]-v-1),0);
	int mnv=1<<30,las=l;
	pii vf;
	For(i,l,r) mnv=min(mnv,a[i]);
	For(i,l,r+1)
		if (a[i]==mnv||i==r+1){
			if (las!=i){
				pii vson=F(las,i-1,mnv);
				int v1=vf.fi,v2=vf.se;
				int v3=2ll*vson.fi%mo,v4=vson.se;
				if (las==l) vf=pii(v3,v4);
				else{
					vf.fi=1ll*v1*v3%mo;
					vf.se=(2ll*(v1+v2)*(v3+v4)+mo-vf.fi)%mo;
				}
			}
			if (i!=r+1){
				if (i==l) vf=pii(1,0);
				else{
					int v1=vf.fi,v2=vf.se;
					vf=pii(v1,(v1+2ll*v2)%mo);
				}
			}
			las=i+1;
		}
	vf.fi=1ll*vf.fi*power(2,mnv-v-1)%mo;
	return vf;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	pii ans=F(1,n,0);
	printf("%d",2ll*(ans.fi+ans.se)%mo);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 2010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn],mark[maxn];
int id[maxn];
int n,k,q;
bool cmp(int x,int y){return a[x]<a[y];}
int check(int mx,int mn)
{
	for(int i=1;i<=n;i++)
		if(i<mn)mark[id[i]]=-1;
		else if(i>mx)mark[id[i]]=1;
		else mark[id[i]]=0;
	int last=0,cnt=0,tot=0;
	for(int i=1;i<=n;i++)
		if(mark[i]==-1){
			tot+=std::min(std::max((i-last-1)-(k-1),0),cnt);
			last=i; cnt=0;
		}
		else cnt+=(!mark[i]);
	tot+=std::min(std::max((n-last)-(k-1),0),cnt);
	return tot>=q;
}
int main()
{
	n=read(); k=read(); q=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		id[i]=i;
	std::sort(id+1,id+n+1,cmp);
	int ans=inf;
	for(int i=q;i<=n;i++){
		int l=0,r=i-q+1;
		while(l<r){
			int mid=(l+r+1)>>1;
			if(check(i,mid))l=mid;
			else r=mid-1;
		}
		if(l)ans=std::min(ans,a[id[i]]-a[id[l]]);
	}
	writeln(ans);
	return 0;
}

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

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(){
  ll x,n;
  cin >> x >> n;

  if(n==0){
    cout << x << endl;
    return 0;
  }

  vector<ll> p(n);
  rep(i,n)cin >> p[i];

  ll ans = -5;
  ll md = 100000;

  sort(p.begin(), p.end(), less<ll>());

  for(ll now = -1; now<=101; now++){
    if(abs(now-x)>=md){
      continue;
    }

    auto it = lower_bound(p.begin(), p.end(), now);
    ll id = distance(p.begin(), it);
    if(now==p[id]){
      continue;
    }else{
      ans = now;
      md = abs(now-x);
    }

  }

  cout << ans << endl;


  return 0;
} 



Measured memory_bytes: 3644
package main

import (
	"fmt"
	"math"
)

func calc(a,b int) int {
	return (a-b)*(a-b)
}

func main() {
	var n,d int
	fmt.Scan(&n,&d)

	x := make([][]int,n)
	for i := 0; i < n; i++ {
		x[i] = append(x[i],make([]int,d)...)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < d; j++ {
			fmt.Scan(&x[i][j])
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		for j := i+1; j < n; j++ {
			if i == j {
				continue
			}

			dist := 0
			for k := 0; k < d; k++ {
				dist += calc(x[i][k],x[j][k])
			}

			a := math.Sqrt(float64(dist))

			if float64(int(a)) == a {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
int main(){
  queue<int> que;
  queue<int> q;
  ll n,k,fro=0;cin>>n>>k;
  ll a[n],b[n];fill(b,b+n,0);
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  que.push(0);b[0]=1;
  int i=0;
  while(b[i]!=2){
    que.push(a[i]-1);
    b[a[i]-1]++;
    i=a[i]-1;
  }
  while(que.front()!=que.back()){
    q.push(que.front());
    que.pop();
    fro++;
  }
  int x=que.size()-1;
  if(k<fro){
    for(int i=0;i<k;i++){
      q.pop();
    }
   cout << q.front()+1<<endl;
  }else{
  k-=fro;
  k=k%x;
  for(int i=0;i<k;i++){
    que.pop();
  }
    cout << que.front()+1<<endl;
}}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    ll n,m,k; cin >> n >> m >> k;
    vector<vector<ll>> fr(n,vector<ll>(0));    
    vector<vector<ll>> bl(n,vector<ll>(0));

    UnionFind tree(n);

    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        tree.unite(a,b);
        fr.at(a).push_back(b);
        fr.at(b).push_back(a);        
    }

    rep(i,k){
        //bl
        ll c,d; cin >> c >> d;
        c--; d--;
        bl.at(c).push_back(d);
        bl.at(d).push_back(c);     
    }
 
    vector<vector<ll>> cls(n,vector<ll>(0));
    vector<ll> ans(n,0);
  
    for(int i=0;i<n;i++){
        cls.at(tree.root(i)).push_back(i);
    }

    for(int i=0;i<n;i++){
        ll x = tree.root(i);
        ll count = 0;
        for(auto ff:fr.at(i)){
            if(tree.same(i,ff)) count++;
        }
        for(auto bb:bl.at(i)){
            if(tree.same(i,bb)) count++;
        }            
        ans.at(i) = (ll)cls.at(x).size() - 1 - count;
        cout << ans.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 17780
a,b=map(int,input().split())
l=list(range(a,b+1))
s=[]
for i in range(len(l)):
    if str(l[i])[0]==str(l[i])[4] and str(l[i])[1]==str(l[i])[3]:s.append(l[i])
print(len(s))

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

#define ll long long
#define mod 1000000007
#define mx 100005

int a[mx+10];
char ch[mx+10];
int n;
vector<string>ans;

void nPermute(string str, int nn)
{

    sort(str.begin(), str.end());
    ans.push_back(str);


    int i = 1;
    while(i<nn)
    {
        (next_permutation(str.begin(), str.end()));
        ans.push_back(str);
        i++;
    }
}

void solve(int ii)
{
    scanf("%d",&n);

    string aa="",bb="";

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        aa+=a[i]+48;
    }
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        bb+=a[i]+48;
    }

    string tem="";

    for(int i=0; i<n; i++)
        tem+=(i+1)+48;

    int val=1;
    for(int i=1; i<=n; i++)
        val*=i;
    nPermute(tem,val);

    int pos1,pos2;

    for(int i=0; i<ans.size(); i++)
    {
        if(ans[i]==aa)
            pos1=i+1;
        if(ans[i]==bb)
            pos2=i+1;

          //  cout<<ans[i]<<endl;
    }

    //cout<<pos1<<" "<<pos2<<endl;

    printf("%d\n",abs(pos1-pos2));

    return;
}

int main()
{
    int t=1;

    for(int i=1; i<=t; i++)
        solve(i);

    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

int a[10];
int n;
int s[100];
int s_max, s_min;
int sum = 0;
int ave = 0;

int main() {
  while(cin >> n, n)
  {
  for(int i =0; i < n; i++){
    cin >> s[i];
  }
  
  s_max = *max_element(s, s + n);
  s_min = *min_element(s, s + n);

  sum = accumulate(s, s + n, 0);

  sum = sum - s_max - s_min;

  ave = sum/(n-2);
  cout << ave << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



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 ll INF=1e15;

const ll mod=1e9+7;


int main(){
   
    ll d,t,s;
    cin >> d >> t >> s;
    if(t*s>=d) cout << "Yes" << endl;
    else cout << "No"<< endl;
    return 0;
}

Measured memory_bytes: 3632
from itertools import combinations_with_replacement as H
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
ret = []
for ls in list(H(range(1,M+1), N)):
    cand = 0
    for a,b,c,d in abcd:
        if ls[b-1] - ls[a-1] == c:
            cand += d
    ret.append(cand)
print(max(ret))

Measured memory_bytes: 24984
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=100000,inf=0x3f3f3f3f;
struct edge{int to,len;};
vector<edge> g[maxn+10];
int n,a[maxn+10],ans,c[16],ccnt,f[1<<16],gg[1<<16],h[1<<16]; bool b[16];
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int l,r,w; scanf("%d%d%d",&l,&r,&w);
		a[l+1]^=w; a[r+1]^=w;
	}
	for(int i=1;i<=n;++i) if(a[i])
		if(b[a[i]]) ++f[0],b[a[i]]=0; else b[a[i]]=1;
	for(int i=0;i<16;++i) if(b[i]) c[ccnt++]=i;
	for(int i=0;i<1<<ccnt;++i)
		for(int j=0;j<ccnt;++j) if(i>>j&1) gg[i]^=c[j],++h[i];
	for(int i=1;i<1<<ccnt;++i){
		f[i]=inf;
		for(int j=i;j;j=(j-1)&i) if(!gg[j]) f[i]=min(f[i],f[i^j]+h[j]-1);
	}
	printf("%d",f[(1<<ccnt)-1]);
}

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

int main() {
	int n, a[4], b[4];
	while(1){
		cin >> n;
		if(n == 0)
			break;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < 4; ++j)
	 			cin >> a[j];
			for(int j = 0; j < 4; ++j)
				cin >> b[j];
			int ans[4] = {0};
			for(int j = 0; j < 4; ++j){
				for(int k = 0; k < 4; ++k){
					int t = j + k;
					int r = a[j] * b[k];
					if(t == 0)
						ans[0] += r;
					else if(j == k)
						ans[0] -= r;
					else if(j == 0){
						if(k == 1)
							ans[1] += r;
						else if(k == 2)
							ans[2] += r;
						else if(k == 3)
							ans[3] += r;
					}
					else if(k == 0){
						if(j == 1)
							ans[1] += r;
						else if(j == 2)
							ans[2] += r;
						else if(j == 3)
							ans[3] += r;
					}
					else if(j == 1){
						if(k == 2)
							ans[3] += r;
						else if(k == 3)
							ans[2] -= r;
					}
					else if(j == 2){
						if(k == 1)
							ans[3] -= r;
						else if(k == 3)
							ans[1] += r;
					}
					else if(j == 3){
						if(k == 1)
							ans[2] += r;
						else if(k == 2)
							ans[1] -= r;
					}
				}
			}
			for(int j = 0; j < 4; ++j){
				if(j)
					cout << " ";
				cout << ans[j];
			}
			cout << endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll p(ll n) {
	if (n == 0) { return 1; }
	else { return 10 * p(n - 1); }
}

long double s(ll n) {
	ll k = 0;

	for (ll m = n; m > 0; m /= 10) {
		k += m % 10;
	}

	return (long double)n / (long double)k;
}

int main() {

	ll X;
	cin >> X;

	vector<ll> snuke;

	rep(K, 15) {//K桁の候補を追加
		ll i;//下i桁は9
		if (9 * K < 10) { i = max(K - 1,0); }
		else if(9 * K < 100) { i = K-2; }
		else { i = K - 3; }

		for (ll x =p(K)+p(i) - 1; x < p(K + 1); x += p(i)) {
			snuke.push_back(x);
			//cout << x << endl;
		}
	}

	ll M = snuke.size();

	//cout << M << endl;

	
	vector<bool> real(M, 0);

	long double v=INF;

	for (ll i = M-1; i >= 0; i--) {
		if (s(snuke[i]) <= v) { real[i] = 1; v = s(snuke[i]); }
	
	}
	ll c = 0;
	rep(i, M) {
		if (real[i] == 1) {
			cout << snuke[i] << endl;
			c++;
			if (c == X) { break; }
		}
	}
	

	system("PAUSE");

	

}


Measured memory_bytes: 892
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

long long ggd(long long x, long long y){
    while(x != y){
        if(x < y){
            long long temp = x;
            x = y;
            y = temp;
        }
        long long num = y;
        y = x - y;
        x = num;
    }
    return x;
}

long long lcm(long long x, long long y){
    return x * y / ggd(x, y);
}

int main(){
    long long a1, a2, a3, m1, m2, m3;
    long long x, y ,z;
    x = y = z = 1;
    long long i, j, k;
    while(cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3, a1||a2||a3||m1||m2||m3){
        long long count = 0;
        bool xc, yc, zc;
        xc = yc = zc = true;
        while(true){
            count++;
            if(xc){
                x = a1 * x % m1;
                if(x == 1){
                    i = count;
                    xc = false;
                }
            }
            if(yc){
                y = a2 * y % m2;
                if(y == 1){
                    j = count;
                    yc = false;
                }
            }
            if(zc){
                z = a3 * z % m3;
                if(z == 1){
                    k = count;
                    zc = false;
                }
            }
            if(!(xc||yc||zc)) break;
        }
        cout << lcm(lcm(i,j),k) << endl;
    }
}

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

def resolve():
    n, k = map(int, input().split())
    aa = list(map(int, input().split()))

    a1 = 0
    for i in range(n-1,-1,-1):
        for j in range(i,-1,-1):
            if aa[i] < aa[j]:
                a1 += 1

    if k == 1:
        print(a1)
        return

    a2 = 0
    aa2 = aa * 2

    for i in range(2*n-1,-1,-1):
        for j in range(i,-1,-1):
            if aa2[i] < aa2[j]:
                a2 += 1

    if k == 2:
        print(a2)
        return

    a3 = 0
    aa3 = aa * 3

    for i in range(3*n-1,-1,-1):
        for j in range(i,-1,-1):
            if aa3[i] < aa3[j]:
                a3 += 1

    b1 = a2 - a1
    b2 = a3 - a2
    d = b2 - b1

    s = int(a1 + ((k-1) * (2 * b1 + (k-2) * d))//2)
    ans = s % (10**9 + 7)
    print(ans)



resolve()

Measured memory_bytes: 42844