akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [[0]*N] * 2
A[0] = list(map(int,input().split()))
A[1] = list(map(int,input().split()))
point = N
point_diff = 0
for i in range(0,N):
    last_0 = 0
    last_1 = 0
    for j in range(i,N):
        if(j != i):
            last_0 += A[0][j]
        last_1 += A[1][j]
    if last_0 <= last_1 and last_1 - last_0 > point_diff:
        point = i
        point_diff = last_1 - last_0
        
        
ans = 0
for i in range(0,N):
    if i <= point:
        ans += A[0][i]
    if i >= point:
        ans += A[1][i]
print(ans)

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

const int MOD=1000000007;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
			inv[i]=ppow(fact[i],MOD-2);
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
vector<int>v[200000];
int main(){
	Fact fact(200000);
	int n,x,y;scanf("%d%d%d",&n,&x,&y);
	set<int>se;
	rep(i,n){
		int c,w;scanf("%d%d",&c,&w);c--;
		v[c].push_back(w);
		se.insert(c);
	}
	if(se.size()==1){
		puts("1");return 0;
	}
	set<P>S;
	rep(i,n){
		if(v[i].empty())continue;
		sort(v[i].begin(),v[i].end());
		S.insert(P(v[i][0],i));
	}
	vector<P>vs;
	rep(i,n){
		if(v[i].empty())continue;
		while(v[i].size()>1&&v[i].front()+v[i].back()>x
		&&v[i].back()+(S.begin()->second==i?(++S.begin())->first:S.begin()->first)>y){
			v[i].pop_back();
		}
		vs.push_back(P(v[i][0],v[i].size()));
	}
	sort(vs.begin(),vs.end());
	while(vs.size()>1&&vs.front().first+vs.back().first>y)vs.pop_back();
	int cnt=0;
	for(auto p:vs)cnt+=p.second;
	ll ans=fact.get(cnt);
	for(auto p:vs)(ans*=fact.get_inv(p.second))%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 30840
import copy
import queue
def bfs(count, x, y, cheese):
    q = queue.Queue()
    q.put((count,x,y))
    tempVisited = copy.deepcopy(visited)
    tempVisited[x][y] = True
    
    while q.qsize()>0:
        tempc,tempx,tempy = q.get(0)
        if geo[tempx][tempy] == cheese:
            return tempc,tempx,tempy
        for i in range(4):
            neox = tempx+dx[i]
            neoy = tempy+dy[i]
            if canGoTo(neox,neoy, tempVisited):
                #if (tempc+1,neox,neoy) not in q:
                q.put((tempc+1,neox,neoy))
                tempVisited[neox][neoy]=True
    return (-1,-1,-1)

def canGoTo(x,y,tempVisited):
    if 0<=x<H and 0<=y<W:
        return not tempVisited[x][y]
    return False

dx = [0,1,0,-1]
dy = [-1,0,1,0]

data = input().split(' ')
H,W,N = map(int, data)

#maps
geo = [[None for i in range(W)] for j in range(H)]
visited = [[False for i in range(W)] for j in range(H)]

x,y=-1,-1
for i in range(H):
    line = input()
    for j in range(W):
        p = line[j:j+1]
        geo[i][j] = p
        if p == 'X':
            visited[i][j] = True
        elif p == 'S':
            x,y, = i,j
            
count = 0
for n in range(1,N+1):
    count,x,y = bfs(count,x,y,str(n))
print(count)

Measured memory_bytes: 35256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>

typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main() {
  char s[100001];
  cin >> s;
  int len = strlen(s);

  int dp[len + 1][13];
  fill(dp[0], dp[len + 1], 0);
  dp[0][0] = 1;
  int rems[6] = { 1, 10, 9, 12, 3, 4 };
  for(int i = 0; i < len; i++) {
    char c = s[i];
    int dig = len - 1 - i;
    int rem = rems[dig % 6];
    if(c >= '0' && c <= '9') {
      int num = (int) (c - '0');
      for(int j = 0; j < 13; j++) {
        int prevj = (j + 13 - (num * rem) % 13) % 13;
        dp[i + 1][j] += dp[i][prevj] % MOD;
      }
    }
    if(c == '?') {
      for(int num = 0; num <= 9; num++) {
        for(int j = 0; j < 13; j++) {
          int prevj = (j + 13 - (num * rem) % 13) % 13;
          dp[i + 1][j] += dp[i][prevj];
          dp[i + 1][j] = dp[i + 1][j] % MOD;
        }
      }
    }
  }
  cout << dp[len][5] << "\n";

  return 0;
}



Measured memory_bytes: 5376
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const int MAX = 1e5+5;



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

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


	queue<pii> q;
	int m = a[0];
	int p = a[n - 1];
	for (int i = 1; i < n-1; i++) {
		if (a[i] < 0) {
			q.push(make_pair(p, a[i]));
			p -= a[i];
		}
		else {
			q.push(make_pair(m, a[i]));
			m -= a[i];
		}
	}
	q.push(make_pair(p, m));
	cout << p - m << endl;
	while (!q.empty()) {
		cout << q.front().first << " " << q.front().second << endl;
		q.pop();
	}
}

