akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N 500000
#define INFTY 1000000000

void mergeSort(int S[],int n,int left,int right);
void merge(int S[],int n,int left,int mid,int right);

int L[N/2 + 2],R[N/2 + 2];
int count;

int main(void)
{
  int S[N],n;
  int i;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S,n,0,n);

  printf("%d",S[0]);
  for(i = 1;i < n;i++){
    if(i != n) printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}
    




void merge(int S[],int n,int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  
  n1 = mid - left;
  n2 = right - mid;

  for(i = 0;i < n1;i++){
    L[i] = S[left+i];
  }
  for(i = 0;i < n2;i++){
    R[i] = S[mid+i];
  }
  
  L[n1] = INFTY;
  R[n2] = INFTY;
  
  i = 0;
  j = 0;
  
  for(k = left;k < right;k++){
    if(L[i] <= R[j]){
      S[k] = L[i];
      i++;
    } else {
      S[k] = R[j];
      j++;
    }
    count++;
  }
}



void mergeSort(int S[],int n,int left,int right){
  int m;
  
  if(left+1 < right){
    m = (left + right)/2;
    
    mergeSort(S,n,left,m);
    mergeSort(S,n,m,right);
    merge(S,n,left,m,right);
  }
}



Measured memory_bytes: 5636
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

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 F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vll a(n);
	vll b(n);
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];
	vll c(n,-1);
	if(n==1){
		if(a[0]!=b[0]) cout<<0<<endl;
		else cout<<1<<endl;
		return;
	}
	c[0]=a[0];
	reep(i,1,n){
		if(a[i-1]<a[i]){
			c[i]=a[i];
		}
	}
	if(c.back()>0&&c.back()!=b.back()){
		cout<<0<<endl;
		return;
	}
	c.back()=b.back();
	bool ng = false;
	if(a.back()!=b[0]) ng=false;
	reep(i,1,n){
		int p=n-1-i;
		if(b[p]>b[p+1]){
			if(c[p]>0&&c[p]!=b[p]){
				ng=true;
			}
			c[p]=b[p];
		}
		else if(c[p]>0&&c[p]>b[p]){
			ng=true;
			// cout<<p<<" "<<c[p]<<" "<<b[p]<<endl;
		}
	}
	ll ans = 1;
	if(ng){
		cout<<0<<endl;
		return;
	}
	rep(i,n){
		if(c[i]>0){
			continue;
		}
		else{
			(ans*=min(a[i],b[i])%MOD)%=MOD;
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

#define ll long long

int main(){
  multimap<ll,ll> A;
  ll N,M,a,b;
  cin >> N >> M;
  for(int i = 0;i < N;i++){
    cin >> a >> b;
    A.insert(make_pair(a,b));
  }
  auto p = A.upper_bound(0);
  ll manny = 0,count = 0;
  if(p->second < M){
    for (auto it = p; it->second < M - count; it++) {
      manny += it->first * it->second;
      count += it->second;
      p = it;
    }
    p++;
  }
  manny += p->first * (M - count);
  cout << manny << endl;
  return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    sort(a+1,a+n+1,greater<int>());
    for(int i=1;i<=n;++i){
        if(i+1>a[i+1]){
        	int ans=0;
            for(int j=i+1;a[j]==i;++j)ans^=1;
            ans|=(a[i]-i)&1;
            if(ans)puts("First");
            else puts("Second");
            return 0;
            
		}
	}
}

Measured memory_bytes: 640
//
//  main.cpp
//  D
//
//  Created by Knight_F on 2019/8/10.
//  Copyright © 2019年 Knight_F. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#define LL long long
using namespace std;
const int maxn=(int)1e5+10;
struct Node{
    int A,B;
}job[maxn];
int cmp(const Node &a,const Node &b){
    return a.A<b.A;
}
priority_queue <int> Q;
int main(){
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>job[i].A>>job[i].B;
    }
    sort(job+1,job+n+1,cmp);
    job[0].A=job[1].A;
    int cnt=1;
    long long ans=0;
    job[n+1].A=m+1;
    for(int i=1;i<=n+1;i++){
        while(cnt<=m&&job[i].A>cnt){
            if(!Q.empty()) ans+=Q.top(),Q.pop();
            cnt++;
        }
        if(cnt>m) break;
        Q.push(job[i].B);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1660
// https://atcoder.jp/contests/apg4b/tasks/APG4b_ac

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

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

const int INF = 1001001001;

int main()
{
	int n, m, x;
	cin >> n >> m >> x;

	int ans = INF;

	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));

	rep(i,n)
	{
		cin >> c[i];
		rep(j, m) cin >> a[i][j];
	}
		// 1<<n 2^n
		rep(s, 1<<n) {
			int cost =0;
			vector<int> d(m);
			rep(i, n) {
				// 右に１シフトずらして，そこが１だったら
				if (s>>i&1) {
					cost += c[i];
					rep(j, m) d[j] += a[i][j];
				}
			}
			bool ok = true;
			rep(j, m) if (d[j] < x) ok=false;
			if (ok) ans = min(ans, cost);
		}

	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
	int a[4];
	cin>>a[1]>>a[2]>>a[3];
	for(int i=1;i<3;i++)
	    for(int j=i+1;j<=3;j++)
	        if(a[i]>a[j])swap(a[i],a[j]);
	cout<<a[1]+a[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	string s,t;
	cin>>s>>t;
	s+=s;
	for(int i=0;i<=t.length();i++)
	{
		if(s.substr(i,t.length())==t)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!long;
    long[] AS;
    long a_sum;
    foreach (a; readln.split.to!(long[])) {
        AS ~= a;
        a_sum += a;
    }

    if (N == 1) {
        writeln("YES");
        return;
    }

    auto x = N*(N+1) / 2;
    if (a_sum % x != 0) {
        writeln("NO");
        return;
    }
    auto K = a_sum / x;

    long[] ds;
    foreach (i; 0..N) ds ~= AS[(i+1)%N] - AS[i];
    long k;
    foreach (d; ds) {
        if (d > K || (K-d) % N != 0) {
            writeln("NO");
            return;
        }
        k += (K-d) / N;
    }
    writeln(k == K ? "YES" : "NO");
}

Measured memory_bytes: 8552
N = int(input())
l1 = [int(i) for i in input().split()]
l2 = [int(i) for i in input().split()]

A = [l1, l2]
max_candy = 0
for i in range(N):
    temp = 0
    temp += sum(A[0][0:i+1])
    temp += sum(A[1][i:])
    if temp > max_candy:
        max_candy = temp

print(max_candy)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  int ans = 1;
  int mx = 0;
  for(int i  = 1; i <= n; i++){
    int now = i;
    int cnt = 0;
    while(now){
      if(now % 2 != 0) break;
      now /= 2;
      cnt++;
    }
    if(mx <= cnt){
      mx = cnt;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

	int one = 0, zero = 0;

	for (int i = 0; i < s.size(); i++)
		if (s[i] == '0')
			zero++;
		else
			one++;

	cout << min(zero, one) * 2 << endl;

	return 0;
}


Measured memory_bytes: 512
N = int(input())
W =[]
for i in range(N):
  W.append(list(map(int,input().split())))

W = sorted(W,key =lambda x:(x[1],x[0]))
now = 0
for w in W:
  #print(now,w[0])
  if now +w[0] > w[1]:
    print("No")
    exit()
  now+=w[0]
print("Yes")

Measured memory_bytes: 61432
#include <iostream>
#include <numeric>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int gcd(int m, int n) {
  int r;
  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }
  return m;
}

int lcm(int m, int n) { return (m * n) / gcd(m, n); }

int main() {
  int n;
  cin >> n;
  cout << lcm(n, 2) << endl;
}


Measured memory_bytes: 256
let () =
  let rec read () =
    try let line = read_line ()
                   |> Str.split (Str.regexp ",")
                   |> List.map float_of_string
                   |> Array.of_list
        in
        let sum = Array.fold_left (+.) 0. (Array.sub line 0 10) in
        let d = sum*.line.(10)/.(line.(10) +. line.(11)) in
        let rec find s i =
          if s >= d then i
          else find (s +. line.(i)) (i+1)
        in Printf.printf "%d\n" (find 0. 0);read ()
    with End_of_file -> ()
  in read ()
;;

Measured memory_bytes: 2340
// review
#include <iostream>

using namespace std;
typedef long long ll;

ll n, k;

void solve() {
  ll remain0 = n / k;
  ll remainHalf = 0;
  if (!(k & 1))  {
    remainHalf = n % k >= k / 2 ? remain0 + 1 : remain0;
  }
  cout << (remain0 * remain0 * remain0 + remainHalf * remainHalf * remainHalf) << endl;
}

int main() {
  cin >> n >> k;
  solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

int main() {
    long long n;
    int ans = 0;
    cin >> n;
    long long t = n - 1;
    for (long long i = 2; i * i <= t; i++)
        if (t % i == 0) {
            ans++;
            if (i * i != t) ans++;
        }
    if (t >= 2) ans++;
    for (long long i = 2; i * i <= n; i++)
        if (n % i == 0) {
            t = n;
            while (t % i == 0) t /= i;
            if (t % i == 1) ans++;
            if (i * i == n) continue;
            t = n;
            while (t % (n / i) == 0) t /= (n / i);
            if (t % (n / i) == 1) ans++;
        }
    ans++;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int n;
double dp[301][301][301];
double get(int c1, int c2 , int c3)
{
    if(c1 < 0 || c2 < 0 || c3 < 0 )return 0;
    if(!c1 && !c2 && !c3)return 0;

    double &ret = dp[c1][c2][c3];
    if(ret == ret)return ret;

    double p1 = 1.0*c1/n;
    double p2 = 1.0*c2/n;
    double p3 = 1.0*c3/n;
    double p = p1 + p2 + p3;

    return ret = (p1*(1+get(c1-1,c2,c3)) + p2*(1+get(c1+1,c2-1,c3)) + p3*(1+get(c1,c2+1,c3-1)) + 1-p)/p;
}
int main()
{
    cin >> n;

    int c1 = 0,c2 = 0,c3 = 0;
    for(int i = 0 ; i < n ; i++)
    {
        int a;  cin >> a;
        if(a == 1)c1++;
        else if (a == 2)c2++;
        else c3++;
    }
    memset(dp,-1,sizeof dp);
    printf("%.10f\n",get(c1,c2,c3));
    return 0;
}


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

int main(void)
{

    int n;
    cin >> n;
    vector<int> a(n);
    //全体
    long long sum = 0, x = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        sum += a.at(i);
    }
    //最小値を求めるので、大きな値を設定
    long long ans = 10000000000000000;

    for (int i = 0; i < n; i++)
    {
        x += a.at(i);
        //片方は1枚以上なのでn-1まで探索
        if (i < n - 1)
        {
            ans = min(ans, abs(sum - x * 2));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> E(H); 
    for (int i = 0; i < H; i++){
        cin >> E.at(i);
    }
    for (int k = 0; k <= W+1; k++){
        cout << "#";
    }
    cout << endl;
    for (int l = 0; l < H; l++){
        cout << '#' << E.at(l) << '#' << endl;
    }
    for (int k = 0; k <= W+1; k++){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int n;
	cin>>n;
	vi a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	int sum=0;
	rep(i,n)sum+=b[i]-a[i];
	if(sum<0){
		cout<<"No"<<endl;
		return 0;
	}
	int co1=sum,co2=sum;
	rep(i,n){
		if(a[i]<b[i]){
			int t=(b[i]-a[i]+1)/2;
			a[i]+=t*2;
			co1-=t;
		}
		if(a[i]>b[i]){
			int t=a[i]-b[i];
			co2-=t;
		}
	}
	if(co1<0||co2<0){
		cout<<"No"<<endl;
		return 0;
	}
	if(co1*2==co2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}










Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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 rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<ll> a, vector<ll> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int N, K;
    cin >> N >> K;
    VLL A(N+1);
    rep(i,N+1){
        A[i]=i;
    }
    VLL S(N+2);
    cum_sum(N+1,A,S);
    ll ans=0;
    rept(i,K,N+2){
        ll mini=S[i]-S[0];
        ll maxi=S[N+1]-S[N+1-i];
        ll count=maxi-mini+1;
        ans+=count;
    }
    cout << ans%(MOD) << endl;
}

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

int main(){
    ll n,c=0,d=0;
    cin>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(a[i]>b[i]){
            c+=a[i]-b[i];
        }
        else if(a[i]+1<b[i]){
            d+=(b[i]-a[i])/2;
        }
    }
    if(c>d) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
   
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))

using namespace std;

string s, t;
int ls, lt, sum, ans = 10000;

int read(){
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}
    return x*w;
}

inline void write(int x){
  	static int sta[35];int top=0;
  	do{sta[top++]=x%10,x/=10;}while (x);
  	while(top)putchar(sta[--top]+48);
}

signed main()
{
    cin>>s; cin>>t;
    ls = s.length()-1; lt = t.length()-1;
    Rep(i,0,ls-lt) {
        sum = 0;
        Rep(l,0,lt) {
            if(s[l+i] != t[l]) sum ++;
        }
        ans = min(sum, ans);
    }
    write(ans);

    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
void calc() {
    int gx, gy; cin >> gx >> gy;
    int p; cin >> p;
    int x1[p], y1[p], x2[p], y2[p];
    rep(i, p) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    ll table[gx + 1][gy + 1];
    rep(i, gx + 1) rep(j, gy + 1) table[i][j] = 0;
    rep(i, gx + 1) rep(j, gy + 1) {
        if (i == 0 && j == 0) {
            table[i][j] = 1;
            continue;
        }
        ll sita = (j <= 0) ? 0 : table[i][j - 1];
        ll hidari = (i <= 0) ? 0 : table[i - 1][j];
        rep(k, p) {
            if (j - 1 >= 0) { //下がx
                if (x1[k] == i && x2[k] == i && ((y1[k] == j - 1 && y2[k] == j) || (y1[k] == j && y2[k] == j - 1))) {
                    sita = 0;
                    //break;
                }
            }
            if (i - 1 >= 0) { //左 x
                if (y1[k] == j && y2[k] == j && ((x1[k] == i - 1 && x2[k] == i) || (x1[k] == i && x2[k] == i - 1))) {
                    hidari = 0;
                    //break;
                }
            }
        }
        table[i][j] = hidari + sita;
    }
    /*
    rep(i, gx + 1) {
        rep(j, gy + 1) cout << table[i][j] << " ";
        cout << endl;
    }
    */
    if (table[gx][gy] != 0) cout << table[gx][gy] << endl;
    else cout << "Miserable Hokusai!" << endl;
}
int main() {
    int q; cin >> q;
    rep(i, q) calc();
}


Measured memory_bytes: 3008
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
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>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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 N,M;
  cin>>N>>M;
  Graph G(N);
  REP(i,M){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].PB(b);
    G[b].PB(a);
  }
  map<int,int> DEG;
  REP(i,N) DEG[(int)G[i].size()]++;
  
  bool CAN=true,CCAN=false;
  FORE(v,DEG){
    if(v.first%2!=0) CAN=false;
  }
  
  for(int i=3; i<=N; ++i){
    if(DEG[2*i]>0) CCAN=true;
  }
  
  if(CCAN==false){
    if(DEG[4]<=1) CAN=false;
    if(DEG[4]==2){
      
      vector<int> FOUR;
      REP(i,N){
        if((int)G[i].size()==4) FOUR.PB(i);
      }
      int S=FOUR[0],T=FOUR[1],cnt=0;
      bool SEEN[N];
      REP(i,N) SEEN[i]=false;
      
      queue<int> Q;
      Q.push(S);
      SEEN[S]=true;
      
      while(!Q.empty()){
        int v=Q.front();
        Q.pop();
        FORE(nv,G[v]){
          if(nv==T) cnt++;
          if(SEEN[nv] || nv==S || nv==T) continue;
          SEEN[nv]=true;
          Q.push(nv);
        }
      }
      
      if(cnt!=2) CAN=false;
    }
  }
  
  if(CAN) COYe;
  else CONo;
  return 0;
}

Measured memory_bytes: 13568
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn max<T: std::cmp::PartialOrd>(a: T, b: T) -> T {
    if a > b {
        return a;
    } else {
        return b;
    }
}

fn main() {
    let n: usize = read();
    let w: usize = read();

    let mut wi: Vec<usize> = Vec::new();
    let mut vi: Vec<u64> = Vec::new();

    for _ in 0..n {
        wi.push(read());
        vi.push(read());
    }

    let mut dp = vec![vec![0; w+1]; n+1];

    for i in 0..n {
        for sum_w in 0..w+1 {
            if sum_w >= wi[i] {
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - wi[i]] + vi[i]);
            }

            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    println!("{}", dp[n][w]);
}


Measured memory_bytes: 106748
myProd :: Integer -> Integer -> Integer
myProd _ 0 = 0
myProd 0 _ = 0
myProd _ (-1) = -1
myProd x y
    | y > 10 ^ 18 = -1
    | otherwise   = x * y

solve :: [Integer] -> Integer
solve xs = foldr1 myProd (1:xs)

main :: IO ()
main = do
    getLine
    getLine >>= return . solve . map read . words >>= print


Measured memory_bytes: 187360
N,M = map(int,input().split())
W = dict()
A = dict()
ac = 0
pt = 0
Q = []
for i in range(M):
    p, S = input().split()
    p = int(p)
    if not p in W.keys():
        W[p] = 0
        A[p] = 0
    if S == 'WA':
        W[p] += 1
    if S == 'AC':
        if A[p] != 'AC':
            A[p] = 'AC'
            pt += W[p]
            ac += 1
print(ac,pt)

Measured memory_bytes: 21212
n = int(input())
a = []
d={}
for i in range(n):
    x = int(input())
    a.append(x)
for i in range(len(a)):
    d[a[i]]=0
for i in range(len(a)):
    d[a[i]]+=1
l = 0
for key in d:
    l+=(d[key]%2)
print(l)


Measured memory_bytes: 59736
import bisect
from collections import deque

N = int(input())

largest = deque([])
for i in range(N):
    A_i = int(input())
    idx = bisect.bisect_left(largest, A_i)
    if idx == 0:
        largest.appendleft(A_i)
    else:
        largest[idx - 1] = A_i
print(len(largest))


Measured memory_bytes: 47960
import sys
import time
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    S = input()
    ans = 0
    for i in range(N):
        X = set(S[:i])
        Y = set(S[i:])
        ans = max(ans, len(X&Y))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, w = sc.nextInt
    val items = Array.fill[Array[Long]](n)(Array.fill[Long](2)(0))
    for (i <- 0 until n) {
      items(i)(0) = sc.nextLong //w
      items(i)(1) = sc.nextLong //v
    }

    val dp = Array.fill[Array[Long]](n + 1)(Array.fill[Long](100100)(0))
    for (i <- 0 until n) {
      for (sumW <- 0 to w) {
        // i番目の品物を選ぶ
        if (sumW - items(i)(0) >= 0) {
          dp(i + 1)(sumW) = math.max(dp(i + 1)(sumW), dp(i)((sumW - items(i)(0)).toInt) + items(i)(1))
        }

        // i番目の品物を選ばない
        dp(i + 1)(sumW) = math.max(dp(i + 1)(sumW), dp(i)(sumW))
      }
    }
    println(dp(n)(w))
  }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int H, W; cin >> H >> W;
  vector<string> s(H); REP(i, H) cin >> s[i];
  vector<vector<int>> f(H, vector<int>(W, -1));
  int all_num = 0;
  REP(i, H) {
    REP(k, W) {
      if(s[i][k] == '.') all_num++;
    }
  }
  queue<P> q; q.push(make_pair(0, 0));
  int cnt = 0; f[0][0] = 1;
  while(!q.empty()) {
    auto p = q.front(); q.pop();
    int x = p.first; int y = p.second;
    cnt++;
    for(int i = 0; i < 4; ++i) {
      if(x + dx[i] < 0 || x + dx[i] >= H) continue;
      if(y + dy[i] < 0 || y + dy[i] >= W) continue;
      if(s[x + dx[i]][y + dy[i]] == '#') continue;
      if(f[x + dx[i]][y + dy[i]] != -1) continue;
      f[x + dx[i]][y + dy[i]] = f[x][y] + 1;
      q.push(make_pair(x + dx[i], y + dy[i]));
    }
  }
  if(f[H - 1][W - 1] == -1) cout << -1 << endl;
  else cout << all_num - f[H - 1][W - 1] << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int n,cnt=0;cin>>n;
  int p_2,p_1,p;cin>>p_2>>p_1;
  REP(i,2,n){
    cin>>p;
    if(((p_2<p_1)&&(p_1<p))||((p<p_1)&&(p_1<p_2)))cnt++;
    p_2=p_1;
    p_1=p;
  }
  print(cnt)
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int a , b , c , tmp;
  scanf("%d%d%d", &a, &b, &c);
  if( b > c ) {
    tmp = b; b = c; c = tmp;
  }
  if( a > b ) {
    tmp = a; a = b; b = tmp;
  }
  if( b > c  ) {
    tmp = b; b = c; c = tmp;
  }
   
   printf("%d %d %d\n", a, b, c);

  return 0;
}





Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   
   ll xo = 0;
   rep(n)
   {
        cin>>arr[i];
        xo^=arr[i];
   }
   
   rep(n)
        cout<<(xo^arr[i])<<" ";
   
   return 0;        
}  
  
          
   


