akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s_lst = [int(input()) for _ in range(n)]

maximum = sum(s_lst)
s_lst.sort()


if maximum % 10 != 0:
    answer = maximum
else:

    for i in range(n):
        maximum -= s_lst[i]
        if maximum % 10 != 0:
            answer = maximum
            break
        else:
            maximum += s_lst[i]

        if i == n - 1 and maximum == sum(s_lst):
            answer = 0

print(answer)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
#define I_O		ios::sync_with_stdio(false),cin.tie(0)
#define ll		long long
#define ff		first
#define ss		second
#define mod 		1000000007
#define rep(i,n)	for(ll i=1;i<=n;i++)
#define repv(i,a,n)	for(ll i=a;i<=n;i++)
#define pb 		push_back
#define newl		'\n'
#define deb(x)		cout<<x<<" "
int main() 
{  
	I_O;
	int x,n,val,diff,mn = 200;	cin>>x>>n;
	set<int> s;	rep(i,n)	cin>>val,s.insert(val);
	repv(i,0,101)
	{
		bool isin = s.find(i)!=s.end();
		if(!isin)
		{
			diff = abs(x - i);
			mn = min(mn,diff); 
		}
	}
	repv(i,0,101)
	{
		bool isin = s.find(i)!=s.end();
		if(!isin)
		{
			diff = abs(x - i);
			if(diff == mn)	return cout<<i,0;
		}
	}
} 