Measured memory_bytes: 4556
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100007],b[100007],h[100007],i,j,k,l,m=0,N,M;
    cin>>N>>M;
    l=N;
    for(i=1; i<=M; i++)
        h[i]=0;
    while(l--)
    {
        cin>>k;
        for(i=0; i<k; i++)
            cin>>a[i];
        for(i=0; i<k; i++)
            h[a[i]]++;
    }
    if(N==1)
        cout<<k<<endl;
    else
    {
        for(i=1; i<=M; i++)
        {
            //cout<<h[i]<<endl;
            if(h[i]==N)
            {
                m++;
                //cout<<h[i]<<endl;
            }
        }
        cout<<m<<endl;
    }
    return 0;

}


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

vector<int> a;
int dp[100010];


int moves(int index,int n,int k){
    if(index >= n-1 )
    {
        return 0;
    }
    
    if(dp[index]!=-1){
        return dp[index];
    }

    for(int i = 1;i<=k;i++){
        int a1 = 1e9;
        if(index + i < n){
            a1 = abs(a[index] - a[index+i]) + moves(index + i,n,k);
        }   
        if(dp[index]!=-1){
            dp[index] = min(dp[index],a1);
        }
        else{
            dp[index] = a1;
        }
    }

    return dp[index];

    // int a1 = 1e9;
    // int b = 1e9;
    // if(index+1 < n){
    //     a1 = abs(a[index]-a[index+1]) + moves(index + 1,n);
    // }
    // if(index + 2 < n ){
    //     b = abs(a[index]-a[index + 2]) + moves(index + 2,n);
    // }
    // return dp[index] = min(a1,b);

}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    int k;
    cin>>k;
    a.resize(n);
    memset(dp,-1,sizeof dp);

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

    cout<<moves(0,n,k)<<endl;

    return 0;
}

Measured memory_bytes: 11872
import Data.List
main=do
 n<-getLine
 an<-map read.words<$>getLine
 let a = map (`div`400) an
     s = length$group.sort$filter(<8)a
 putStrLn$if s==0 then "1"++" "++n else show s++" "++show (s+length(filter(>=8)a))
     
 

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using D = double;
using ld = long double;
using ii = pair<int, int>;
using vi = vector <int>;
using vii = vector <ii>;

#define pb push_back
#define re return 
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define re return
#define sz(x) ((int) x.size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rei(i, n) for (int i = 0; i < (n); i++) 

const int inf = 2e9;

ll binpow (ll x, ll y) {
 	if (y == 0) re 1;
 	else if (y % 2 != 0) re x*binpow(x, y - 1);
 	else {
 		ll ans = binpow(x, y/2);
 		re ans*ans;
   }
}

int main() {
 	ios::sync_with_stdio(0);
 	cin.tie(NULL);
 	cout.tie(NULL);
	ll n, m;
	cin >> n >> m;
	vector <pair<ll, ll>> a;
	vector <ll> b;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		b.pb(x);
		while (x) {
		 	a.pb(mp(x, i));
		 	x /= 2;
		}
	}
	sort(rall(a));
	map <ll, ll> rm;
	for (int i = 0; i < min(m, (ll) sz(a)); i++) {
		rm[a[i].se]++;		 	
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
	 	ans += b[i]/binpow(2, rm[i]); 
	 	//cout << ans << " ";
	}
	cout << ans;
 	re 0;
}


Measured memory_bytes: 68832
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n;
     cin>>n;
     vi v(n);
     in(v,n);
     int res=0;
     for(int i=0;i<n;i++)
     {
     	  for(int j=i+1;j<n;j++)
     	  	res+=v[i]*v[j];
     }
     cout<<res<<endl;
     time();
     return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 4100
