akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// 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();
}

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

int n, m;
int cnt[101010];

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

  cin >> n >> m;
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }

  bool ans = true;
  rep(i, n) {
    if (cnt[i] % 2) {
      ans = false;
      break;
    }
  }

  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 640
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))

MOD=10**9+7

LCM=defaultdict(int)
def f(n):
    tmp=0
    p=2
    while n%p==0:
        tmp+=1
        n//=p
    LCM[p]=max(LCM[p],tmp)
    p=3
    while p*p<=n:
        tmp=0
        while n%p==0:
            tmp+=1
            n//=p
        LCM[p]=max(LCM[p],tmp)
        p+=2
    if n>1:
        LCM[n]=max(LCM[n],1)

for a in A: f(a)

l=1
for p,n in LCM.items():
    l=l*pow(p,n,MOD)%MOD

ans=0
for a in A:
    ans+=l*pow(a,MOD-2,MOD)
    ans%=MOD

print(ans)

Measured memory_bytes: 48220
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int tasu = a + b;
        int kakeru = a * b;
        int hiku = a - b;
        if(tasu > hiku) {
            if(tasu > kakeru) {
                System.out.println(tasu);
            }else {
                System.out.println(kakeru);
            }
        }else {
            if(hiku > kakeru) {
                System.out.println(hiku);
            }else {
                System.out.println(kakeru);
            }
        }
    }
}

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

#define mk(a,b) make_pair(a,b)
#define fi first
#define se second

typedef pair<int,int> pii;

int N;
vector<int> V[100010];
queue<pii> Q;
int D[100010] = {0};
int sum[3] = {0};

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        V[a].push_back(b);
        V[b].push_back(a);
    }
    Q.push(mk(1,1));Q.push(mk(N,2));
    while(Q.size())
    {
        pii now = Q.front();Q.pop();
        if(D[now.fi] != 0)continue;
        D[now.fi] = now.se;
        sum[now.se]++;
        for(int i = 0; i < V[now.fi].size(); i++)
        {
            Q.push(mk(V[now.fi][i],now.se));
        }
    }
    if(sum[1] <= sum[2])printf("Snuke\n");
    else printf("Fennec\n");
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
  while (cin >> N >> R && N){
    vector<int> A(N,0);
    int i;
    for(i=0;i<N;i++){
      A[i]=N-i;
    }
    for(i=0;i<R;++i){
      cin >> p >> c;
      if (p==0){
        cout << "Incorrect input" << endl;
        exit(1);
      }
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
}

Measured memory_bytes: 3000
def divisor_counter(num)
  counter = 0
  (1..num).each do |n_value|
    counter += 1 if num % n_value == 0
  end
  counter
end

n = gets.chomp.to_i
odd_nums = []

odd_num = 1
result_counter = 0

while odd_num <= n
  odd_nums << odd_num
  odd_num += 2
end

odd_nums.each do |num|
  result_counter += 1 if divisor_counter(num) == 8
end

print result_counter

Measured memory_bytes: 1788
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

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

	var N, M, X int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &M)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &X)

	as := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &as[i])
	}

	left := 0
	right := 0
	for _, a := range as {
		if a < X {
			left++
		} else {
			right++
		}
	}
	fmt.Println(min(left, right))
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  string s;
  cin >> s;
  
  ll a = 0;
  for (int i = 0; i < 4; i++){
    if (s[i] == '+')
      a++;
    else
      a--;
  }
  cout << a << endl;

  return 0;
}


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

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N <= K) {
        cout << N * X << endl;
    }
    else {
        cout << X * K + (N - K) * Y << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m,a,d;
bool data[50][50];

bool check()
{
  int now=m;
  for(int i=0;i<d;i++)
    {
      if(now-1>=0 && data[i][now-1])
	now=now-1;
      else if(now<n-1 && data[i][now])
	now=now+1;
    }
  if(now==a)
    return true;
  else 
    return false;
}

int main()
{
  for(;cin>>n,n;)
    {
      cin>>m>>a>>d;
      m--;
      a--;
      for(int i=0;i<d;i++)
	for(int j=0;j<n-1;j++)
	  {
	    char tmp;
	    cin>>tmp;
	    data[i][j]=(tmp=='1');
	  }

      bool flag=true;
      if(check())
	{
	  flag=false;
	  cout<<"0"<<endl;
	}
      else
	{
	  for(int i=0;i<d&&flag;i++)
	    for(int j=0;j<n-1&&flag;j++)
	      {
		if(!data[i][j] &&
		   (j-1<0||!data[i][j-1]) &&
		   (j+1>=n-1||!data[i][j+1]) )
		  {
		    data[i][j]=true;
		    //   cout<<"tmp "<<i<<" "<<j<<endl;
		    if(check())
		      {
			flag=false;
			cout<<i+1<<" "<<j+1<<endl;
			break;
		      }
		    data[i][j]=false;
		  }
	      }
	}
      if(flag)
	cout<<"1"<<endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	ll cnt=0;
	while(n--){
		int a,b; char c; cin >> a >> c >> b;
		if(c=='('){
			cnt+=b;
		}else{
			cnt-=b;
		}
		if(cnt){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}
}


Measured memory_bytes: 3112
/**
        ______________________
      AnTi-MiRaGe on Anti-Mage xD
      --------------------------
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")
#define int long long

using namespace std;

int n, k, ans;

main()
{
    cin >> n >> k;
    if (k == 0)
    {
        cout << n * n << endl;
        return 0;
    }
    for (int i = k; i <= n; i++)
        ans += n - i;

    for (int i = k + 1; i <= n - k; i++)
    {
        for (int j = min(n, i + i); ;)
        {
            ans += max(0ll, j - ( (j % i == 0 ? j / i - 1 : j / i) * i + k) );

            if (j == n && j % i != 0 && j >= (j / i) * i + k )
                ans++;

            if (j >= n) break;

            j += i;

            if (j > n) j = n;
        }
    }
    cout << ans << endl;
}
/**
287927211
287933049
**/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

ll n;
double a[10010],ans=0;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)ans+=1/a[i];
}

int main(void){
	init();
	cout<<1/ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<int>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int ct1,ct2;
struct edge{ll to;}; //edgeパラメータ
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)
  vector<ll> parent;
  vector<ll> depth; // d[ノード] ノードの深さ

  graph(ll n){ //グラフ生成時
    N = n;
    G.resize(N); //Edge情報
    parent.resize(N); //Node情報,親
    depth.resize(N); //Node情報,深さ
    rep(i,N){depth[i]= -1; parent[i]= -1;}
  }
  void add_edge(ll s, ll t){
    G[s].emplace_back((edge){t});
  }

  void dfs(ll v=0, ll p=0, ll d=0){
    parent[v] = p;
    depth[v] = d;
    for(auto& E : G[v]){ // E つなぐエッジ
      if(E.to != p) dfs(E.to , v , d+1); //まだ行ってないなら
    }
  }
};