Measured memory_bytes: 5132
#include <bits/stdc++.h>
using namespace std;
const int maxn=2*100000+5;
vector<int> g[2][maxn];
void addedge(int id,int from,int to)
{
    g[id][from].push_back(to);g[id][to].push_back(from);
}
int n,k,l;
bool vis[maxn];
int Bel[2][maxn];
vector<int> has[maxn];
set<int> ach[maxn];
void dfs(int v,int paint,int id)
{
    if(id==0) has[paint].push_back(v);
    if(id==1) ach[paint].insert(v);
    vis[v]=true;
    Bel[id][v]=paint;
    for(int i=0;i<(int)g[id][v].size();i++)
    {
        int u=g[id][v][i];
        if(!vis[u]) dfs(u,paint,id);
    }
}
int rlt[maxn];
int have[maxn];
int main()
{
    scanf("%d%d%d",&n,&k,&l);
    for(int i=0;i<k;i++)
    {
        int from,to;
        scanf("%d%d",&from,&to);
        addedge(0,from,to);
    }
    for(int i=0;i<l;i++)
    {
        int from,to;
        scanf("%d%d",&from,&to);
        addedge(1,from,to);
    }
    int bl1,bl2;
    int bl=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i]){
            dfs(i,++bl,0);
        }
    }
    bl1=bl;
    memset(vis,0,sizeof(vis));
    bl=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i]){
            dfs(i,++bl,1);
        }
    }
    bl2=bl;
    for(int i=1;i<=bl1;i++)
    {
        for(int j=0;j<(int)has[i].size();j++)
            have[Bel[1][has[i][j]]]++;
        for(int j=0;j<(int)has[i].size();j++)
            rlt[has[i][j]]=have[Bel[1][has[i][j]]];
        for(int j=0;j<(int)has[i].size();j++)
            have[Bel[1][has[i][j]]]=0;
    }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=0;j<(int)has[Bel[0][i]].size();j++)
        {
            int u=has[Bel[0][i]][j];
            if(Bel[1][u]==Bel[1][i]) rlt[i]++;
        }
    }*/
    for(int i=1;i<=n;i++)
        printf("%d%c",rlt[i],i==n?'\n':' ');
    return 0;
}