#define NN 201000
typedef long long ll;
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
}
using namespace std;
const int up = 4010;
const int base = 2001;
const int P = 1e9 + 7;
const int inv2 = 5e8 + 4;
inline ll quickpow(ll x, int k) {
  ll res = 1;
  while (k) {
    if (k & 1)  res = res * x % P;
    x = x * x % P;
    k >>= 1;
  }
  return res;
}
int n;
int a[NN], b[NN];
int f[N][N];
int ed[N][N];
ll jie[NN], jieni[NN];
inline void init() {
  jie[0] = jieni[0] = 1;
  for (int i = 1; i <= 10000; ++i)  jie[i] = jie[i - 1] * i % P;
  jieni[10000] = quickpow(jie[10000], P - 2);
  for (int i = 9999; i; --i)  jieni[i] = jieni[i + 1] * (i + 1) % P;
}
inline ll get_c(int n, int m) {
  if (n < 0 || m < 0 || n - m < 0)  return 0;
  return jie[n] * jieni[m] % P * jieni[n - m] % P;
}

inline void work() {
  ll ans = 0;
  for (int i = 1; i <= up; ++i) {
    for (int j = 1; j <= up; ++j) {
      f[i][j] = (1ll * f[i][j] + f[i - 1][j] + f[i][j - 1]) % P;
      if (ed[i][j]) ans = (ans + 1ll * ed[i][j] * f[i][j]) % P;
    }
  }
  for (int i = 1; i <= n; ++i) {
    ans = (ans - get_c((a[i] + b[i]) << 1, a[i] << 1) + P) % P;
  }
  ans = ans * inv2 % P;
  printf("%lld\n", (ans % P + P) % P);
}

int main() {
  read(n);
  for (int i = 1; i <= n; ++i)  read(a[i]), read(b[i]), ++f[base - a[i]][base - b[i]], ed[base + a[i]][base + b[i]]++;
  init();
  work();
  return 0;
}


Measured memory_bytes: 92372
#include<cstdio>
int N,T,A,X;
int main(){
  scanf("%d%d%d",&N,&T,&A);
  int res=0;
  int cc=1<<30;
  for(int i=1;i<=N;i++){
    scanf("%d",&X);
    int d=(T*1000-X*6)-A*1000;
    if(d<0) d=-d;
    if(cc>d) cc=d,res=i;
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int r;
    cin >> r;
    cout << 3* r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    int n,k; cin>>n>>k;
    ll a[n]; forn(i,n) cin>>a[i];
    sort(a,a+n);
    ll sm = 0;
    forn(i,k) sm += a[i];
    cout<<sm;
    
	return 0;
}


Measured memory_bytes: 3652
N=int(input())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(d) for d in b]

sum_A=sum(A)
sum_B=sum(B)

sa=[]
for n in range(N):
    number=A[n]-B[n]
    sa.append(number)
new_sa=sorted(sa)
plus=[]
minus=[]
for n in new_sa:
    if n>=0:
        plus.append(n)
    else:
        minus.append(n)

saishou=abs(sum(minus))
new_plus=sorted(plus,reverse=True)
answer=len(minus)
n_plus=[]
n_plus.append(new_plus[0])
del new_plus[0]
for plu in new_plus:
    n_plus.append(n_plus[-1]+plu)

if sum_A<sum_B:
    print(-1)
else:
    if answer==0:
        print(answer)
    else:
        number=1
        for suuji in n_plus:
            if suuji>=saishou:
                print(answer+number)
                break
            else:
                number+=1
                

Measured memory_bytes: 109840
def main():
    n=int(input())
    ab=[list(map(int,input().split())) for _ in [0]*(n-1)]
    c=sorted(list(map(int,input().split())),reverse=True)
    g=[set() for _ in [0]*n]
    [g[a-1].add(b-1) for a,b in ab]
    [g[b-1].add(a-1) for a,b in ab]
    l=[]
    print(sum(c)-max(c))
    for i in range(n):
        if len(g[i])==1:
            l.append(i)
    ans_l=[0]*n
    while l:
        i=l.pop()
        ans_l[i]=c.pop()
        for j in g[i]:
            g[j].remove(i)
            if len(g[j])==1:
                l.append(j)
        g[i]=set()
    print(*ans_l)
main()

Measured memory_bytes: 9216
#include <iostream>

using namespace std;

int main() {
	int sx, sy, tx, ty;
	int a, b;

	cin >> sx >> sy >> tx >> ty;

	a = tx - sx;
	b = ty - sy;


	
	//1
	for (int i = 0; i<a; i++) {
		cout << "R";
	}

	//2
	for (int i = 0; i<b; i++) {
		cout << "U";
	}

	//3
	for (int i = 0; i<a; i++) {
		cout << "L";
	}

	//4
	for (int i = 0; i<b; i++) {
		cout << "D";
	}

	//5
	cout << "D";

	//6
	for (int i = 0; i<a; i++) {
		cout << "R";
	}
	cout << "R";

	//7
	for (int i = 0; i<b; i++) {
		cout << "U";
	}
	cout << "U";

	//8
	cout << "L";
	
	//9
	cout << "U";

	//10
	for (int i = 0; i<a; i++) {
		cout << "L";
	}
	cout << "L";

	//11
	for (int i = 0; i<b; i++) {
		cout << "D";
	}
	cout << "D";

	//12
	cout << "R";

	cout << endl;

	return 0;

}

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