void Main(){

  int N;
  cin>>N;

  graph g(N);
  graph g2(N);

  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    g.add_edge(a-1,b-1);
    g.add_edge(b-1,a-1);
    g2.add_edge(a-1,b-1);
    g2.add_edge(b-1,a-1);
  }

  g.dfs();
  g2.dfs(N-1,N-1);

  rep(i,N){
    if(g.depth[i]<=g2.depth[i])ct1++;
    else ct2++;
  }

  cout<< ( ct1>ct2 ? "Fennec" : "Snuke" )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 17920
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

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

  stack<int> st;
  string str;
  stringstream ss;
  while(cin >> str) {
    if(str == "+") {
      int r = st.top(); st.pop();
      int l = st.top(); st.pop();
      st.push(l+r);
    }
    else if(str == "-") {
      int r = st.top(); st.pop();
      int l = st.top(); st.pop();
      st.push(l-r);
    }
    else if(str == "*") {
      int r = st.top(); st.pop();
      int l = st.top(); st.pop();
      st.push(l*r);
    }
    else {
      // string -> int
      int num;
      ss << str;
      ss >> num;
      ss.clear();

      st.push(num);
    }
  }
  cout << st.top() << endl;
}

Measured memory_bytes: 1232
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int r,d,x; cin >> r >> d >> x;
    int i = 0;
    while (i < 10) {
        x = r * x - d;
        cout << x << endl;
        i++;
    }
}

Measured memory_bytes: 3652
#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 ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second

#define mp map<ll,ll>
#define vc vector<ll>
#define pq priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..
 
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)
 
#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)
 
#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define mod 1000000007
#define INF 1e18
 
const double PI = acos(-1);
 
bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}
 