Measured memory_bytes: 46328
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        None
    } else {
        s.parse::<T>().ok()
    }
}

fn main(){
    while let Some(s) = read::<String>() {
        let mut ans = None;
        for i in 0..26 {
            let c = (i + 'a' as u8) as char;
            if s.find(c).is_none() {
                ans = Some(c.to_string());
                break;
            }
        }
        println!("{}", ans.unwrap_or("None".to_owned()));
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(int, a, b, c);
	YesNo(a + b == c || a + c == b || b + c == a);
}

Measured memory_bytes: 256
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
#define ld long db
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db find() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
}
using namespace fast_io;
#define pb push_back
ll a,b,ans,l,r,s,t,k;
int main()
{
	a=read(),b=read();if(a==b) return write("1"),ot(),0;
	for(k=61;~k;k--) if(((a>>k)&1)!=((b>>k)&1))
	{
		l=a&((1ll<<(k+1))-1),r=l+(b&(1ll<<k)),t=k-1;
		while(~t&&!((b>>t)&1)) t--;
		s=(1ll<<k)+(1ll<<(t+1))-1;break;
	}
	write((1ll<<(k+1))-l+(s<r)*(s-r+1),'\n');
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 3560
n,m= map(int, input().split())
h = list( map(int, input().split()))
ab = [map(int,input().split()) for i in range(m)]


# s = input()

# n,m,q = map(int, input().split())
# abcd = [map(int, input().split())for _ in range(q)]

# a = list(map(int, input().split()))
G = {}

for a,b in ab:
    if a-1 not in G:
        G[a-1]={b-1}
    else:
        G[a-1].add(b-1)
    if b-1 not in G:
        G[b-1]={a-1}
    else:
        G[b-1].add(a-1)
ans=0
for i in range(n):
    if i not in G:
        ans +=1
        continue
    visited = G[i]
  
    height = h[i]
    flag = True
    for j in visited:
        if j == i:
            continue
        else:
            if h[j] >= height:
                flag =False
                break
    if flag :
        ans +=1
print(ans)



Measured memory_bytes: 66480
def solve():
  while True:
    m, n  = int(input()), int(input())
    if not m:
      break
    ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)]
    ices.insert(0, [0] * (m + 2),)
    ices.append([0] * (m + 2))
    score = [[0] * (m + 2) for _ in range(n + 2)]
    
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if ices[x][y]:
          score[x][y] += (ices[x - 1][y] + ices[x + 1][y] + ices[x][y - 1] + ices[x][y + 1])
    
    def bfs(x, y, imap, acc):
      imap[x][y] = 0
      acc += 1
      a = b = c = d = 0
      if imap[x - 1][y]:
        a = bfs(x - 1, y, imap, acc)
      if imap[x + 1][y]:
        b = bfs(x + 1, y, imap, acc)
      if imap[x][y - 1]:
        c = bfs(x, y - 1, imap, acc)
      if imap[x][y + 1]:
        d = bfs(x, y + 1, imap, acc)
      imap[x][y] = 1
      return max(acc, a, b, c, d)
    
    ans = 0
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if score[x][y] in [1, 2] and ices[x][y]:
          a = bfs(x, y, ices, 0)
          if ans < a:
            ans = a
    
    print(ans)