struct Point {
  int x;
  int y;
};

const char WALL = '#';
const char ROAD = '.';

const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, -1, 0, 1};

int max_dist(vector<vector<char>> maze, Point start) {
  vector<vector<int>> dists(maze.size(), vector<int>(maze.at(0).size(), -1));
  dists.at(start.y).at(start.x) = 0;

  int max_dist = 0;

  queue<Point> q;
  q.push(start);

  while (!q.empty()) {
    Point a = q.front();
    q.pop();
    int ad = dists.at(a.y).at(a.x);

    rep(i, 4) {
      Point p = {a.x + dx.at(i), a.y + dy.at(i)};

      if (maze.at(p.y).at(p.x) == ROAD) {
        int pd = dists.at(p.y).at(p.x);
        if (pd < 0 || pd > ad + 1) {
          dists.at(p.y).at(p.x) = ad + 1;
          max_dist = max(max_dist, ad + 1);
          q.push(p);
        }
      }
    }
  }
#ifdef DEBUG
  rep(i, maze.size()) {
    rep(j, maze.at(0).size()) { cout << setw(2) << dists.at(i).at(j) << " "; }
    cout << endl;
  }
  cout << "---" << endl;
#endif
  return max_dist;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H + 2, vector<char>(W + 2, WALL));

  rep1(y, H) {
    string s;
    cin >> s;
    rep1(x, W) maze.at(y).at(x) = s.at(x - 1);
  }

  int ans = 0;

  rep1(i, H) {
    rep1(j, W) {
      Point p = {j, i};
      if (maze.at(p.y).at(p.x) == WALL) continue;
      int d = max_dist(maze, p);
      ans = max(ans, d);
    }
  }

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


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

#define rep(i,s,t) for(int i = s; i < t; ++i)
#define per(i,s,t) for(int i = s; i > t; --i)

int const N = 200 * 1000 + 16;
int const M = 1000*1000*1000 + 7;

int n;
int a[26];
char w[N];

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> w;
  for(n = 0; w[n]; ++n)
    a[w[n]-'a']++;

  ll ans = 1ll * n * (n+1) / 2 + 1;
  for(int i = 0; i < 26; ++i) {
    ll x = a[i];
    ans -= x*(x-1)/ 2 + x;
  }  
  cout << ans << endl;
}

Measured memory_bytes: 512
import fractions

N,K =list(map(int,input().split(" ")))
As= list(map(int,input().split(" ")))
g = As[0]
ma = -1
for a in As:
    g = fractions.gcd(g,a)
    ma = max(ma,a)
    if K == a:
        print("POSSIBLE")
        exit()
if K % g == 0 and ma >= K:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16240
(N,T)=map(int,input().split())
a=list(map(int,input().split()))
x=10**9
d=0
counter=0
for i in a:
    if i<x:
        x=i
    elif i-x>d:
        d=i-x
        counter=1
    elif i-x==d:
        counter+=1
print(counter)

Measured memory_bytes: 14252
import numpy as np
n = int(input())
A = [int(i) for i in input().split()]

def j(B,sign):
    ans,cur = 0,[0]
    for i in range(n):
        cur.append(cur[i]+B[i])
        cs = np.sign(cur[i+1])
        if cs != sign:
            if sign == -1:
                ans += -(-cur[i]-1)+B[i]
                cur[i+1] = -1
            else:
                ans += -cur[i]+1-B[i]
                cur[i+1] = 1
        sign *= -1
    return ans

print(min(j(A,1),j(A,-1)))


Measured memory_bytes: 23268
# coding: utf-8
# Your code here!

#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""


H1,M1,H2,M2,K = map(int,input().split())

time = (H2*60)+M2- (H1*60)-M1

if time <= K:
    print("0")