struct hash_pair{ 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
 
int twocount(ll n){
	int ans=0;
	while (n>0){
		n=n/2;
		ans++;
	}
	return ans;
} 

int main(){
	string a,b;
	cin>>a>>b;
	if(b.length()==a.length()+1){
		if(b.substr(0,b.length()-1)==a){
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	}
	else cout<<"No"<<endl;
}

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

int main() {
    ll n, a[5];
    cin >> n;
    rep(i, 5) cin >> a[i];
    sort(a, a + 5);
    ll ans = 5;
    ll num = n - a[0];
    ans += num / a[0];
    if (n > a[0] && num % a[0] != 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr int MAX = 160 * 80 + 1;

bitset<MAX * 2> dp[80][80];

int a[80][80], b[80][80], c[80][80];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
  rep(i, 0, h) rep(j, 0, w) cin >> b[i][j];
  rep(i, 0, h) rep(j, 0, w) c[i][j] = abs(a[i][j] - b[i][j]);

  dp[0][0][c[0][0] + MAX] = 1;
  rep(i, 0, h) rep(j, 0, w) {
    if (i) {
      dp[i][j] |= dp[i - 1][j] << c[i][j];
      dp[i][j] |= dp[i - 1][j] >> c[i][j];
    }
    if (j) {
      dp[i][j] |= dp[i][j - 1] << c[i][j];
      dp[i][j] |= dp[i][j - 1] >> c[i][j];
    }
  }

  rep(i, 0, MAX) if (dp[h - 1][w - 1][i + MAX]) {
    cout << i << endl;
    return 0;
  }
}

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

int gcd(int a,int b){
    int t;
    while(b>0){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}

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

int main(){
    ll c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans;
    string s,t,u;
    cin>>n;
    ll a[n],b[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    
    for(ll i=0;i<n;i++){
        if(b[i]==a[n-1]){
            cout<<a[n-2]<<endl;   
        }
        else cout<<a[n-1]<<endl;
    }
}



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

using namespace std;

const int N = 1e6+5;

const int mod = 1e9+7;

int n;
int cnt[N];
bool did[N];

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

int main(){
    scanf("%d " , &n);
    int totG = 0;
    for(int i = 1; i <= n; i++){
       int x;
       scanf("%d" , &x);
       cnt[x]++;
       totG = gcd(x , totG);
    }
    bool exit = 0;
    for(long long i = 2; i < N; i++){
        if(did[i])
            continue;
        int found = 0;
        for(long long j = i; j < N; j += i){
            found += cnt[j];
            did[j] = 1;
        }
        if(found > 1)
            exit = 1;
        if(exit)
            break;
    }
    //cout << exit << "\n" ;
    if(!exit){
        puts("pairwise coprime");
    } else if(exit && totG == 1){
        puts("setwise coprime");
    } else {
        puts("not coprime");
    }
}


Measured memory_bytes: 8572
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	ll n;
	ll a[10001] = {}, b[10001] = {};
	ll suma = 0,sumb = 0;
	ll atimes = 0, btimes = 0;
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		suma += a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
		sumb += b[i];
	}

	bool flag = true;
	
	for (ll i = 0; i < n; i++) {
		if (a[i] > b[i]) {
			btimes+= a[i] - b[i];
		}
		else if(a[i] < b[i]){
			if ((b[i] - a[i]) % 2 == 0) {
				atimes += (b[i] - a[i]) / 2;
			}
			else {
				atimes += (b[i] - a[i]+1) / 2;
				btimes++;
			}
		}
	}

	if (btimes> atimes) {
		flag = false;
	}

	if (flag) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x-r>=0 & y-r>=0 & x+r<=W & y+r<=H) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
	int x;
	int i=1;
	for(i=1;;i++){
		cin >> x;
		if(x == 0) {
			break;
		}
		cout << "Case" << " " << i<< ":" << " " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
N = int(input().strip())

def F(a, b):
    return max(len(str(a)), len(str(b)))

f = N
for i in range(1, N):
    if i * i > N:
        break
    if N % i == 0:
        _f = F(i, N // i)
        f = min(f, _f)

print(f)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
#include <math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7;

using namespace std;
double dp[3100][3100]={};
int n;
double p[3005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    dp[1][1]=1;
    cin>>n;
    reps(i,n){
	cin>>p[i];
    }
    
    for(int i=1;i<=n;i++){
	for(int j=1;j<=i+1;j++){
	    dp[i+1][j+1]+=dp[i][j]*p[i];
	    dp[i+1][j]+=dp[i][j]*(1-p[i]);
	}
    }

    double sum=0;
    for(int i=(n+1)/2+1;i<=n+1;i++){
	sum+=dp[n+1][i];
    }
    


    cout<<SYOU(9)<<sum<<endl;
    
    return 0;
}


Measured memory_bytes: 72320
#include <stdio.h>

int main(void) {

  int X, Y, flag = 0;
  scanf("%d %d", &X, &Y);
  
  for(int i = 0; i <= X; ++i){
    int j = X - i;
    if(2*i + 4*j == Y){
      flag = 1;
      break;
    }
  }
  
  if(flag == 1)
    printf("Yes\n");
  
  else
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1628
import java.io.InputStream;
    import java.io.PrintStream;
    import java.util.Scanner;
     
    public class Main {
     
      public static void main(String[] args) {
        resolve(System.in, System.out);
      }
     
      static void resolve(InputStream is, PrintStream pw) {
        Scanner sc = new Scanner(is);
        int n = Integer.parseInt(sc.next());
        int nextExpectation = 1;
        int brokenBlock = 0;
        for (int i = 0; i < n; i++) {
          int ai = Integer.parseInt(sc.next());
          if (ai == nextExpectation) {
            nextExpectation++;
          } else {
            brokenBlock++;
          }
        }
        if (nextExpectation == 1) {
          pw.println(-1);
        } else {
          pw.println(brokenBlock);
        }
      }
    }

Measured memory_bytes: 49548
N = int(input())
la = list(map(int, input().split()))

m = max(la)
if (m == N - 1) and (len(set(la)) == 1):
    print('Yes')
else:
    d = N - m
    cnt = la.count(m)
    if ((cnt >= d + 1) and (cnt <= 2 * d)):
        if cnt < N:
            if (len(set(la)) == 2) and min(la) == m - 1:
                print('Yes')
            else:
                print('No')
        else:
            print('Yes')
    else:
        print('No')
    
    


Measured memory_bytes: 14564
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  double a,b;
  int c,d,e;
  while(scanf("%lf %lf",&a,&b)!=EOF){
    if(a<35.50)c=1;
    else if(a<37.50)c=2;
    else if(a<40.00)c=3;
    else if(a<43.00)c=4;
    else if(a<50.00)c=5;
    else if(a<55.00)c=6;
    else if(a<70.00)c=7;
    else c=0;
    
    if(b<71.00)d=1;
    else if(b<77.00)d=2;
    else if(b<83.00)d=3;
    else if(b<89.00)d=4;
    else if(b<105.00)d=5;
    else if(b<116.00)d=6;
    else if(b<148.00)d=7;
    else d=0;
    
    if(c==0||d==0)printf("NA\n");
    else{
      if(d>c)c=d;

      if(c==1)printf("AAA\n");
      else if(c==2)printf("AA\n");
      else printf("%c\n",c+'A'-3);
    }
  }
  return 0;
}

Measured memory_bytes: 636
h, n = gets.chomp.split.map(&:to_i)

dp = [0xffffffff]*20001
dp[0] = 0

n.times do
  a, b = gets.chomp.split.map(&:to_i)

  dp[a] = b if dp[a] > b

  h.times do |i|
    x, y = a + i, dp[i] + b
    dp[x] = y if y < dp[x]
  end
end

puts dp.drop(h).min


Measured memory_bytes: 1916
N = int(input())
A = [ int(x) for x in input().split() ]
B = [ int(x) for x in input().split() ]
C = [ int(x) for x in input().split() ]

prev = -100
manzoku = 0
for i in range(N):
    current = A[i] - 1
    manzoku += B[current]
    if prev + 1 == current:
        manzoku += C[prev]
    prev = current 

print(manzoku)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define scanf___Am_I_a_joke_to_you  ios_base :: sync_with_stdio(false);
#define ll                          long long
#define MAXN                        200007

int main ()
{
    scanf___Am_I_a_joke_to_you

    int n, m, cnt = 0, total_solved = 0; cin >> n >> m;

    vector <int> vec(MAXN, 0), pen(MAXN, 0);

    while(m--)
    {
        int s;
        string str; cin >> s >> str;

        if (vec[s]) continue;
        if (str == "AC") vec[s] = 1;
        else pen[s]++;
    }

    for (int i = 0; i<MAXN; i++) if(vec[i]) cnt += pen[i], total_solved++;
    cout << total_solved << " " << cnt << endl;



    return 0;
}



Measured memory_bytes: 1792
#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;


int main(){
    ll a;cin>>a;
    string b;cin>>b;
    ll b100 = (b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    ll ans = a*b100/100;
    cout<<ans<<endl;

}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
#define rl rd<LL>
typedef long long LL;
using namespace std;
const int maxN = 5e3 + 7;
const int maxM = 2e2 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
LL dis[maxN];
int a[maxN][maxM];
int stack[maxM][maxN], Top[maxM];
LL ans = 0;

namespace Seg {
	static const int maxP = 16389;
	#define lc (x << 1)
	#define rc (x << 1 | 1)

	LL a[maxP], tag[maxP];

	inline void pushup(int x) {
		a[x] = max(a[lc], a[rc]);
	}

	inline void totag(int x, LL d) {
		a[x] += d;
		tag[x] += d;
	}

	inline void pushdown(int x) {
		if (tag[x]) {
			totag(lc, tag[x]);
			totag(rc, tag[x]);
			tag[x] = 0;
		}
	}

	void build(int x, int l, int r) {
		if (l == r) {
			a[x] = dis[l];
			return;
		}
		tag[x] = 0;
		int mid = (l + r) >> 1;
		build(lc, l, mid);
		build(rc, mid+1, r);
		pushup(x);
	}

	void add(int x, int l, int r, int tl, int tr, LL d) {
		if (tl <= l && r <= tr) {totag(x, d); return;}
		int mid = (l + r) >> 1;
		pushdown(x);
		if (tl <= mid) add(lc, l, mid, tl, tr, d);
		if (mid < tr) add(rc, mid+1, r, tl, tr, d);
		pushup(x);
	}

	LL get(int x, int l, int r, int tl, int tr) {
		if (tl <= l && r <= tr) return a[x];
		int mid = (l + r) >> 1;
		pushdown(x);
		if (tr <= mid) return get(lc, l, mid, tl, tr);
		if (mid < tl) return get(rc, mid+1, r, tl, tr);
		return max(get(lc, l, mid, tl, mid), get(rc, mid+1, r, mid+1, tr));
	}

	void build() {build(1, 1, n);}
	void add(int l, int r, LL d) {add(1, 1, n, l, r, d);}
	LL get(int l, int r) {return get(1, 1, n, l, r);}

	#undef lc
	#undef rc
}

int main() {

	n = ri(), m = ri();
	dis[1] = 0; rep (i, 2, n) dis[i] = dis[i - 1] + rl();
	rep (i, 1, n) rep (j, 1, m) a[i][j] = ri();

	Seg::build();

	rep (i, 1, n) {
		rep (j, 1, m) {
			Seg::add(i, i, a[i][j]);
			int cur = i - 1;
			for (; Top[j] && a[i][j] >= a[stack[j][Top[j]]][j]; cur = stack[j][--Top[j]]) 
				Seg::add(stack[j][Top[j] - 1] + 1, cur, a[i][j] - a[stack[j][Top[j]]][j]);
			stack[j][++Top[j]] = i;
		}
		LL d = Seg::get(1, i);
		ans = max(ans, d - dis[i]);
	}

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

	return 0;
}

Measured memory_bytes: 7168
N=int(input())
H=list(map(int,input().split()))

dp=[0]*N
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))

print(dp[N-1])

Measured memory_bytes: 20524
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    const int INF = INT32_MAX>>3;
    cin >> h >> w;
    //ベルマンフォード法
    /*
    struct edge {
        int from, to, cost;
    };
    vector<edge> G(9*9);
    rep(i,10) rep(j,10) {
        int c;
        cin >> c;
        if(i == j) continue;
        G.push_back({i,j,c});
    }
    vector<int> A;
    rep(i,h) rep(j,w) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    vector<int> d_min(10);
    rep(i, 10) {
        vector<int> d(10, INF);
        d[i] = 0;
        rep(j, 10) {
            for(auto e: G) {
               if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                   d[e.to] = d[e.from] + e.cost;
               }
            }
        }
        d_min[i] = d[1];
    }
    int ans = 0;
    rep(i, A.size()) {
        if(A[i] != -1) {
            ans+=d_min[A[i]];
        }
    }
    cout << ans << endl;
    */

    //ワーシャルフロイド法
    /*
    vector<vector<int>> d(10,vector<int>(10,INF));
    rep(i,10) rep(j,10) cin >> d[i][j];
    vector<vector<int>> a(h, vector<int>(w));
    rep(i,h) rep(j,w) cin >> a[i][j];
    rep(k,10) rep (i,10) rep(j,10) chmin(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    rep(i,h) rep(j,w) if(a[i][j]!=-1)ans+=d[a[i][j]][1];
    cout << ans << endl;
    */
   //ダイクストラ法
    struct edge {
       ll to, cost;
    };
    vector<vector<edge>> G(10);
    rep(i,10) rep(j,10) {
        int c;
        cin  >> c;
        G[i].push_back({j,c});
    }
    vector<int> A;
    rep(i,h*w) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    using P=pair<int,int>;
    vector<int> s_min(10);
    rep(s,10) {
        vector<int> d(10,INF);
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = 0;
        pq.emplace(d[s], s);
        while(!pq.empty()) {
            P p = pq.top();
            int v = p.second;
            pq.pop();
            if(p.first > d[v]) continue;
            for(auto e : G[v]) {
                if(p.first + e.cost < d[e.to]) {
                    d[e.to] = p.first + e.cost;
                    pq.emplace(d[e.to], e.to);
                }
            }
        }
        s_min[s] = d[1];
    }
    int ans = 0;
    rep(i,A.size()) {
        if (A[i] == -1) continue;
        ans += s_min[A[i]];
    }
    cout << ans << endl;
}

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

int main() {
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    for (auto &b : a) cin >> b;
    
    long long dp[57][2];
    dp[0][1] = 0; dp[0][0] = 1;
    
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            dp[i+1][0] = dp[i][0]*2;
            dp[i+1][1] = dp[i][1]*2;
        } else {
            dp[i+1][0] = dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][0] + dp[i][1];
        }
    }
    