solve()


Measured memory_bytes: 5808
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1LL<<32
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
 
 
int main(void) {
    ll n, i;
    cin >> n >> i;
    cout << n-i+1 << endl;
    
}

Measured memory_bytes: 256
import copy

D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))
last = [0]*26
    
ans = 0
md = [0]*26
cand = []
cand2 = []
tl = []

for day in range(D):
    for j in range(26):
        last[j] += 1
    
    for k in range(26):
        #k番目を選ぶことによる
        merit = s[day][k]
        merit += last[k] * c[k]
        demerit = 0
        for j in range(26):
            if j != k:
                demerit += c[j] * last[j]
        md[k] = merit - demerit

    #日程の確定
    md2 = sorted(md)
    t = md.index(md2[-1])
    last[t] = 0
    tl.append(t+1)
    
    can = md.index(md2[-2])
    cand.append(can+1)
    
    can2 = md.index(md2[-3])
    cand2.append(can2+1)
    #print(t+1)
    

    
#得点計算

def calcans(tl):
    last = [0]*26
    ans = 0
    for day in range(D):
        #満足度プラス計算
        ans += s[day][tl[day]-1]
        for j in range(26):
            last[j] += 1
        last[tl[day]-1] = 0
        #満足度マイナス計算
        minus = 0
        for j in range(26):
            minus += c[j] * last[j]
        ans -= minus
    return ans

