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

using namespace std;

int dec(vector<int>& arr, int beg) {
    while(1 + beg < (int)arr.size() && arr[beg] >= arr[1 + beg]) ++beg;
    return beg;
}


int cre(vector<int>& arr, int beg) {
    while(1 + beg < (int)arr.size() && arr[beg] <= arr[1 + beg]) ++beg;
    return beg;
}

int solve(vector<int>& arr) {
    int ans = 0, i = 0;
    for(i = 0; i < (int)arr.size() - 1; ++i) {
        re:
        if(i >= (int)arr.size()-1) break;
        if(arr[i] > arr[1 + i]) {
            i = 1 + dec(arr, i);
            ++ans;
            goto re;
        }
        else if(arr[i] < arr[1 + i]) {
            i = 1 + cre(arr, i);
            ++ans;
            goto re;
        }
    }
    if(i == arr.size() - 1) ++ans;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
    cout << solve(arr) << '\n';
    return 0;
}


Measured memory_bytes: 640
from collections import Counter
input()
V = list(map(int, input().split()))
odd = Counter(V[::2])
even = Counter(V[1::2])
odd_max = max(odd.items(), key=lambda x: x[1])
even_max = max(even.items(), key=lambda x: x[1])
if odd_max[0] != even_max[0]:
    print(len(V) - odd_max[1] - even_max[1])
    exit()
odd_second = odd.most_common(2)
if len(odd_second) >= 2:
    odd_second = odd_second[1][1]
else:
    odd_second = 0
even_second = even.most_common(2)
if len(even_second) >= 2:
    even_second = even_second[1][1]
else:
    even_second = 0
if odd_second >= even_second:
    first = even_max[1]
    second = odd_second
else:
    first = odd_max[1]
    second = even_second
print(len(V) - first - second)


Measured memory_bytes: 18656
#include<bits/stdc++.h>
using namespace std;
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 ll long long
#define MOD (ll)1e9+7
#define REP(i,b,e) for(int (i)=b;(i)<e;(i)++)
const ll INF= 1LL << 60;

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