    cout << dp[n][p] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String S = br.readLine();
		String T = br.readLine();
		int l = S.length();
		int cont = 0;
		for (int i = 0; i < l; i++) {
			char s = S.charAt(i);
			char t = T.charAt(i);
			if (s != t) {
				cont++;
			}
		}
		System.out.print(cont);
	}
}

Measured memory_bytes: 37744
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll max(ll a,ll b)
{
  return (a>b)?a:b;
}
int main()
{
ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll t1=a*c;
  ll t2=a*d;
  ll t3=b*c;
  ll t4=b*d;
  ll ans=max(max(t1,t2),max(t3,t4));
  cout<<ans<<endl;
  
  
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int N;
  cin>>N;
  N=N%10;
  if(N==3) cout<<"bon"<<endl;
  else if(N==0||N==1||N==6||N==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
}


Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		while(sc.hasNext()){
			String hu = sc.nextLine();
			String[] stra = hu.split(",");
			double bmi = Double.parseDouble(stra[1]) / Math.pow(Double.parseDouble(stra[2]),2);
			if (bmi >= 25) System.out.println(stra[0]);

		}
		sc.close();
	}

}

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

int coef[4][4] = {
	{1,1,1,1},
	{1,-1,1,-1},
	{1,-1,-1,1},
	{1,1,-1,-1}
};