normal = calcans(tl)
change = -1

tl2 = copy.deepcopy(tl)
for ii in range(D):
    tl2[ii] = cand[ii]
    challenge = calcans(tl2)
    if normal < challenge:
        normal = challenge
    else:
        tl2[ii] = cand2[ii]
        challenge = calcans(tl2)
        if normal < challenge:
            normal = challenge
        else:
            tl2[ii] = tl[ii]
        
    
for tlc in tl2:
    print(tlc)

Measured memory_bytes: 9540
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

set<P> st;
int H, W;
int M;

int cnth[300000], cntw[300000];


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W;
    cin >> M;
    int maxh = 0, maxw = 0;
    for(int i = 0; i < M; i++){
        int h, w; cin >> h >> w; h--; w--;
        cnth[h]++; cntw[w]++;
        maxh = max(maxh, cnth[h]);
        maxw = max(maxw, cntw[w]);
        st.insert(P(h, w));
    }
    vector<int> vh;
    vector<int> vw;
    for(int h = 0; h < H; h++){
        if(cnth[h] == maxh) vh.push_back(h);
    }
    for(int w = 0; w < W; w++){
        if(cntw[w] == maxw) vw.push_back(w);
    }
    for(int h : vh){
        for(int w : vw){
            if(st.count(P(h, w)) == 0){
                cout << maxh+maxw << endl;
                return 0;
            }
        }
    }
    cout << maxh+maxw-1 << endl;
}