//入力
ll n;
vector<ll> A((ll)1e5+10,0);
vector<ll> B((ll)1e5+10,0);
int main(){
  cin >> n;
  REP(i,0,n/2){
    ll a,b;
    cin >> a>>b;
    A[a]++;
    B[b]++;
  }
  
  ll a,b,na[2],nb[2];
  auto ai=max_element(A.begin(),A.end());
  a=distance(A.begin(),ai);
  na[0]=A.at(a);
  A.at(a)=0;
  na[1]=*max_element(A.begin(),A.end());
  
  auto bi=max_element(B.begin(),B.end());
  b=distance(B.begin(),bi);
  nb[0]=B.at(b);
  B.at(b)=0;
  nb[1]=*max_element(B.begin(),B.end());
  
  ll ans=0;
  if(a!=b){
    chmax(ans,na[0]+nb[0]);
  }else{
    chmax(ans,na[0]+nb[1]);
    chmax(ans,na[1]+nb[0]);
  }
  
  cout<<n-ans<<endl;
  
  return 0;
}

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define MOD 1000000007
#define PI 3.14159265359
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int n;
	cin>>n;

	int a[n],x=0;

	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		x=x^a[i];
	}

	for(int i=0;i<n;i++)
	{
		int ans = x^a[i];
		cout<<ans<<" ";
	}

}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<long long int> a(n),as(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  as[0] = a[0];
  for(int i=1;i<n;i++) as[i] = a[i] + as[i-1];
  int ind = 0;
  for(int i=n-1;i>0;i--){
  	if(a[i] > 2 * as[i-1]){ ind = i; break;}
  }
  cout << n - ind << endl;
  return 0;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAXN 201010
typedef long long int ll;
typedef pair<int, int> pii;

int main(){
	int v[5];
	int ans = 1010101010;
	cin >> v[0] >> v[1] >> v[2];
	
	sort(v, v + 3);
	do
	{
		int aux = abs(v[1] - v[0]) + abs(v[2] - v[1]);
		ans = min(ans, aux);
	} while (next_permutation(v, v + 3));
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<double> dp(n+1);
    dp[0]=1;
    for(int coin=1; coin<=n; ++coin){
        double pi_head;
        cin>>pi_head;
        double pi_tail = 1-pi_head;
        for(int i=coin ; i>=0; --i){
            dp[i] = ( i==0 ? 0 : dp[i-1]*pi_head) + dp[i]*pi_tail;
        }
    }
    int max_head= n/2+1;
    double ans=0;
    for(int i=max_head; i<=n; ++i){
        ans+=dp[i];
    }
    printf("%.10lf\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>

#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;

// <<fixed<<setprecision(6)<<

int gcd(lint x, lint y){
	return y==0 ? x:gcd(y,x % y);
}



int main(){
  int l;
  cin>>l;
  if(l%3==0){
      double i = double(l)/3.0;
      i=i*i*i;
      cout<<fixed<<setprecision(12)<<i;
  }
  else {
    double a,b,c;
    a=double(l)/3.0;
    b=double(l)/3.0;
    c=double(l)/3.0;
    cout<<fixed<<setprecision(12)<<a*b*c;
  }
}


Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
s =["#"*(w+2)] + ["#" + str(input()) + "#" for i in range(h)] + ["#"*(w+2)]
opt = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            temp = [[0]*(w+2) for i in range(h+2)]
            temp[i][j] = 1
            dq = deque([(i,j)])
            
            while dq:
                x,y = dq.popleft()
                for k in opt:
                    x1,y1 = x+k[0],y+k[1]
                    if s[x1][y1] == "." and temp[x1][y1] == 0:
                        temp[x1][y1] = temp[x][y] + 1
                        dq.append((x1,y1))
                        ans=max(ans,temp[x1][y1])
print(ans-1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 100001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
void solve(){
	ll n,k;
	cin>>n>>k;
	vl a(n);
	cin>>a;
	vector<bool> is(k+1);
	ll mn=*min_element(all(a));
	is[mn]=true;
	for(ll i=mn+1;i<=k;i++){
		for(ll j=0;j<n;j++){
			if(a[j]<=i) is[i]=is[i]|(!is[i-a[j]]);
		}
	}
//	cout<<is;
	if(is[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    cout << S.substr(0, 4) << " " << S.substr(4, 8) << endl;
}


Measured memory_bytes: 256
def doChain(ar, si, ei):
	p, c = 0, []  #p:ar[i]のcolor, c:4連続以上のarのindex
	for i in range(si, ei):
		if ar[i]==p:
			c.append(i)
			if i==len(ar)-1 and len(c)>=4:
				del ar[min(c):max(c)+1]
				return True, max(0, si-3),min(ei+5, len(ar))
		else:
			if len(c)>=4:
				del ar[min(c):max(c)+1]
				return True, max(0, si-3),min(ei+5, len(ar))
			p = ar[i]
			c = [i]
	return False, 0, len(ar)


while True:
	N = int(input())
	if N==0: break
	A = [int(input()) for _ in range(N)]
	minvalue = N
	for j in range(len(A)-1):
		B = A[:]
		if B[j+1]!=B[j]:
			B[j+1] = B[j]
			result = True
			si, ei = max(0, j-3), min(j+5, len(A))
			while result==True:
				result, si, ei = doChain(B, si, ei)
				if len(B)<minvalue:
					minvalue = len(B)

	print(minvalue)



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

int n, A[200005];

int getsum(int l, int r){ // [ l, r ]
  
  int res = A[r];
  
  if( l != 0 ) res -= A[l-1];
  
  return res;
}

typedef pair<int,int> P;

vector<P> get(int l, int r){ // [ l, r ]

  int L = l, R = r;
  
  while( L < R ){
    
    int M = ( L + R ) / 2;
    
    if( getsum( l, M ) < getsum( M + 1, r ) ) L = M + 1;
    else R = M;
    
  }
  
  vector<P> res;
  
  for(int i=-10;i<=10;i++){
    
    if( L + i - l + 1 >= 1 && r - ( L + i + 1 ) + 1 >= 1 ){
      
      res.push_back( P( getsum( l, L + i ), getsum( L + i + 1, r )) );
      
    }
    
  }
  
  return res;
}

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
    cin>>A[i];
    if( i ) A[i] += A[i-1];
  }
  
  int ans = 1e18;
  
  for(int i=1;i<n-1;i++){
    
    vector<P> a = get( 0, i );
    
    vector<P> b = get( i + 1, n - 1 );
    
    for(int j=0;j<(int)a.size();j++){

      for(int k=0;k<(int)b.size();k++){
	
	int v1 = a[j].first;
	int v2 = a[j].second;
	int v3 = b[k].first;
	int v4 = b[k].second;
	
	int maxv = max( max( v1, v2 ), max( v3, v4 ) );
	
	int minv = min( min( v1, v2 ), min( v3, v4 ) );
	
	ans = min( ans, maxv - minv );
	
      }
      
    }
    
  }

  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vecint v(n, -1);
  REP(i,n) {
    int a;
    cin>>a;
    *prev(lower_bound(ALL(v),a))=a;
  }
  cout<<n-count(ALL(v),-1)<<endl;
  return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   	string check, text;
   	int ret = 0;
   	cin >> check;
   	for(int i = 0 ; i < (int)check.size(); i++) 
   	if (check[i] >= 'A' && check[i] <= 'Z') check[i] += 'a' - 'A';
   	cin >> text;
   	while(text != "END_OF_TEXT"){
	  for(int i = 0 ; i < (int)text.size(); i++) 
	  if (text[i] >= 'A' && text[i] <= 'Z') text[i] += 'a' - 'A';
	  if (text == check) ret++;
	  cin >> text;
	}
  cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	lli 			long long int
#define 	rep(i, n) 		for(int i = 0 ; i < n ; i++)
#define 	repn(i, n) 		for(int i = n - 1 ; i >= 0 ; i--)
#define 	loop(i, a, b)	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define 	hello 			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	pb 				push_back
#define 	mp				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define 	vs 				vector<string>
#define 	print(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; }

bool compare(const pair<string, int> &a, const pair<string, int> &b){ return a.second < b.second; }

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

int main()
{
	boost;
	int  n, m;
	cin>>n>>m;
	if(n<m)
		rep(i,m)cout<<n;
	else
		rep(i,n)cout<<m;
	cout<<nl;
}

Measured memory_bytes: 256
def hantei(ls, X):
    dekita=True
    for i in ls:
        if i < X:
            dekita=False
    if dekita==True:
        return True
    else:
        return False


N,M,X=list(map(int,input().split()))
hon=[]
for i in range(N):
    hon.append(list(map(int,input().split())))

keihi_rireki=[]
for i in range(2**N):
    rikaido=[0]*M
    keihi=0
    dekita=False
    for j in range(N):
        if((i>>j) & 1):
            keihi=keihi+hon[j][0]
            for k in range(M):
                rikaido[k]=rikaido[k]+hon[j][k+1]
    if hantei(rikaido, X)==True:
        keihi_rireki.append(keihi)

if len(keihi_rireki)==0:
    print(-1)
else:
    print(min(keihi_rireki))


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void dfs(string s, char mx, int n) {
  if (n == s.size()) {
    cout << s << endl;
  } else {
    for (char c = 'a'; c <= mx; c++) {
      dfs(s + c, (c == mx) ? (mx + 1) : mx, n);
    }
  }
}

void solve() {
  int N;
  cin >> N;
  dfs("", 'a', N);
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int H, W;
char A[1024][1024];
char visited[1024][1024];

struct queue_t {
	int y, x;
	int cost;
} Q[1024 * 1024];
int Qbegin = 0, Qend = 0;

int main(void) {
	static const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
	int i, j;
	int maxCost = 0;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%1023s", A[i]) != 1) return 1;
		for (j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				Q[Qend].y = i;
				Q[Qend].x = j;
				Q[Qend].cost = 0;
				Qend++;
				visited[i][j] = 1;
			}
		}
	}
	while (Qbegin < Qend) {
		struct queue_t cur = Q[Qbegin++];
		if (cur.cost > maxCost) maxCost = cur.cost;
		for (i = 0; i < 4; i++) {
			int ny = cur.y + d[i][0];
			int nx = cur.x + d[i][1];
			if (0 <= nx && nx < W && 0 <= ny && ny < H && !visited[ny][nx]) {
				Q[Qend].y = ny;
				Q[Qend].x = nx;
				Q[Qend].cost = cur.cost + 1;
				Qend++;
				visited[ny][nx] = 1;
			}
		}
	}
	printf("%d\n", maxCost);
	return 0;
}


Measured memory_bytes: 14464
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
	string str;
	cin >> str;
	int count = 0;
	if (str.length() == 1){
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i < str.length(); i++){
		if (str[i] != str[i - 1]){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 512
function main(input) {
    input = input.split("\n");
    var n = parseInt(input[0].split(" ")[0]);
    var x = parseInt(input[0].split(" ")[1]);
    var list = input[1].split(" ").map(v=>parseInt(v,10));

    var i = 0;
    var d = 0;
    while(n > i) {
        d = d + list[i];
        if (d > x) break;
        i++;
    }

    console.log(i + 1);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
program range_set
  implicit none
  integer(8), parameter :: modu = 1000000007
  integer :: n, a, b, i, j
  integer(8) :: x = 1, f(0:5000, 2) = 0, g(0:5000, 2) = 0
  read(*,*) n, a, b
  if (a > b) then
    i = a
    a = b
    b = i
  end if
  g(1, 2) = 1
  do i = 2, b - 1
    g(i, 2) = mod(sum(g(i - 1, :)), modu)
    g(i, 1) = mod(sum(g(1:i - a, 2)), modu)
  end do
  f(0, :) = 1
  do i = 1, n
    x = mod(x * 2, modu)
    f(i, 1) = mod(sum(f(max(i - a + 1, 0):i - 1, 2)), modu)
    do j = 1, min(b - 1, i)
      if (i == n) f(i, 1) = mod(f(i, 1) + f(i - j, 1) * g(j, 1), modu)
      f(i, 2) = f(i, 2) + merge(sum(g(j, :)), mod(f(i - j, 1) * g(j, 2), modu), j == i)
    end do
    f(i, 2) = mod(f(i, 2), modu)
  end do
  write(*,'(i0)') modulo(x - sum(f(n, :)), modu)
end program range_set

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

int main() {
  int N;
  cin >> N;
  
  for (int i = 1; i < 10; i++) {
    if (N % i != 0) continue;
    if (N/i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

int main(){
  string s;
  while(cin >> s && s[0] != '#'){
    vector< vector< char > > non_jfen;
    vector<char> v;
    non_jfen.push_back(v);
    int hgt = 0;
    for(int i = 0 ; i < s.size(); i++){
      if(s[i] == '/'){
        non_jfen.push_back(v);
        hgt++;
      }
      else if(s[i] == 'b'){
        non_jfen[hgt].push_back(s[i]);
      }
      else{
        for(int j = 0; j < stoi(s.substr(i,1)); j++){
          non_jfen[hgt].push_back('.');
        }
      }
    }
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    non_jfen[a-1][b-1] = '.';
    non_jfen[c-1][d-1] = 'b';
    string ans;
    for(int i = 0; i < non_jfen.size(); i++){
      for(int j = 0; j < non_jfen[i].size(); j++){
        if(non_jfen[i][j] == '.'){
          a = 0;
          int k;
          for( k = j ; k < non_jfen[i].size(); k++){
            if(non_jfen[i][k] == '.') a++;
            else{
              break;
            }
          }
          j = k-1;
          ostringstream ss;
          ss << a;
          ans = ans + ss.str();
        }
        else ans.push_back('b');
      }
      if(i != non_jfen.size() - 1) ans.push_back('/');
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 3156
#include <stdio.h>

#define N 10000

int main(){

  int n,flag=0,count=0;
  int i,j;
  int a[N];
  int if23=0;
  
  scanf("%d",&n);
  for( i = 0 ; i < n ; i++){
    scanf("%d",&a[i]);
  }

  for(i = 0 ; i < n ; i++){
    for( j = 2 ; j*j <= a[i] ; j++){
      if(a[i]%j == 0){
	flag = 1;
	break;
      }
    }
    if( flag != 1) count++;
    else flag = 0 ;
  }
  printf("%d\n",count);

  return 0;
}
    



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

typedef unsigned long long ULL;
const ULL MOD = 1e9+7;
ULL ans[64][2][2][2][2];

bitset<64> L, R;

ULL dfs(int pos, bool xDown, bool xUp, bool yUp, bool lead) {
	if (pos < 0) return 1;
	ULL &res = ans[pos][xDown][xUp][yUp][lead];
	if (res != 0) return res;

	const int xLow = xDown ? L[pos] : 0;
	const int xHigh = xUp ? R[pos] : 1;
	const int yHigh = yUp ? R[pos] : 1;

	for (int i=xLow; i<=xHigh; ++i) {
		for (int j=i; j<=yHigh; ++j) {
			if (lead && i!=j) continue;
			res += dfs(pos-1, xDown&&i==xLow, xUp&&i==xHigh, yUp&&j==yHigh, lead&&i==0);
		}
	}
	return (res %= MOD);
}

int main() {
	ULL L1, R1;
	cin >> L1 >> R1;
	L = bitset<64>(L1);
	R = bitset<64>(R1);

	int st = 63;
	while (R[st] == 0) --st;
	ULL ans = dfs(st, true, true, true, true);
	printf("%llu\n", ans);

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <set>

using namespace std;


using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();


int main() {
  ULL x;
  cin >> x;
  ULL n = x % 11;
  ULL add = 0;
  if (n != 0) {
    if (n <= 6) {
      add = 1;
    }
    else {
      add = 2;
    }
  }
  cout << x / 11 * 2 + add << endl;
  return 0;
}

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

int main() {
    ll x, k, d;
    cin>>x>>k>>d;
    x=abs(x);
    if (x/d>k)
        cout<<x-d*k<<endl;
    else if ((x/d+k)%2==0)
        cout<<x%d<<endl;
    else
        cout<<d-x%d<<endl;
    return 0;
}

Measured memory_bytes: 3604
n,*a=$<.map &:to_i
a.sort!
p [0,1].map{|x|b=(0...n).map{|i|a[x==i%2?i/2:n-i/2-1]}
eval (0...n).map{|i|(b[i-1]-b[i]).abs}.max(n-1)*?+}.max

Measured memory_bytes: 123344
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, K;

    cin >> N >> K;

    int ans = K;
    for (int i = 2; i <= N; i++) {
        ans *= K - 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,i,j,f[100][10],p[100][11],a[100]={0},l,k,max=-2000000000,s=0;
cin>>n;
for(i=0;i<n;i++){
for(j=0;j<10;j++){
cin>>f[i][j];
}}
for(i=0;i<n;i++){
for(j=0;j<=10;j++){
cin>>p[i][j];
}}
for(k=1;k<1024;k++){
j=k;
for(i=0;i<10;i++){
if(j%2==1){for(l=0;l<n;l++){if(f[l][i]==1)a[l]++;}}
j=j>>1;
}
for(i=0;i<n;i++){s+=p[i][a[i]];a[i]=0;}
if(s>max)max=s;
s=0;
}
cout<<max<<endl;
return 0;



}


Measured memory_bytes: 256
// "for if god is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
void solve() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int tot = (h2 - h1) * 60 + (m2 - m1);
	cout << tot - k;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input2.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;

namespace G___Longest_Path
{
    class Program
    {
        static List<int>[] connection;
        static int[] DP;
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0];
            var M = NM[1];

            connection = new List<int>[N + 1];
            for (int i = 1; i < N + 1; i++) connection[i] = new List<int>();

            DP = new int[N + 1];
            for (int i = 0; i < N + 1; i++) DP[i] = -1;

            for (int i = 0; i < M; i++)
            {
                var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                connection[xy[0]].Add(xy[1]);
            }

            int result = 0;
            for (int i = 1; i < N + 1; i++) result = Math.Max(result, search(i));

            Console.WriteLine(result);
        }

        static int search(int currentNode)
        {
            if (DP[currentNode] != -1) return DP[currentNode];

            int result = 0;
            foreach (int nextNode in connection[currentNode])
                result = Math.Max(result, search(nextNode) + 1);

            return DP[currentNode] = result;
        }
    }
}


Measured memory_bytes: 33412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000

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

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

using namespace std;

using ll = long long;

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

    vector<int> deg(4);
    for (int i = 0; i < 3; ++i) {
        int a, b;
        cin >> a >> b;
        ++deg[a - 1];
        ++deg[b - 1];
    }
    sort(deg.begin(), deg.end());
    if (deg[0] == 1 && deg[1] == 1 && deg[2] == 2 && deg[3] == 2)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


Measured memory_bytes: 384
using System;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string[] ss = s.Split(' ');
        
        int w = int.Parse(ss[0]);
        int h = int.Parse(ss[1]);
        int x = int.Parse(ss[2]);
        int y = int.Parse(ss[3]);
        int r = int.Parse(ss[4]);
        
        if(x + r <= w && x - r >= 0 && y + r <= h && y - r >= 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}


Measured memory_bytes: 17996
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int X, N;
  cin >> X >> N;
  vi p(N);
  cin >> p;
  vector<bool> valid(111, true);
  rep(i, 0, N) { valid[p[i]] = false; }
  int ans = INF;
  int mn = INF;
  rep(i, 0, 110) {
    if (!valid[i]) continue;
    if (chmin(mn, abs(X - i))) {
      ans = i;
    }
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
  int n;
  int a = 0;

  scanf("%d",&n);

  int p[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < n; i++) {
    if (p[i] != i+1)
      a++;
  }
  if (a <= 2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 1636
//Name-Deepesh Bhatt
//Institute-IIT Dhanbad

#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define MOD 1E9+7
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}

int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    int r;
    cin>>r;
    float c;
    c=2*3.1415926535*r;
    cout<<setprecision(10)<<c;
    return 0;
}

Measured memory_bytes: 3800
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeMaximum(Node x){
 while(x->right!=NIL)x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL){
    x=y->left;
  }
  else x=y->right;

  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL)root=x;
  else{
    if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z)z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else{
    if(z->key<y->key)y->left=z;
    else y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9


const int NMax = 1005;
const int VMax = NMax * (NMax-1)/2;


vector<int> to[VMax];
int gameID[NMax][NMax];

int dist[VMax];
bool seen[VMax];
bool finished[VMax];

int getGID(int x, int y){
    if(x > y) swap(x, y);
    return gameID[x][y];
}


int dfs(int _v){
    if(finished[_v]){
        return dist[_v];
    }

    if(seen[_v] && !finished[_v]) return -1;

    seen[_v] = true;
    dist[_v] = 1;

    for(int k : to[_v]){
        int result = dfs(k);
        if(result == -1) return -1;
        dist[_v] = max(dist[_v], dist[k]+1);
    }
    finished[_v] = true;

    return dist[_v];
}



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;

    // A[i][j] i番目の人のj番目の試合の相手が入ってる
    vector<vector<int>> A(N, vector<int> (N-1));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-1; j++){
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    // game ID をつける
    int v = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-1; j++){
            int y = A[i][j];
            if(i < y){
                gameID[i][y] = v;
                v++;
            }
        }
    }

    //game ID のリストに置き換える
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-1; j++){
            A[i][j] = getGID(i, A[i][j]);
        }
    }

    // パスを貼る  
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-2; j++){
            to[A[i][j]].push_back(A[i][j+1]);
        }
    }

    // 最長パスを求める
    int ans = 0;
    for(int i = 0; i < v; i++){
        int len = dfs(i);
        if(len == -1){
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, len);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 38656
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))[::-1]

if N == 2:
    print(abs(A[0]-A[1]))
    exit()

S = sum(A) - A[0]

ret = 10**9
arai = A[0]
for i in range(1, N):
    ret = min(abs(S-arai), ret)
    S -= A[i]
    arai += A[i]

print(ret)


Measured memory_bytes: 30804
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 1e18
#define MOD 1000000007
#define PI 4*atan(1.0)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=1005;
//int arr[SIZE]={};
//ここまでテンプレ
typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
 
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
int main(){
	cout<<setprecision(20);
	int sx,sy,gx,gy;
	cin>>sx>>sy>>gx>>gy;
	int N;
	cin>>N;
	int x[SIZE]={},y[SIZE]={},r[SIZE]={};
	for(int i=0;i<N;i++){
		scanf("%d%d%d",&x[i],&y[i],&r[i]);
	}
	x[N]=sx,y[N]=sy,r[N]=0;
	x[N+1]=gx,y[N+1]=gy,r[N+1]=0;
	Graph G;
	for(int i=0;i<N+2;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<N+2;i++)for(int j=0;j<N+2;j++){
		double cost=max(0.0,sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-(double)(r[i]+r[j]));
		G[i].push_back(Edge(i,j,cost));
	}
	vector<Weight> dis;
	vector<int> prev;
 
	shortestPath(G,N,dis,prev);
	cout<<dis[N+1]<<endl;
	return 0;
}

Measured memory_bytes: 22268
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long X = sc.nextLong();
		long[] five = new long[1001];
		long A = 0;
		for( int i=1; i<=1000; i++ ){
			A++;
			five[i] = A*A*A*A*A;
		}
		loop:for( int i=0; i<=1000; i++ ){
			for( int k=0; k<=1000; k++ ){
				if( five[i]-five[k]==X ){
					System.out.println(i+" "+k);
					break loop;
				}
				if( five[i]+five[k]==X ){
					System.out.println(i+" "+(-k));
					break loop;
				}			
			}
		}
	}
}

Measured memory_bytes: 38784
#include <stdio.h>

int n,m,a[100];
int p[100];
int i,j,fa;

int main(void){
	scanf("%d%d",&n,&m);
	for(i = 0;i < m;i++)scanf("%d",a+i);
	for(i = 0;i < m;i++)
		for(j = 0;j < n;j++){
			scanf("%d",&fa);
			if(fa == a[i])
				p[j]++;
			else
				p[a[i] - 1]++;
		}
	for(i = 0;i < n;i++)printf("%d\n",p[i]);
		return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x >= y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x <= y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << '\n';
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  sort(ALL(A));
  if (A[0] >= 0) {
    int now = A[0];
    vector<pair<int, int>> ans;
    FOR(i, 1, N-1) {
      ans.push_back(make_pair(now, A[i]));
      now -= A[i];
    }
    ans.push_back(make_pair(A[N-1], now));
    cout << A[N-1] - now << endl;
    for (pair<int, int> p : ans) {
      int x, y; tie(x, y) = p;
      cout << x << ' ' << y << endl;
    }
  } else if (A[N-1] <= 0) {
    int now = A[N-1];
    vector<pair<int, int>> ans;
    REP(i, N-1) {
      ans.push_back(make_pair(now, A[i]));
      now -= A[i];
    }
    cout << now << endl;
    for (pair<int, int> p : ans) {
      int x, y; tie(x, y) = p;
      cout << x << ' ' << y << endl;
    }
  } else {
    vector<int> pos, neg, zero;
    for (int x : A) {
      if (x > 0) {
        pos.emplace_back(x);
      } else if (x < 0) {
        neg.emplace_back(x);
      } else {
        zero.emplace_back(x);
      }
    }

    vector<pair<int, int>> ans;
    int pos_now = pos[0], neg_now = neg[0];
    if (pos.size() > 1) {
      FOR(i, 1, pos.size()) {
        ans.push_back(make_pair(neg_now, pos[i]));
        neg_now -= pos[i];
      }
    }
    if (neg.size() > 1) {
      FOR(i, 1, neg.size()) {
        ans.push_back(make_pair(pos_now, neg[i]));
        pos_now -= neg[i];
      }
    }

    REP(i, zero.size()) ans.push_back(make_pair(pos_now, 0));
    ans.push_back(make_pair(pos_now, neg_now));
    cout << pos_now - neg_now << endl;

    for (pair<int, int> p : ans) {
      int x, y; tie(x, y) = p;
      cout << x << ' ' << y << endl;
    }

  }


  return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int> v(n+1);
	

	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}

	vector<int> a(100005), b(100005);
	fill(a.begin(), a.end(), 0);
	fill(b.begin(), b.end(), 0);

	for (int i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			a[v[i]]++;
		}
		else {
			b[v[i]]++;
		}
	}

	int maxA = 0;
	int indexA = 0;
	int maxB = 0;
	int indexB = 0;

	for (int i = 1; i < 100005; i++) {
		if (a[i] > maxA) {
			maxA = a[i];
			indexA = i;
		}
		if (b[i] > maxB) {
			maxB = b[i];
			indexB = i;
		}
	}

	if (indexA != indexB) {
		cout << (n / 2 - maxA) + (n / 2 - maxB) << endl;
	}
	else {
		sort(a.begin(), a.end(), greater<int>());
		sort(b.begin(), b.end(), greater<int>());
		cout << min((n / 2 - a[0]) + (n / 2 - b[1]), (n / 2 - a[1]) + (n / 2 - a[0]));
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep (i, n) {
    cin >> a[i];
  }
  rep (i, m) {
    cin >> b[i];
  }
  rep (i, n+1-m) {
    rep (j, n+1-m) {
      bool flag = true;
      rep (k, m) {
        rep (l, m) {
          if (a[i+k][j+l] != b[k][l]) {
            flag = false;
            k = m;
            break;
          }
        }
      }
      if (flag) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");

  return 0;
}


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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
  int n, m;
  cin >> n >> m;
  ll a[n];
  REP(i, n) cin >> a[i];
  ll b[n+1] = { };
  REP(i, n) b[i+1] = (b[i] + a[i])%m;
  map<ll, ll> f;
  REP(i, n+1) f[b[i]]++;
  ll ans = 0;
  for(map<ll, ll>::iterator i = f.begin(); i != f.end(); i++){
    ans += (i->second)*(i->second - 1)/2;
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
    int x=0,ans=0,b;
    string a;
    cin >> b >> a;
    for(int i =0;i < b;i++){
        if(a[i] =='I')
            x++;
        else   
            x--;
        if(x>ans)
            ans = x;
    }
    cout  << ans << endl;
}


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

int main(){
    int n;
    cin>>n;
    vector<vector<long long>> a(n,vector<long long>(2));
    for(int i=0;i<n;i++){
        cin>>a[i][1];
        cin>>a[i][0];
    }
    sort(a.begin(),a.end());
    bool p=true;
    long long cur=0;
    for(int i=0;i<n;i++){
        cur+=a[i][1];
        if(cur>a[i][0]){
            p=false;
        }
    }
    if(p){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int main() {
    string s;
    cin >> s;
    map<char, int> cnt;
    for (char c : s) cnt[c]++;
    if (cnt.size() == 1) {
        if (s.size() == 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
        return 0;
    } else if (cnt.size() == 2) {
        if (s.size() < 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
        return 0;
    } else {
        if (max({cnt['a'], cnt['b'], cnt['c']}) - min({cnt['a'], cnt['b'], cnt['c']}) <= 1) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 512