else:
    print(time-K)






Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cnt=0,ans=0;
  for(int i=0; i<n; i++){
    char c;
    cin>>c;
    if(c=='x')cnt++;
    else cnt=0;
    if(cnt==2)break;
    ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, k;
    cin >> n >> k;
    vector<ll> v(n), rv(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        rv[n - 1 - i] = v[i];
    }
    ll ret = -1e15;
    for (int l = 0; l <= min(n, k); l++)
    {
        for (int r = 0; r <= min(n, k) - l; r++)
        {
            int undo = k - (l + r);
            priority_queue<ll, vector<ll>, greater<ll>> que;
            for (int i = 0; i < l; i++)
                que.push(v[i]);
            for (int i = 0; i < r; i++)
                que.push(rv[i]);
            for (int i = 0; i < undo; i++)
            {
                if (!que.empty() && que.top() <= 0)
                    que.pop();
            }
            ll sum = 0;
            while (!que.empty())
            {
                sum += que.top();
                que.pop();
            }
            ret = max(ret, sum);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,ans=0;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  uint32_t a=A[0];
  int b=A[0];
  for(int l=0,r=0;l<N;){
    for(r++;r<N;r++){
      a^=A[r];
      b+=A[r];
      if(a!=b){
        a^=A[r];
        b-=A[r];
        break;
      }
    }
    ans+=r-l;
    r--;
    a^=A[l];
    b-=A[l];
    if(r<=l)l++,r=l,a^=A[l],b+=A[l];
    else l++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    int d, n;
    cin >> d >> n;
    int t = 1;
    t = pow(100, d);
    if(n==100) cout << t*(n+1) << endl;
    else cout << t*n << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
using namespace std;

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

const long long INF = 1LL << 60;
const int dp_max = 3100;

// 入力
string s, t;

// DPテーブル
string ans = "";
long long dp[dp_max][dp_max] = {0};

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

  size_t s_size = s.length();
  size_t t_size = t.length();

  // DPループ
  for (int i = 0; i < s_size; i++) {
    for(int j = 0; j < t_size; j++){
      if(s[i] == t[j]){
        chmax(dp[i+1][j+1], dp[i][j] + 1);
      }
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }

  int i = (int)s_size;
  int j = (int)t_size;
  while(i > 0 && j > 0){
    if (dp[i][j] == dp[i-1][j]) {
        --i;
    }

    else if (dp[i][j] == dp[i][j-1]) {
        --j;
    }

    else {
        ans = s[i-1] + ans;
        --i, --j;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,a[200001],max1,max2,p;
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	cin>>a[1]>>a[2];
	if(a[1]>a[2]){
		max1=a[1];
		max2=a[2];
		p=1;
	}
	else{
		max1=a[2];
		max2=a[1];
		p=2;
	}
	for(int i=3;i<=n;i++){
		cin>>a[i];
		if(a[i]>max1){
			max2=max1;
			max1=a[i];
			p=i;
		}
		else if(a[i]>max2){
			max2=a[i];
		}
	}
	rep(i,n){
		if(i==p){
			cout<<max2<<endl;
		}
		else{
			cout<<max1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
using System.Linq;
using System;

public class Hello {
    public static void Main() {
        // 自分の得意な言語で
        // Let's チャレンジ！！
        var n = int.Parse (System.Console.ReadLine ());
        var chars = System.Console.ReadLine ().Split(' ');
        var numP = chars.Any (x => x == "P");
        var numW = chars.Any (x => x == "W");
        var numG = chars.Any (x => x == "G");
        var numY = chars.Any (x => x == "Y");
        if (!(numP && numW && numG && numY)) {
            Console.WriteLine ("Three");
        } else {
            Console.WriteLine ("Four");
        }
    }
}

Measured memory_bytes: 13268
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let k: usize = read(&mut stdin_lock, &mut buf, b'\n');

    let mut rv = vec![0i64; k];
    for x in 1..n + 1 {
        rv[x % k] += 1;
    }

    let mut ans = 0i64;
    for a in 0..k {
        let bc = (k - a) % k;
        if (bc + bc) % k == 0 {
            ans += rv[a] * rv[bc] * rv[bc];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  string s;
  cin >> s;
  int n;
  cin >> n;
  int answerl=s[0]-'0';
  REP(i,s.size()/2)
    if(s[i*2+1]=='+') answerl+=(s[i*2+2]-'0');
    else answerl*=(s[i*2+2]-'0');
  int answerm=0;
  vector<int> adds;
  adds.push_back(s[0]-'0');
  REP(i,s.size()/2)
    if(s[i*2+1]=='+') adds.push_back(s[i*2+2]-'0');
    else adds[adds.size()-1]*=(s[i*2+2]-'0');
  REP(i,adds.size()) answerm+=adds[i];
  string ans="IMLU";
  int ansnum=0;
  if(n==answerm) ansnum+=1;
  if(n==answerl) ansnum+=2;
  cout << ans[ansnum] << endl;
  return 0;
}

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


int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    vector<ll> H(N);
    rep(i, N){
        cin >> H[i];
    }

    sort(H.begin(), H.end(), greater<ll>());
    for(int i = K; i < N; i++){
        ans += H[i];
    }
    cout << ans << endl;

}

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

int main() {

	int m[10];
	for (int i = 0; i < 10; i++)
	{
		cin >> m[i];
	}
	sort(m, m + 10);
	cout << m[9] << endl;
	cout << m[8] << endl;
	cout << m[7] << endl;
	return 0;
}

Measured memory_bytes: 1176
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int r=in.nextInt();
    int l=in.nextInt();
    int d=in.nextInt();
    int c=0;
   for(int i=r;i<=l;i++)
   {
	   if(i%d==0)
	   {
		   c++;
	   }
   }
   System.out.println(c);
  }
}

Measured memory_bytes: 35468
#include<iostream>
#include<vector>

struct tree{
	int dst;
	int cost;
};

std::vector<std::vector<tree>> tList;
std::vector<long long> costList;
std::vector<bool> isVisited;

void dfs(int cur, long long cost);

int main(){
	int n, q, k;
	std::vector<int> xList;
	std::vector<int> yList;

	std::cin>>n;

	tList.resize(n);
	costList.resize(n, 0);
	isVisited.resize(n, false);

	for(int i=0; i<n-1; i++){
		int tmp1, tmp2, tmp3;
		std::cin>>tmp1>>tmp2>>tmp3;

		tList[tmp1-1].push_back({tmp2-1, tmp3});
		tList[tmp2-1].push_back({tmp1-1, tmp3});
	}

	std::cin>>q>>k;

	xList.resize(q);
	yList.resize(q);

	for(int i=0; i<q; i++)
		std::cin>>xList[i]>>yList[i];

	dfs(k-1, 0);

	for(int i=0; i<q; i++)
		std::cout<< costList[xList[i]-1] + costList[yList[i]-1]<<std::endl;

	return 0;
}

void dfs(int cur, long long cost){
	costList[cur]= cost;
	isVisited[cur]= true;

	for(int i=0; i< tList[cur].size(); i++){
		tree next= tList[cur][i];

		if(!isVisited[next.dst])
			dfs(next.dst, cost+ next.cost);
	}

}

Measured memory_bytes: 13568
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int[] h = new int[n];
        for (int i = 0; i < h.Length; i++)
        {
            h[i] = 0;
        }
        for(int i = 0;i<a.Length;i++)
        {
            h[a[i]-1]++;
        }
        foreach (var ans in h)
        {
            Console.WriteLine(ans);
        }
        
    }
}

Measured memory_bytes: 42928
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a[] = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int average = (int) Math.round(Arrays.stream(a).average().getAsDouble());
			System.out.println(Arrays.stream(a).map(i -> (i - average) * (i - average)).sum());
		}
	}
}


Measured memory_bytes: 36772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (s.hasNextInt()) {
			int a = s.nextInt();
			int b = s.nextInt();
			System.out.println(Integer.valueOf(a + b).toString().length());
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(b<c ||d<a) out(0);
    else{
        int start = max(a, c);
        int last = min(b, d);
        out(last-start);
    }
}

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

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a==1 && b==2){
		printf("%d\n",3);
	}
	else if(a==1 && b==3){
		printf("%d\n",2);
	}else if(a==2 && b==1){
		printf("%d\n",3);
	}else if(a==2 && b==3){
		printf("%d\n",1);
	}else if(a==3 && b==1){
		printf("%d\n",2);
	}else if(a==3 && b==2){
		printf("%d\n",1);
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest094 e問題 未完成
Author     : Kitaura Hiromi
LastUpdate : 20180420
Since      : 20180414
"""
inf = 10**20
# 最終的に, 1組以外はすべて0になる
N = int(input())
s = 0
m = inf
for i in range(N):
    a, b = map(int, input().split(" "))
    if a > b:
        if m > b:
            m = b
    s += a
if m == inf:
    print(0)
else:
    print(s - m)

Measured memory_bytes: 3064
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],B[MAXN+5];
bitset<MAXN+5> bi;
vi dske[MAXN+5];
void DFS(ll x,ll su){
	if(bi[x])re ;
	bi[x]=1;
	ll ans=0;
	su+=A[x];
	B[x]=su;
	fuv(i,dske[x]){
		DFS(dske[x][i],su);
	}
}
ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(n,q);
	f1(i,n-1){
		sc2(x,y);
		dske[x].pb(y);
		dske[y].pb(x);
	}
	while(q--){
		sc2(x,y);
		A[x]+=y;
	}
	
	DFS(1,0);
	f1(i,n){
		cout<<B[i]<<" ";
	}
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 48512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {
	ll r, g, b, n,cnt = 0;
	cin >> r >> g >> b >> n;
	for (ll i = 0; i <= n; i++){
		for (ll k = 0; k <= n; k++) {
			if (n - (r * i + g * k) < 0)break;
			if ((n - (r * i + g * k)) % b == 0)cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
def sd()
  q = Hash.new(0)
  p = gets.to_i
  for i in 0..p-1
    a = gets.split(' ')
    if a[0] == 'insert'
      q[a[1]] = 1
    elsif a[0] == 'find'
      if q[a[1]] == 1
        puts 'yes'
      else
        puts 'no'
      end
    end
  end
end

sd()

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

int main(){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  
  if(s == u) a--;
  else b--;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <complex>
#include <stdio.h>
#include <unordered_set>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL MAXN = 100 + 1;
const LL MAXS = 100 + 1;
const LL MAXT = 100 + 1;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	int n, m;
	cin >> n >> m;

	VI a(n);
	FOR(i, 0, n)
		cin >> a[i];

	VI cnt(n + 1, 0);
	FOR(i, 0, n)
		cnt[a[i]]++;

	int ye = 0;
	VI ok(n, 0);
	FOR(i, 1, n + 1)
		RFOR(j, i, max(0, i - cnt[i]))
		ok[j]++;

	FOR(i, 0, n)
		if (!ok[i])
			++ye;
	
	REP(q, m)
	{
		int x, y;
		cin >> x >> y;
		--x;

		if (y != a[x])
		{
			if (y > cnt[y])
			{
				if (ok[y - cnt[y] - 1] == 0)
					--ye;
				ok[y - cnt[y] - 1]++;
			}

			if (a[x] >= cnt[a[x]])
			{
				if (ok[a[x] - cnt[a[x]]] == 1)
					++ye;
				ok[a[x] - cnt[a[x]]]--;
			}

			cnt[a[x]]--;
			cnt[y]++;
			a[x] = y;
		}
		cout << ye << endl;
	}

	return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int h, w, m;
pii d[N];
vector<int> v[N], vv[N], mmm;
int num[N], nnum[N];

int main() {
    scanf("%d%d%d", &h, &w, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &d[i].first, &d[i].second);
        v[d[i].first].push_back(d[i].second);
        vv[d[i].second].push_back(d[i].first);
    }
    int mmax = -1;
    for (int i = 1; i <= h; i++) {
        num[i] = v[i].size();
        if (num[i] > mmax) {
            mmax = num[i];
            mmm.clear();
            mmm.push_back(i);
        }
        if (num[i] == mmax)mmm.push_back(i);
    }
    for (int i = 1; i <= w; i++)nnum[i] = vv[i].size();
    int maxx = -1;
    for (auto x:mmm) {
        sort(v[x].begin(), v[x].end());
    }
    for (int i = 1; i <= w; i++) {
        if (num[mmm[0]] + nnum[i] - 1 >= maxx) {
            for (auto x:mmm) {
                int pos = lower_bound(v[x].begin(), v[x].end(), i) - v[x].begin();
                if (v[x][pos] != i) {
                    maxx = max(maxx, num[x] + nnum[i]);
                    break;
                }
                maxx = max(maxx, num[x] + nnum[i] - 1);
            }
        }
//        for (auto x:mmm) {
//            if (num[x] + nnum[i] - 1 >= maxx) {
//                if (mmp[make_pair(x, i)] == 0) {
//                    maxx = num[x] + nnum[i];
//                    break;
//                } else {
//                    maxx = num[x] + nnum[i] - (mmp[make_pair(x, i)] == 1 ? 1 : 0);
//                }
//            }
//        }
    }
    printf("%d\n", maxx);
    return 0;
}

Measured memory_bytes: 74768
import time
import sys
import io
import re
import math
#start = time.clock()
i = [0]*127
#n = raw_input()
for x in sys.stdin.read().lower():
    i[ord(x)]+=1
for y in range(ord('a'), ord('z')+1):
    print chr(y)+ ' : ' + str(i[y])

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) {
        cout << "error\n";
    } else {
        cout << a + b << "\n";
    }
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3604
import sys

rr = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(sys.stdin.readline())

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)



Measured memory_bytes: 3064
#include<stdio.h>

int max(int b1,int b2);//大きい方を返す関数
int min(int a1,int a2);//小さい方を返す関数

int main(){
  int n;//滞在日数
  int x,y;//入浴券の料金x,プール券の料金y
  int b,p;//使用する入浴券の枚数bと使用するプール券の枚数p
  int i;//カウンタ
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&x,&y,&b,&p);
    printf("%d\n",min(x*b+y*p,(x*max(b,5)+y*max(p,2))*4/5));//関数で大きい方と小さい方を仕分けて、最安値を求める
  }
  return(0);
}


//大きい方を返す関数
int max(int b1,int b2){
  int bigger;//大きい方を格納する変数
  if(b1>b2){
    bigger=b1;
  }else{
    bigger=b2;
  }
  return(bigger);
}

//小さい方を返す関数
int min(int a1,int a2){
  int smaller;//小さい方を格納する変数
  if(a1<a2){
    smaller=a1;
  }else{
    smaller=a2;
  }
  return(smaller);
}



Measured memory_bytes: 2748
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*b, c*d) << endl;

  return 0;
}

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

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

  if (a * b == 15)
    cout << '*' << endl;
  else if (a + b == 15)
    cout << '+' << endl;
  else 
    cout << 'x' << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string a, b, c,d;
	cin >> a; cin >> b; cin >> c;
	d.push_back(a[0]);
	d.push_back(b[0]);
	d.push_back(c[0]);
	cout <<d<<endl;
} 

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

int main() {
  int X,Y,Z;
  cin >> X >> Y >> Z;
  cout << Z  << ' ' << X <<' '<< Y;
  
  
}


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Measured memory_bytes: 256
//                             In The Name Of Allah                                           
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
const int N = 1e5 + 100, OO = 1e9 + 7, K = 1e7 + 4, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int n, cnt, ans;
int a[N], b[N], x[N], y[N];
bool vis[N];
vector <int> Q[N];
map <int, int> d;

void dfs(int x) {
    vis[x] = 1;
    for(auto u : Q[x]) 
    	if(!vis[u]) 
			dfs(u);
}

int32_t main() {
	use_fast;
	cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
		a[n + 1] ^= a[i];
        if(!d[a[i]]) 
			d[a[i]] = ++cnt;
    }
    if(!d[a[n + 1]]) 
		d[a[n + 1]] = ++cnt;
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
		b[n + 1] ^= b[i];
        if(!d[b[i]]) 
			d[b[i]] = ++cnt;
    }
    if(!d[b[n + 1]]) 
		d[b[n + 1]] = ++cnt;
    memcpy(x, a, sizeof x);
	memcpy(y, b, sizeof y);
    sort(x + 1, x + n + 2);
	sort(y + 1, y + n + 2);
    for(int i = 1; i <= n; i++) 
    	if(x[i] != y[i]) 
			return cout << -1, 0;
    for(int i = 1; i <= n + 1; i++) 
    	a[i] = d[a[i]], b[i] = d[b[i]];
    for(int i = 1; i <= n; i++) 
    	if(a[i] != b[i]) 
			ans++, Q[a[i]].pb(b[i]);
    if(a[n + 1] != b[n + 1]) 
		Q[a[n + 1]].pb(b[n + 1]);
    for(int i = 1; i < cnt; i++) 
    	if((int)Q[i].size() && !vis[i]) 
			dfs(i), ans++;
    if(!vis[cnt]) 
		ans++;
    cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 23232
#include<bits/stdc++.h>
using namespace std;
#define lol long long
int main(){
  lol a,b,c,d,a2;
  cin>>a>>b;
  d=a*b;
  a2=a;
  for(lol i=2;i<a2;i++){
    while(1){
      if(d%i*i==0 && a%i==0 && b%i==0){
	d/=i;
	a/=i;
	b/=i;
      }
      else break;
    }
  }
  cout<<d<<"\n";
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    string s;
    cin >> s;
    ll res = 0, len = s.size(), stk = 0;
    REP(i, len){
        if(s[i] == 'S') stk++;
        else if(stk){
            res++;
            stk--;
        }
    }
    cout << len - 2 * res << endl;
}

Measured memory_bytes: 640
n, c, k = list(map(int, input().split()))
li = []
for _ in range(n):
    li.append(int(input()))

li.sort()
ans = 1
cnt = 1
t0 = li[0]
for t in li[1:]:
    if t > t0 + k or cnt == c:
        ans += 1
        t0 = t
        cnt = 1
    else:
        cnt += 1

print(ans)

Measured memory_bytes: 7884
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, k = geta(int)
    ans = 0
    for i in range(1, n+1):
        l = i
        while l < k:
            l *= 2
        ans += i/l/n

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316