Measured memory_bytes: 23832
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		double ans = 0;
		if(n == 1){
		    ans = 1;
		    System.out.println(ans);
		}
		else if(n%2 == 0){
		    ans = 0.5;
		    System.out.println(ans);
		}
		else{
		    ans =  (double)((n-1)/2 +1)/(double)n;
		    System.out.println(ans);
		}
	}

}

Measured memory_bytes: 35976
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,m = LI()
    student = []
    spot = []
    for _ in range(n):
        a,b = LI()
        student.append([a,b])

    for _ in range(m):
        c,d = LI()
        spot.append([c,d])
    inf = float("inf")
    for x,y in student:
        near = (0,inf)
        area_num = 1
        for s,t in spot:
            dist = abs(x-s) + abs(y-t)
            if near[1] > dist:
                near = (area_num,dist)
            area_num += 1
        print(near[0])
main()

Measured memory_bytes: 74724
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int x,y;
  cin >> x >> y;
  if(x==1) x=14;
  if(y==1) y=14;
  if(x==y) pr("Draw");
  else if(x>y) pr("Alice");
  else pr("Bob");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int h = 5*n+10;
			int[][] map = new int[h][5];
			int d, p, q, max, cnt;
			for(int i=0;i<n;i++){
				d = sc.nextInt();
				p = sc.nextInt();
				q = sc.nextInt() - 1; 
				
				if(d==1){
					max = -1;
					for(int j=q;j<q+p;j++){
						cnt = h-1;
						while(map[cnt][j]==0){
							cnt--;
							if(cnt==-1) break;
						}
						max = Math.max(max, cnt);
					}
					for(int j=q;j<q+p;j++) map[max+1][j] = 1;
				}else{
					cnt = h-1;
					while(map[cnt][q]==0){
						cnt--;
						if(cnt==-1) break;
					}
					for(int j=cnt+1;j<cnt+1+p;j++) map[j][q] = 1;
				}
				
				cnt = 0;
				for(int j=0;j<h;j++){
					if(map[j][0]==1 && map[j][1]==1 && map[j][2]==1 && map[j][3]==1 && map[j][4]==1) continue;
					map[cnt] = map[j];
					cnt++;
				}
			}
			
			int sum = 0;
			for(int i=0;i<h;i++){
				for(int j=0;j<5;j++){
					sum += map[i][j];
				}
			}
			System.out.println(sum);
		}	
	}	
}

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

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