int to[4][4] = {
	{0,1,2,3},
	{1,0,3,2},
	{2,3,0,1},
	{3,2,1,0}
};

vector<int> calc(vector<int> A,vector<int> B){
	vector<int> answer(4);
	for(int i = 0 ; i < 4 ; i++)
		for(int j = 0 ; j < 4 ; j++)
			answer[to[i][j]] += A[i] * B[j] * coef[i][j];
	return answer;
}

int main(){
	int n;
	while(cin >> n && n){
		vector<int> A(4);
		vector<int> B(4);
		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];
			vector<int> answer = calc(A,B);
			for(int j = 0 ; j < 4 ; j++)
				cout << (j?" ":"") << answer[j];
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
    int a,p;
    cin>>a>>p;
    cout<<(3*a+p)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 100001;

int p3[N];

int main()
{
	fio;
	p3[0] = 1;
	for(int i=1; i<N; i++)
		p3[i] = (3ll * p3[i-1]) % MOD;
	string s;
	cin >> s;
	int n = s.length(), x = 1, ans = 0;
	for(int i=0; i<n; i++)
	{
		if(s[i] == '1')
		{
			int y = n - i - 1;
			ans += (x * 1ll * p3[y]) % MOD;
			ans %= MOD;
			x <<= 1;
			x %= MOD;
		}
	}
	ans += x;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int a[3];

int main() {
    int t = 0, just = 0, ei = 0, don = 0;
    while (cin >> a[0] >> a[1] >> a[2]) {
        sort(a, a+3);
        if (a[2] >= a[0] + a[1]) break;
        
        ++t;
        if (a[2]*a[2] == a[0]*a[0] + a[1]*a[1]) ++just;
        else if (a[2]*a[2] > a[0]*a[0] + a[1]*a[1]) ++don;
        else ++ei;
    }
    
    cout << t << " " << just << " " << ei << " " << don << endl;
    return 0;
}


Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<tuple>

using namespace std;

int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int day1=a*60+b;
  int day2=c*60+d;
  int ji;
  int hun;
  if(day1<=day2)
  {
    ji=c-a;
    if(b<=d)
    {
      hun=d-b;
    }
    else
    {
      ji--;
      hun=d-b+60;
    }
  }
  else
  {
    a=24-a;
    ji=a+c;
    if(b>d)
    {
      ji--;
      hun=d-b+60;
    }
    else
    {
      hun=d-b;
    }
  }
  cout<<ji*60+hun-e<<endl;
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        if ((b - a) % 2 == 0) {
            System.out.println((b - a) / 2);
        } else {
            long cand1 = Math.min(b - 1, n - a);
            // Aがはじ
            long cand2 = (a - 1) + (b - a + 1) / 2;
            // Bがはじ
            long cand3 = (n - b) + (b - a + 1) / 2;
            System.out.println(Math.min(Math.min(cand1, cand2), cand3));
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;

int main(){
  ull N;
  const ull mod=pow(10,9)+7;
  vector<ull> A;
  ull sum=0;
  cin >> N;

  for(int i=0;i<N;i++){
    ull input;
    cin >> input;
    A.push_back(input);
    }
  
  for(int bit=0;bit<=60;bit++){
    ull ones=0;
    vector<ull> v=A;
    for(int i=0;i<N;i++){
      ull a=v.back();
      v.pop_back();
      if(a&(1LL<<bit)) ones++;
    }
    sum = (sum + (1LL << bit) % mod * ones % mod * (N - ones) % mod) % mod;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint h, w;
    cin >> h >> w;
    lint ret = inf;
    for (lint i = 1; i <= h - 1; ++i) {
        lint a, b, c;
        a = i * w;
        b = (h - i) * (w / 2);
        c = h * w - a - b;
        if (a != 0 && b != 0 && c != 0)
            ret = min(ret, max({a, b, c}) - min({a, b, c}));

        b = (h - i) / 2 * w;
        c = h * w - a - b;
        if (a != 0 && b != 0 && c != 0)
            ret = min(ret, max({a, b, c}) - min({a, b, c}));
    }

    swap(h, w);

    for (lint i = 1; i <= h - 1; ++i) {
        lint a, b, c;
        a = i * w;
        b = (h - i) * (w / 2);
        c = h * w - a - b;
        if (a != 0 && b != 0 && c != 0)
            ret = min(ret, max({a, b, c}) - min({a, b, c}));

        b = (h - i) / 2 * w;
        c = h * w - a - b;
        if (a != 0 && b != 0 && c != 0)
            ret = min(ret, max({a, b, c}) - min({a, b, c}));
    }

    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP_1_C{
    class Program{
        static void Main(){

            int a,b;
            string[] str = Console.ReadLine().Split(' ');//2?????\?????????????????????????????\????????????
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            //??¢???
            int menseki = a * b;
            //??¨?????????
            int syuu = a * 2 + b * 2;

            Console.WriteLine(menseki + " " + syuu );
        }
    }
}

Measured memory_bytes: 9168
#include <stdio.h>
int main()
{
  int a,b,c,n,t;
  int x,y;
  for(;;)
    {
      scanf("%d%d%d",&a,&b,&c);
      if(a==0)
	break;
      scanf("%d",&n);
      for(;n--;)
	{
	  scanf("%d",&t);
	  if(a*a+b*b<(t*2)*(t*2) || a*a+c*c<(t*2)*(t*2) || c*c+b*b<(t*2)*(t*2))
	    puts("OK");
	  else
	    puts("NA");	 
	  //	  printf("ab=%d bc=%d ac=%d 2t2=%d\n",a*a+b*b,b*b+c*c,a*a+c*c,(t*2)*(t*2));
	}
    }
  return 0;
}

Measured memory_bytes: 0
import sys
input = lambda: sys.stdin.readline().rstrip()
NN = 19
X = [0] * ((1<<NN+1)-1)
 
def popcount(x):
    x -= (x >> 1) & 0x55555555
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x3f

def update(a, x):
    i = (1<<NN) - 1 + a
    X[i] = x
    while i:
        i = (i-1) // 2
        X[i] = X[2*i+1] | X[2*i+2]

def rangeor(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    x = 0
    while l < r:
        if l%2:
            x |= X[l-1]
            l += 1
        if r%2:
            r -= 1
            x |= X[r-1]
        l >>= 1
        r >>= 1
    return x

N = int(input())
A = [ord(a) - 97 for a in input()]
for i, a in enumerate(A):
    X[(1<<NN) + i] = 1 << a
for i in range((1<<NN)-1)[::-1]:
    X[i] = X[i*2+1] | X[i*2+2]

Q = int(input())
for _ in range(Q):
    a, b, c = input().rstrip().split()
    if a == "1":
        b = int(b)
        c = ord(c) - 97
        update(b, 1<<c)
    else:
        b, c = int(b), int(c)
        print(popcount(rangeor(b, c+1)))


Measured memory_bytes: 75720
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((b * 10 + c) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  int count = 0;
  rep(i, n){
    if(i + 1 != a[i]){
      count++;
    }
  }
  if(count <= 2)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n;
string s;
ll ans = 1e18;
ll x, y;
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> s;
	ll C = 0;
	s = '.'  +s;
	for (int i = 1; i <= n; i ++) {
		C += (s[i] == 'R');
	}
	ans = C;
	x = 0;
	y = C;
	for (int i = 1; i <= n; i ++) {
		x += (s[i] == 'W');
		y -= (s[i] == 'R');
		ans = min(ans, max(x, y));
	}
	cout << ans;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}

void chmin(int &a, int &b){if (a>b){a = b; return;}return;}
void chmax(int &a, int &b){if (a<b){a = b; return;}return;}


const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int n; cin >> n;
  string s; cin >>s;
  int ans = 0;
  for (int i=0; i<n-2; i++){
    if (s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C') ans++;
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <memory>
#include <algorithm>
#include <map>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <functional>
#include <cassert>
using namespace std;

int n, a[55];

bool isOk() {
	for (int i = 2; i <= n; ++i) if (a[i] < a[i-1]) return false;
	return true;
}

bool sol() {
	for (int i = 1; i <= n; ++i) {
		for (int j = i+1; j <= n; ++j) {
			swap(a[i], a[j]);
			if (isOk()) return true;
			swap(a[i], a[j]);
		}
	}
	return false;
}

int main(int argn, char **argc) {

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	if (isOk() || sol()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
from Queue import PriorityQueue
from collections import defaultdict
pq=PriorityQueue()
N,K=map(int,raw_input().split())
T=[];D=[];I=range(N)
for i in range(N):
    t,d=map(int,raw_input().split())
    T.append(t);D.append(d)
    pq.put((-d,t,i))    
P=zip(D,T,I) 
P.sort();P.reverse()
cost=0
kind=defaultdict(int)
curPq=PriorityQueue()
for d,t,i in P[:K]:
    kind[t]+=1
    cost+=d
    curPq.put((d,t,i))
ans=cost+(len(kind)**2)
K=len(kind)
while True:
    d,t,i=None,None,None
    while not curPq.empty():
        d,t,i=curPq.get()
        if kind[t]>1:break
    else: break
    nd,nt,ni=None,None,None
    while not pq.empty():
        nd,nt,ni=pq.get()
        nd=-nd
        if kind[nt]==0:break
    else: break
    # delete: (d,t,i)
    kind[t]-=1
    cost-=d
    # add: (nd,nt,ni)
    kind[nt]+=1
    cost+=nd
    K+=1
    ans=max(ans, cost+(K**2))

print(ans)

Measured memory_bytes: 99352
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;


const int INF = 1e+9;

// num より大きい数がいくつあるかを求める
// 転倒数 (i<j かつ a[i]>a[j] となる組の数) の求め方とほぼ同じ
long long check( int num, vector<int>& a )
{
    int N = a.size();
    long long ret = 0, now = 0;
    unordered_map<int,int> count;  // count[i]: iが現れた回数
    vector<int> ps(N);

    count[0] = 1;
    for( int i = 0; i < N; ++i ){
        // a[i] > num となる数を求める
        ps[i] = (i? ps[i-1]: 0) + (a[i]<=num? 1: -1);
        if( a[i] <= num ) now += count[ps[i]-1];
        else now -= count[ps[i]];
        ++count[ps[i]];
        ret += now;
    }

    return ret;
}


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


    // 中央値になる値を二分探索
    // 数列 M には、中央値より大きい数がちょうど [M/2] あることを利用
    int l = 0, r = INF;
    long long want = 1LL*(N+1)*N/4 + 1;  //　自分より大きい数がこれだけあればOK
    while(r-l > 1){
        int c = (l+r)/2;
        if( check(c, a) >= want ) r = c;
        else l = c;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 5192
n,W = map(int,input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i],v[i] = map(int,input().split())

dp = [[0 for _ in range(n+1)] for _ in range(W+1)]
for i in range(1,W+1):
    for j in range(1,n+1):
        if i-w[j-1] >= 0:
            dp[i][j] = max(dp[i-w[j-1]][j-1]+v[j-1],dp[i][j-1])
        else:
            dp[i][j] = dp[i][j-1]

print(dp[W][n])

Measured memory_bytes: 130396
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        long l[] = new long[100002];
        int next = 10;
        int cur = 1;

        l[1] = 1;
        l[2] = 2;
        l[3] = 3;
        l[4] = 4;
        l[5] = 5;
        l[6] = 6;
        l[7] = 7;
        l[8] = 8;
        l[9] = 9;
        for (; next <= k;) {
            long b = l[cur] % 10;

            if (b != 0) {
                l[next] = l[cur] * 10 + b - 1;
                next++;
            }
            l[next] = l[cur] * 10 + b;
            next++;
            if (b != 9) {
                l[next] = l[cur] * 10 + b + 1;
                next++;
            }

            cur++;
        }

        System.out.println(l[k]);
    }
}


Measured memory_bytes: 21844