Measured memory_bytes: 3660
#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)
     return u;
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x){
  if(x->right !=NIL)
    return treeSuccessor(x->right);

  Node y;
  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



}

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

}


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 = treeSearch(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: 25148
H, W = gets.chomp.split(" ").map(&:to_i)

canvas = []
H.times do |h|
  canvas[h] = gets.chomp.split("")
end

def have_black?(canvas, x, y)
  dirs = []
  dirs << {x: -1, y:  0} if x != 0 
  dirs << {x:  1, y:  0} if x != W - 1
  dirs << {x:  0, y: -1} if y != 0
  dirs << {x:  0, y:  1} if y != H - 1

  dirs.any? do |p|
    canvas[y + p[:y]][x + p[:x]] == "#"
  end
end

is_break = false
H.times do |y|
  W.times do |x|
    next if canvas[y][x] == "."

    is_break = true if not have_black?(canvas, x, y)

    break if is_break
  end
  break if is_break
end

if is_break then
  puts "No"
else
  puts "Yes"
end

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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const ll INF = 1001001001;
const ll MOD = 1e9 + 7;

ll gcdl[100000], gcdr[100000];
ll gcd(ll a, ll b){
  if(b > a) swap(a, b);
  if(a%b == 0) return b;
  return gcd(b, a%b);
}

int main(){
  int n;
  ll a[100000];
  ll ans = 1;
  cin >> n;
  rep(i, n) cin >> a[i];
  gcdl[0] = a[0];gcdr[0] = a[n-1];
  for(int i = 1; i < n; i++){
    gcdl[i] = gcd(gcdl[i-1], a[i]);
    gcdr[i] = gcd(gcdr[i-1], a[n-i-1]);
  }
  for(int i = 0; i < n-2; i++){
    ans = max(ans, gcd(gcdl[i], gcdr[n-3-i]));
  }
  ans = max(ans, gcdl[n-2]);
  ans = max(ans, gcdr[n-2]);
  cout << ans <<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>N>>S;

    ll ans=0;
    ll now=0;
    rep(i,N){
        if(S[i]=='I'){
            now++;
        }else{
            now--;
        }
        chmax(ans,now);
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define MAX 300000
int n,size;
vector<int> A;
int mp[MAX];
vector<ll> bit;
vector<P> tree;

void update(int a,int b,P x,int k,int l,int r){
  if(b<=l || r<=a)return;
  if(a<=l && r<=b){
    tree[k]=max(tree[k],x);
  }else{
    int m=(l+r)/2;
    update(a,b,x,k*2+1,l,m);
    update(a,b,x,k*2+2,m,r);
  }
}

void Upd(int a,int b,P x){
  a+=2;
  b+=2;
  if(a<b){
    update(a,b+1,x,0,0,size);
  }else{
    update(a,size,x,0,0,size);
    update(0,b+1,x,0,0,size);
  }
}

ll Get(int i){
  i+=2;
  i+=size-1;
  P res=tree[i];
  while(i){
    i=(i-1)/2;
    res=max(res,tree[i]);
  }
  return res.second;
}

void Add(int i,ll x){
  i+=2;
  while( i<(int)bit.size() ){
    bit[i]+=x;
    i+=(i&-i);
  }
}

ll Sum(int i){
  i+=2;
  ll res=0;
  while(i>0){
    res+=bit[i];
    i-=(i&-i);
  }
  return res;
}

ll Sum(int a,int b){
  if(a<b){
    return Sum(b)-Sum(a-1);
  }else{
    return Sum(n)-Sum(a-1)+Sum(b);
  }
}


ll solve(){
  vector<int> X;
  for(int i=0;i<(int)A.size();i++)
    X.push_back(A[i]);
  sort(X.begin(),X.end());
  
  
  size=1;
  while( size < n+5 ) size*=2;
  bit.clear();
  bit.resize(size);
  tree.clear();
  tree.resize(size*2);
  for(int i=0;i<(int)A.size();i++){
    A[i]= lower_bound( X.begin(), X.end(), A[i]) -X.begin() + 1;
    Upd(i,i+1,P(0,i));
    Add(i,1);
    mp[ A[i] ]=i;
  }
  
  int p=-1;
  ll res=0;
  for(int i=1;i+1<=n;i++){
    int num=mp[i];
    int target=Get(num);
    Add(num,-1);
    res+=Sum(p,target);
    Upd(p,target,P(i,target));
    p=target;
  }
  return res;
}

int main(){
  scanf("%d",&n);
  A.clear();
  A.resize(n);
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  printf("%lld\n",solve());
  return 0;
}

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

      int a = sc.nextInt();
      String op = sc.next();
      int b = sc.nextInt();


      if (op.equals("+")) {
        System.out.println(a+b);
      }else{
        System.out.println(a-b);
      }
  }
}


Measured memory_bytes: 21840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s[] = {"AC", "WA", "TLE", "RE"};
    int n;
    cin >> n;
    map<string, int> mp;
    while(n--){
        string t;
        cin >> t;
        mp[t]++;
    }
    for(auto x: s){
        cout << x << " x " << mp[x] << endl;
    }
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;
        vector<vector<int>> E(N);
        rep(i, M) {
            int a, b; cin >> a >> b;
            a--; b--;
            E[a].push_back(b);
            E[b].push_back(a);
        }
        vector<bool> visited(N);
        function<vector<int>(int)> go = [&](int now) -> vector<int> {
            visited[now] = true;
            for(int nxt : E[now]) {
                if(not visited[nxt]) {
                    auto ret = go(nxt);
                    ret.push_back(now + 1);
                    return ret;
                }
            }
            return {now + 1};
        };
        vector<int> ans;
        {
            rep(i, N) {
                if(E[i].size() == 1) {
                    ans = go(i);
                    goto END;
                }
            }            
            auto a = go(0);
            a.pop_back();
            reverse(all(a));
            auto b = go(0);            
            for(int i : a) b.push_back(i);
            ans = b;
        }
  END:
        cout << ans.size() << endl;
        for(int a : ans) cout << a << (a == ans.back() ? "\n" : " ");
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 14712
/*template date:2019/12/27*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<limits.h>
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
ll llgcd(ll x,ll y){if(y==0)return x;return llgcd(y,x%y);}
double to_deg(double r){return r*180.0/(atan(1.0)*4.0);}
typedef struct{
    int x;
    int y;
}pair_t;
int asc_cmp_t(const void* X,const void* Y){int x=(*(pair_t*)X).x,y=(*(pair_t*)Y).y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp_t(const void* X,const void* Y){int x=(*(pair_t*)X).x,y=(*(pair_t*)Y).y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
int main(){
    ll a,b;scanf("%lld %lld",&a,&b);
    ll x=a;
    x*=b;
    if(a<b){
        printf("%lld\n",x/llgcd(b,a));
    }else{
        printf("%lld\n",x/llgcd(a,b));
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct Union_Find_Tree{
    vector<int> par, rank, num;
    const int n;
    
    Union_Find_Tree(int n) : n(n){
        par.assign(n, -1), rank.assign(n, 0), num.assign(n, 1);
    }
    
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x, num[x] += num[y];
        return true;
    }
    
    int size(int x) {return num[root(x)];}
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    void clear(){
        fill(all(par), -1), fill(all(rank), 0), fill(all(num), 1);
    }
};

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

    int N;
    cin >> N;
    Union_Find_Tree uf(N);
    pii p[N];
    rep(i, N){
        int x, y; cin >> x >> y; x--, y--;
        p[x] = {y, i};
    }
    stack<int> s;
    int h[N];
    rep(i, N){
        h[i] = p[i].first;
        while(!s.empty() && p[s.top()].first < p[i].first){
            uf.unite(p[i].second, p[s.top()].second);
            chmin(h[i], h[s.top()]);
            s.pop();
        }
        if(!s.empty()){
            if(h[s.top()] < p[i].first){
                uf.unite(p[i].second, p[s.top()].second);
                chmin(h[i], h[s.top()]);
            }
        }
        s.push(i);
    }
    rep(i, N){
        cout << uf.size(i) << endl;
    }
}

Measured memory_bytes: 7952
N = int(input())
a = [0]*N
for i in range(N):
  a[i]=int(input())
cur = 1-1
ret = 0
v = set()
while cur != 2-1:
  #print(cur,v)
  if cur in v:
    print(-1)
    exit()
  v.add(cur)
  cur = a[cur]-1
  ret += 1
print(ret)

Measured memory_bytes: 15852
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int n, m,k,a;
	cin >> n >> m;
	vector<int> ans(m);
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			ans[a - 1]++;
		}
	}

	int cnt = 0;
	for (int i = 0;i < m; i++) {
		if (ans[i] == n) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll h,w;
ll ch,dh,cw,dw;
const int maxn=1e3+3;
ll g[maxn][maxn];
ll d[maxn][maxn];
ll dx[4]={1,-1,0,0};
ll dy[4]={0,0,1,-1};
ll vis[maxn][maxn];
bool check(ll x,ll y)
{
	if(x>h || x<1 || y>w || y<1 || g[x][y]==0) return false;
	return true;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>h>>w;
	cin>>ch>>cw>>dh>>dw;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			char ch;
			cin>>ch;
			if(ch=='.') g[i][j]=1;
			else g[i][j]=0;
		}
	}
	priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>> q;
	q.push(mp(0,mp(ch,cw)));
	memset(d,0x3f,sizeof(d));
	d[ch][cw]=0;
	while(!q.empty())
	{
		auto tp=q.top();q.pop();
		ll wt=tp.first;
		ll i=tp.second.first;
		ll j=tp.second.second;
		if(vis[i][j]==1) continue;
		vis[i][j]=1;
		for(ll k=0;k<4;k++)
		{
			ll x=i+dx[k];
			ll y=j+dy[k];
			if(check(x,y) && !vis[x][y])
			{
				d[x][y]=min(d[x][y],wt);
				q.push(mp(d[x][y],mp(x,y)));
			}	
		}
		for(ll I=-2;I<=2;I++)
		{
			for(ll J=-2;J<=2;J++)
			{
				ll x=i+I;
				ll y=j+J;
				if(check(x,y) && !vis[x][y])
			{
				d[x][y]=min(d[x][y],1+wt);
				q.push(mp(d[x][y],mp(x,y)));
			}
			}
		}
	}
	if(vis[dh][dw]) cout<<d[dh][dw]<<'\n';
	else cout<<-1<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



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

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

 vector<int> rev(N);
 for(int i=0;i<N;i++) rev[A[i]-1]=i+1;
 for(int i=0;i<N;i++) cout<<rev[i]<<endl;

}


Measured memory_bytes: 3948
// Author : Ritik Patel
// Institution: Pandit Deendayal Petroleum University

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

#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define what_is(x) cout << #x << " is: " << x << endl;

#define bitcount(a) __builtin_popcount(a)   // count set bits
#define lzcount(x) __builtin_clz(x)        // count leading zeros in binary representation of number
#define tzcount(x) __builtin_ctz(x)        // count trailing zeros in binary representation of number

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

typedef long long ll;
typedef long double lld;
const ll MOD = 1e9+7;
const lld PI = acos(-1.0);

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y){T ans=1;while(y>0){if(y&1LL) ans=(ans*x);y>>=1LL;x=(x*x);}return ans;}
template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }
template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }

//inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
//ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
//ll add(ll a,ll b,ll M)  { return mod(( mod(a,M ) + mod(b,M )),M);     }
//ll sub(ll a, ll b,ll M) { return mod((mod(a,M ) + M - mod(b,M )),M);   }
//ll mult(ll a,ll b,ll M) { return  mod(( mod(a,M)*mod(b,M) ),M) ; }
//bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd1= gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd1;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
  
               /* -------------------------------Main Code------------------------------- */

int main(){
    FAST
    int n;cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    vector<int> ans(n+1);
    for(int i=1;i<=n;i++){
        ans[a[i]] = i;
    }
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    if(n>1&&m>1)
        cout << combination(n, 2) + combination(m, 2) << endl;
    else if(n>1){
        cout << combination(n, 2) << endl;
    }
    else if(m>1){
        cout << combination(m, 2) << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

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

using namespace std;

int main(){
	
	vector<int> a;
	vector<int> b;
	
	for(int i=0;i<10;i++){
		int c;
		cin>>c;
		a.push_back(c);
	}
	
	for(int i=0;i<10;i++){
		int c;
		cin>>c;
		b.push_back(c);
	}
	
	
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	
	printf("%d %d\n", a[7]+a[8]+a[9], b[7]+b[8]+b[9]);
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long k = sc.nextLong();

		long a[] = new long[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long l = Long.MIN_VALUE;
		long r = Long.MAX_VALUE;
		while (l+1 < r){
			long x = (l + r) / 2;

			long tot = 0;
			for (int i=0; i<n; i++){
				if (a[i] < 0){
					int lSub = -1;
					int rSub = n;
					while (lSub + 1 < rSub){
						int c = (lSub + rSub) / 2;
						if (a[c]*a[i] < x) {
							rSub = c;
						} else {
							lSub = c;
						}
					}
					tot += n - rSub;
				} else {
					int lSub = -1;
					int rSub = n;
					while (lSub+1 < rSub) {
						int c = (lSub + rSub) / 2;
						if (a[c]*a[i] < x) {
							lSub = c;
						} else {
							rSub = c;
						}
					}
					tot += rSub;
				}
				if (a[i]*a[i] < x) {
					tot--;
				}
			}
			tot /= 2;
			if (tot < k){
				l = x;
			} else {
				r = x;
			}
		}
		System.out.println(l);
	}
}

Measured memory_bytes: 87044
s = list(input())
left = int(''.join(s[:2]))
right = int(''.join(s[2:]))
lyy = False
lmm = False
ryy = False
rmm = False
if 0 <= left <= 99:
    lyy = True
    if 1<= left <= 12:
        lmm = True

if 0 <= right <= 99:
    ryy = True
    if 1<= right <= 12:
        rmm = True

if lyy and lmm and ryy and rmm:
    print('AMBIGUOUS')
elif lyy and rmm:
    print('YYMM')
elif lmm and ryy:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n,i,a[8]={0,1,2,4,8,16,32,64};
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (i=7;i>=1;i--)
	  if (a[i]<=n)
	  {
	  	cout<<a[i]<<endl;
	  	return 0;
	  }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
char buf[20];
void mypr(int n)
{
    int i;
    if (!n) { pc('0'); return; }
    i = 0; while (n) buf[i++] = n%10 + '0', n/=10;
    while (i--) pc(buf[i]); 
}
 
typedef struct { char c; int a; int id; } DATA;
 
int partition(DATA *a, int lo, int hi)
{
    int i, j;
    int key;
    DATA t;
     
    key = a[hi].a, i = lo-1;
    for (j = lo; j < hi; j++) {
        if (a[j].a <= key) i++, t = a[i], a[i] = a[j], a[j] = t;
    }
    t = a[++i], a[i] = a[hi], a[hi] = t;
    return i;
}
 
void quick_sort(DATA *a, int lo, int hi)
{
    int mi;
 
    if (lo < hi) {
        mi = partition(a, lo, hi);
        quick_sort(a, lo, mi-1);
        quick_sort(a, mi+1, hi);
    }
}
 
DATA a[100002];
 
int main()
{
    int N, i, f;
 
    N = in();
    for (i = 0; i < N; i++) {
        a[i].c = gc(), gc();
        a[i].a = in(), a[i].id = i;
    }
    quick_sort(a, 0, N-1);
    f = 0; for (i = 1; i < N; i++) {
        if (a[i-1].a == a[i].a && a[i-1].id > a[i].id) { f = 1; break; }
    }
    puts(f? "Not stable": "Stable");
    for (i = 0; i < N; i++) {
        pc(a[i].c), pc(' '), mypr(a[i].a), pc('\n');
    }
    return 0;
}


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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);
			int c = Integer.parseInt(s[2]);
			int d = Integer.parseInt(s[3]);
			int total = 0;
			if(a < c) {
				if(b < d) {
					total = b - c;
				}else {
					total = d - c;
				}
			}else {
				if(b < d) {
					total = b - a;
				}else {
					total = d - a;
				}
			}

			if(total >= 0) {
				System.out.println(total);
			}else {
				total = 0;
				System.out.println(total);
			}

//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second

typedef long long ll;

int N,M,W,K,A,B,S;

using namespace std;

int main() {
    cin >> N;
    vector<pair<int,int>> a(N,pair<int,int>(0,0));
    stack<int> sta;
    rep(i,N){
        cin >> a.at(i).fi;
        a.at(i).se = i + 1 - a.at(i).fi; 
        if(a.at(i).se < 0){
            cout << -1 << endl;
            return 0;
        }
    }
    int N2 = N;
    rep(count,N2) {
        for(int i = N-1; i >= 0; i--){
            if(a.at(i).se > 0) continue;
            if(a.at(i).se == 0) {
                sta.push(a.at(i).fi);
                reps(j,i+1,N) a.at(j).se--;
                //cout << a.at(i).fi << ' ' << a.at(i).se << endl;
                a.erase(a.begin() + i);
                N--;
                break;
            }
        }
    }
    rep(i,N2) {
        cout << sta.top() << endl;
        sta.pop();
    }
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int inp[200];
int n;

int dp[100010];

int solve(int rem) {

    if(rem == 0) {
        return 0;
    }

    if(dp[rem] != -1) return dp[rem];

    int res = 0;

    for(int i = 0; i < n; i++) {
        if(rem >= inp[i]) {
            int ans = solve(rem - inp[i]);
            if(ans == 0) res = 1;
        }
    }

    dp[rem] = res;
    return res;

}

int main(){

    cin>>n;

    int k;
    cin>>k;

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

    for(int i = 0; i < 100010; i++) {
        dp[i] = -1;
    }

    if(solve(k)) {
        cout<<"First"<<endl;
    } else cout<<"Second"<<endl;


}


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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

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

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

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	char buf[8] = "";
	for(int cand = 0; cand < 1000; ++cand){
		sprintf(buf, "%03d", cand);
		int x = 0;
		for(char c : s){
			if(c == buf[x]){ ++x; }
		}
		ans += x == 3;
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  int min_val = N+1;
  for(int i = 0; i < (int)vec.size(); i++){
      if(vec[i] < min_val){
          ans++;
          min_val = vec[i];
      }
  }
  cout << ans << endl;
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  LL ans = 1e18;
  for(LL a=0;a<=1e6;++a){
	LL sum = A * a;
	LL da = X - a;
	LL rb = Y;
	if(da > 0){
	  sum += C * da * 2;
	  rb -= da;
	}

	if(rb > 0){
	  sum += min(B, C*2) * rb;
	}
	mini(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include <numeric>

#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(p) cerr<<#p<<'='<<(p.first)<<" "<<p.second<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
const ll MOD = 1e9 + 7;
const int N = 'Z'+5;
const int demo = 10;
using namespace std;
const ll cfmod=998244353;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
char button[4]={'L','R','U','D'};

// Ahhiya thi lakhvanu chalu thasse....

signed main() {
    FAST
    int q = 1;
    //cin>>q;
    while (q--) {
        int a,b;
        cin>>a>>b;
        if(a!=1 && b!=1){
            cout<<(a*b+1)/2;
        }
        else{
            cout<<1<<endl;
        }
    }
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n, l;
  cin >> n >> l;
  int aji[n];
  int m = INF;
  int choice = -1;
  int sum = 0;
  rep (i, n) {
    aji[i] = i + l;
    sum += aji[i];
    if (m > abs(aji[i])) {
      choice = i;
      m = abs(aji[i]);
    }
  }

  P(sum - aji[choice]);


  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    long long ans = 0;
    int p = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'B') p++;
        else ans += p;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())
S=[]
for _ in range(H):
    S.append(input())

dx=[1,1,0,-1,-1,-1,0,1]
dy=[0,1,1,1,0,-1,-1,-1]
minesweeper=[['#']*W for _ in range(H)]
for y in range(H):
    for x in range(W):
        if S[y][x]=='.':
            cnt=0
            for i in range(8):
                if 0<=y+dy[i]<H and 0<=x+dx[i]<W:
                    if S[y+dy[i]][x+dx[i]] =='#':
                        cnt+=1
            minesweeper[y][x]=str(cnt)
#print(minesweeper)
for row in minesweeper:
    print(''.join(row))



Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 2000000009
string s,t;
vector<string> ans;
int main()
{
	ios::sync_with_stdio(false);
	cin>>s>>t;
	int n=s.size(),sz=t.size();
	for (int i=0;i<=n-sz;++i){
		string now=s;bool f=1;
		for (int j=0;j<i;++j)
		  now[j]= s[j]=='?'? 'a':s[j];
		for (int j=i;j<i+sz;++j){
			now[j]=t[j-i];
			if (s[j]!=t[j-i]&&s[j]!='?'){
				f=0;
				break;
			}
		}
		for (int j=i+sz;j<n;++j) now[j]= s[j]=='?'? 'a':s[j];
		if(f){
			ans.push_back(now);
			//cout<<now<<endl;
		}
	}
	sort(ans.begin(),ans.end());
	if(ans.empty()) cout<<"UNRESTORABLE";
	else cout<<ans[0];
}

Measured memory_bytes: 256
n, a = input(), map(int, raw_input().split())

mi, mx = min(a), max(a)

b = []

p = a.index(mx if abs(mx) > abs(mi) else mi)
for i in xrange(n):
    if i != p:
        a[i] += a[p]
        b.append((p, i))

if a[0] > 0:
    for i in xrange(n - 1):
        if a[i] > a[i + 1]:
            a[i + 1] += a[i]
            b.append((i, i + 1))
else:
    for i in xrange(n - 1, 0, -1):
        if a[i] < a[i - 1]:
            a[i - 1] += a[i]
            b.append((i, i - 1))

print len(b)
for x in b:
    print x[0] + 1, x[1] + 1



Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

mint comb(ll n, ll r) {
  mint res = 1;
  for (int i = 1; i <= r; i++) {
    res *= n;
    res /= i;
    n--;
  }
  return res;
}

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

  int n, k;
  cin >> n >> k;
  int a = n - k + 1;
  int b = k - 1;

  vector<ll> mul1(2001, -1), mul2(2001, -1);
  rep(i, 1, k + 1) {
    ll x = 0, y = 0;
    if (mul1[i - 1] != -1)
      x = mul1[i - 1];
    else
      x = comb(b, i - 1).x;

    if (mul2[i] != -1)
      y = mul2[i];
    else
      y = comb(a, i).x;

    ll ans = (x * y) % mod;
    cout << ans << endl;
  }
}


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

typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for (int i = b; i <= e; i++)
#define FORD(i, b, e) for (int i = b; i >= e; i--)
#define SIZE(x) ((int)(x).size())
#define pb push_back
#define st first
#define nd second
#define all(a) begin(a), end(a)
#define watch(x) cerr << (#x) << " is " << (x) << '\n';

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

    string a, b;
    cin >> a >> b;
    int cnt = 0;
    FOR(i, 0, 2) if (a[i] == b[i]) cnt++;
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
l = input()
MOD = 10**9 + 7
r = len(l)
res = 0
num=0
for i in range(len(l)):
    tmp = r-i-1
    if(l[i]=="1"):
        res += pow(2,num,MOD) * pow(3,tmp,MOD)
        res%=MOD
        num+=1

res += pow(2,num)
print(res%MOD)


Measured memory_bytes: 65212
i=list(map(int,input().split()))

ans = 0

for j in range(i[0]):
    for k in range(i[1]):
        k += 1
        if len(str(k)) >= 2:
            k = str(k)
            if (int(k[-1])>=2)and(int(k[-2])>=2):
                if j+1 == int(k[-1])*int(k[-2]):
                    #print(j+1,int(k[-1]),int(k[-2]))
                    ans += 1
            k = int(k)
        k -= 1

        
print(ans) 


Measured memory_bytes: 3064
N = int(input())
S = input()


alphabet = [
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 
  'H', 'I', 'J', 'K', 'L', 'M', 'N', 
  'O', 'P', 'Q', 'R', 'S', 'T', 'U', 
  'V', 'W', 'X', 'Y', 'Z'
]*2

alphabet_converter = {a: alphabet[i+N] for i, a in enumerate(alphabet[:26])}

converted_S = ''
for s in S:
  converted_S += alphabet_converter[s]
  
print(converted_S)




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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int lol = ((n + 999) / 1000) * 1000;
    cout << lol - n << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<queue>
#include<iomanip>
using namespace std;
int main() {
	int N,W;
	cin >> N>>W;
	vector<int> weight(N),v(N);
	for (int i = 0; i < N; i++) {
		cin >> weight[i]>>v[i];
	}
	vector<vector<long long int>> dp(N+1,vector<long long int>(W+1,0));
	for (int i = 0; i < N; i++) {
		for (int w = 0; w <= W; w++) {
			if (w - weight[i] >= 0)dp[i + 1][w] = max(dp[i][w - weight[i]] + v[i],dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}
	cout << dp[N][W]<<endl;
}

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

int main() {
      int H, W, A, B;
      cin >> H >> W >> A >> B;
      vector<vector<int>> matrix(H, vector<int>(W));

      for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                  if ((i < B && j < A) || (i >=B  && j >= A)) {
                        matrix.at(i).at(j) = 1;
                  }
                  cout << matrix.at(i).at(j);
            }
            cout << endl;
      }
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,a,b;
    cin >> x >> a >> b;
    if (abs(x-a) < abs(x-b))
    {
      cout << 'A' << endl;
    }
    else
    {
      cout << 'B' << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
 
int prime[100000+510];
void makep(ll n){prime[0]=prime[1]=1;for(int i=2;i*i<=n;i++)if(!prime[i])for(int j=i*i;j<=n;j+=i)prime[j]=1;}
 
int main(){
	makep(100500);
	ll n,p;
	while(scanf("%lld%lld",&n,&p),~n){
		n++;
		ll a[510]={};
		rep(i,0,500)if(!prime[n+i])rep(j,i,500-i)if(!prime[n+j])a[i+j]++;
		ll crr=0;
		rep(i,0,p)while(!a[crr]--)crr++;
		printf("%lld\n",n+n+crr);
	}
}


Measured memory_bytes: 2192
N = int(input())
A = list(map(int, input().split()))

B = [0]*(N+1)

for i in range (0, N):
	B[A[i]]+=1
    
C = 0
import math

for i in range (1, N+1):
	C+=math.comb(B[i],2)
    
for i in range (0, N):
	print(C+math.comb(B[A[i]]-1,2)-math.comb(B[A[i]],2))

Measured memory_bytes: 32156
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>

using namespace std;

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

int N,M;
vector<pair<int,int> > job;

int main()
{
	scanf("%d%d",&N,&M);

	rep(i,N) {
		int a,b; scanf("%d%d",&a,&b);
		job.push_back(pair<int,int>(a, b));
	}

	sort(begin(job), end(job));

	int ans = 0;
	priority_queue<int> q;

	int cur = 0;
	for (int d = 1; d <= M; ++d) {
		while (cur < N and job[cur].first <= d) {
			q.push(job[cur].second);
			cur++;
		}
		if (not q.empty()) {
			int a = q.top();
			q.pop();

			ans += a;
		}
	}

	printf("%d\n",ans);
}


Measured memory_bytes: 1908
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
constexpr int  INF = 1000000007;
typedef long long ll;
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; }
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int n;
	cin >> n; int m;
	cin >> m;
	cout << max({ n + m,n - m,n * m }) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  maes = [(0,0)]
  usiros = [(0,0)]
  
  for i in range(n):
    place = a[i]
    value,preplace = maes[i]
    maes.append((value+abs(preplace-place),place))
  for i in range(n-1,-1,-1):
    place = a[i]
    value,preplace = usiros[(n-i-1)]
    usiros.append((value+abs(preplace-place),place))

  for i in range(n):
    maeval,maeplace = maes[i]
    usival,usiplace = usiros[n-i-1]
    print(maeval+usival+abs(maeplace-usiplace))

solve()

Measured memory_bytes: 29168