int main(){
	int sum;
	
	while(scanf("%d",&sum),sum){
		rep(i,9){
			int a; scanf("%d",&a);
			sum -= a;
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		double s[1000]={0.0},ave=0.0,sum=0.0;
		for(int i=0;i<n;i++){
			cin>>s[i];
			ave+=s[i];
		}
		ave=ave/n;
		for(int i=0;i<n;i++){
			s[i]=pow((s[i]-ave),2);
			sum+=s[i];
		}
		printf("%.8lf\n",sqrt(sum/n));
	}
	return 0;
}

Measured memory_bytes: 3180
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, k int

	fmt.Sscan(getNextLine(scanner), &n, &k)

	ans := 0
	for i := 1; i <= n; i++ {
		am := i % k
		bm := (k - am) % k
		cm := (k - am) % k
		if (bm+cm)%k == 0 {
			if bm == 0 {
				ans += ((n - bm) / k) * ((n - cm) / k)
				continue
			}
			ans += ((n - bm + k) / k) * ((n - cm + k) / k)
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

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

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

  if (n == 1 && m == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1 || m == 1) {
    cout << n * m - 2 << endl;
    return 0;
  }

  cout << (n-2) * (m-2) << endl;

  return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
if A+B <= 2*C:
    print(A*X + B*Y)
else:
    if X >= Y:
        if A >= 2*C:
            print(X*2*C)
        else:
            print(Y*2*C + (X-Y)*A)
    else:
        if B >= 2*C:
            print(Y*2*C)
        else:
            print(X*2*C + (Y-X)*B)

Measured memory_bytes: 3064