akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int n;
int compress(int *x1,int *x2,int w){
	vector<int> xs;
	REP(i,n){
		FOR(d,-1,2){
			int tx1 = x1[i] + d,tx2 = x2[i] + d;
			if(tx1 >=0 && tx1 <= w)xs.push_back(tx1);
			if(tx2 >=0 && tx2 <= w)xs.push_back(tx2);
		}
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	REP(i,n){
		x1[i] = find(xs.begin(),xs.end(),x1[i])-xs.begin();
		x2[i] = find(xs.begin(),xs.end(),x2[i])-xs.begin();
	}
	return xs.size();
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int h,w;
	while(cin >> w >> h,w){
		cin >> n;
		int x1[1003],x2[1003],y1[1003],y2[1003];
		REP(i,n){
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		}
		w = compress(x1,x2,w);
		h = compress(y1,y2,h);
		vector<vector<int> > fld(h,vector<int>(w,0));
		REP(i,n){
			fld[y1[i]][x1[i]]++;
			fld[y1[i]][x2[i]]--;
			fld[y2[i]][x1[i]]--;
			fld[y2[i]][x2[i]]++;
		}
		REP(i,h)REP(j,w-1)fld[i][j+1] += fld[i][j];
		REP(j,w)REP(i,h-1)fld[i+1][j] += fld[i][j];

		vector<vector<bool> > ispass(h,vector<bool>(w,false));
		queue<pair<int,int> > que;
		que.push(make_pair(0,0));
		int ct = 0;
		/*		REP(i,h){
			REP(j,w){
				cout << fld[i][j] << ' ';
			}
			cout << endl;
			}*/
		REP(i,h-1){
			REP(j,w-1){
				if(!ispass[i][j] && fld[i][j] == 0){
					ct++;
					ispass[i][j] = true;
					que.push(make_pair(i,j));
					while(!que.empty()){
						int y = que.front().first,x = que.front().second;
						que.pop();
						REP(k,4){
							int ny = y + dy[k];
							int nx = x + dx[k];
							if(nx >= 0 && nx <w-1 && ny>=0 && ny < h-1 && !ispass[ny][nx] && fld[ny][nx]==0){
								ispass[ny][nx] = true;
								que.push(make_pair(ny,nx));
							}
						}
					}
				}
			}
		}
		cout << ct << endl;
	}
  return 0;
}

Measured memory_bytes: 10316
n = int(input())
xl = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[0]+x[1])

x, l = xl[0]
ans = n
for i in range(1, n):
    if x+l-1 < xl[i][0]-xl[i][1]:
        x, l = xl[i]
    else:
        ans -= 1


print(ans)

Measured memory_bytes: 65496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int main () {

  char s[3], c;
  cin >> s[0] >> c >> c;
  cin >> c >> s[1] >> c;
  cin >> c >> c >> s[2];
  cout << s[0] << s[1] << s[2] << endl;
  return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A1 = sc.nextInt();
		int A2 = sc.nextInt();
		int A3 = sc.nextInt();
		int ans = 0;

		int [] list = new int [] {A1, A2, A3};
		Arrays.sort(list);

		ans = (list[1] - list[0]) + (list[2] - list[1]) ;
		System.out.println( ans );
	}
}

Measured memory_bytes: 21716
/*
	Author: Ritik Patel
*/
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#include <bits/stdc++.h>
using namespace std;
 
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define int long long int
// #define ll long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
// #define ld long double
// const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&


void solve(){
    int L, R, D;
    cin >> L >> R >> D;
    int cnt = 0;
    for(int i = L; i <= R; ++i){
        if(i%D == 0){
            ++cnt;
        }
    }
    cout << cnt << '\n';
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}
 
/*
Sample inp
*/

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

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

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

using namespace std;

int main()
{
   FAST/**/
   
   ll h1,m1,h2,m2,k;
   cin>>h1>>m1>>h2>>m2>>k;
   
   ll t1 = h1*60+m1;
   ll t2 = h2*60+m2;
   ll temp = t2;
   temp = t2-k;
   temp-=(t1);
   temp = max(temp,0ll);
   cout<<temp;
   
   
   return 0;        
}  
  
   

Measured memory_bytes: 3636
/* ex7_3 
melo */
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int row_N,col_N,i,j;//整数の箱を４つ用意する
    char **arrayc;
    int *row_TorF, *col_TorF;
    scanf("%d %d",&row_N,&col_N);//行と列を代入
    arrayc=(char**)calloc(row_N,sizeof(char*));
    if(arrayc==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    for(int i=0;i<row_N;i++){
        arrayc[i]=(char*)calloc(col_N,sizeof(char));
        if(arrayc[i]==NULL){
            fprintf(stderr,"memory allocation error.\n");
            exit(1);
        }
    }
    row_TorF=(int*)calloc(row_N,sizeof(int));
    if(row_TorF==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    col_TorF=(int*)calloc(col_N,sizeof(int));
    if(col_TorF==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    for(i=0;i<row_N;i++){//二次元の文字配列を代入
        for(j=0;j<col_N;j++){
            scanf(" %c",&arrayc[i][j]);
        }
    }
    for(i=0;i<row_N;i++){//初期化
        row_TorF[i]=0;
    }
    for(j=0;j<col_N;j++){//初期化
        col_TorF[j]=0;
    }
    for(i=0;i<row_N;i++){//黒がある行と列を探す
        for(j=0;j<col_N;j++){
            if(arrayc[i][j]=='#'){
                row_TorF[i]=1;//i列には黒がある
                col_TorF[j]=1;//i行には黒がある
            }
        }
    }
    for(i=0;i<row_N;i++){//白いマスのみからなる列または行以外（黒があった列または行）を表示する
        for(j=0;j<col_N;j++){
            if(row_TorF[i]==1&&col_TorF[j]==1){
                printf("%c",arrayc[i][j]);
            }
        }
        if(row_TorF[i]==1){
                printf("\n");//1列分表示されたら改行する
        }
    }
    free(row_TorF);
    free(col_TorF);
    for(int i=0;i<row_N;i++){
        free(arrayc[i]);
    }
    free(arrayc);
    return 0;//正常終了
}

Measured memory_bytes: 1604
#include <stdio.h>
int main(){
  int n,a,b,c,x,y[10000];
  while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n){
    int i,count=0;
    for(i=0;i<n;i++)scanf("%d",&y[i]);
    for(i=0;i<=10000;i++){
      if(y[count]==x)count++;
      x=(a*x+b)%c;
      if(count==n){
	printf("%d\n",i);
	break;
      }
      if(i==10000)printf("-1\n");
    }
  }
  return 0;
}

Measured memory_bytes: 620
n,a,b=map(int,input().split())
ans=0
for i in range(1,n+1):
    n=i
    cnt=0
    while i//10 != 0:
        cnt+=i%10
        i=i//10
    else:
        cnt+=i
    if a<=cnt and cnt<=b:
        ans+=n
print(ans)

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

using namespace std; 

int main () {
		string a, b; cin >> a >> b;
		int s = 0;
		for (int i=0; i < a.size(); i++) {
			if (a[i] == b[i]) {
				s ++;
			}
		}
		cout << s;
}

Measured memory_bytes: 3608
from heapq import heappop, heappush
def inpl(): return list(map(int, input().split()))
N, M = inpl()
A = inpl()
Q = []
for a in A:
    heappush(Q, [-a, a, 0])

for i in range(M):
    x, a, d = heappop(Q)
    if x == 0:
        break
    heappush(Q, [-(a//pow(2, d+1)), a, d+1])

print(sum([-q[0] for q in Q]))

Measured memory_bytes: 24848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll a,b,c,k; cin >> a >> b >> c >> k; 
  ll ans = min(a,k);
  k-=a;
  k-=b;
  if (k>0) ans -= k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int n;
int a,b,c,d;
ld dp[305][305][305];
int mam[305][305][305];
ld dawaj( int x, int y, int z)
{
	if(mam[x][y][z]==1)
		return dp[x][y][z];
	double px,py,pz;
	px=(double) x/n;
	py=(double) y/n;
	pz=(double) z/n;
	double res=0;
	if(x)
		res+=px*(dawaj(x-1,y,z)+1);
	if(y)
		res+=py*(dawaj(x+1,y-1,z)+1);
	if(z)
		res+=pz*(dawaj(x,y+1,z-1)+1);
	double p0=1.0 - px - py - pz;
	res+=p0;
	res/=1.0-p0;
	dp[x][y][z]=res;
	mam[x][y][z]=1;
	return res;
}
int main(){
	cin>>n;
	for(int i=1;n>=i;i++)
	{
		cin>>d;
		if(d==1)
			a++;
		else if(d==2)
			b++;
		else
			c++;
	}
	dp[0][0][0]=0;
	mam[0][0][0]=1;
	cout.precision(10);
	cout<<fixed<<dawaj(a,b,c);
	return 0;
}


Measured memory_bytes: 549120
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    const int MOD = 1e9 + 7;
    vint a(n); vin(a);
    vvint cnt(60, vint(2, 0LL));
    rfor(x, a) {
        rep(i, 60) {
            if(x & 1LL << i) {
                cnt[i][1]++;
            } else {
                cnt[i][0]++;
            }
        }
    }
    int ans = 0LL;
    rep(i, 60) {
        int t = (1LL << i) % MOD;
        t = t * cnt[i][0] % MOD;
        t = t * cnt[i][1] % MOD;
        ans = (t + ans) % MOD;
    }
    print(ans);

    return 0;
}


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

  int k;
  int a;
  int b;
  int x;
  int flag = 0;

  scanf("%d%d%d", &k, &a, &b);

  for (x = a; x <= b; x++){
    if (x % k == 0) flag = 1;
  }

  if (flag == 1) printf("OK\n");
  else printf("NG\n");

  return 0;

}


Measured memory_bytes: 1628
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    H = int(input())
    A = [None] + [int(i) for i in input().split(" ")]

    def parent(i):
        return i // 2

    def left(i):
        return 2*i

    def right(i):
        return 2*i + 1

    for i in range(1, H+1):
        print("node {}: key = {},".format(i, A[i]), end=" ")
        if parent(i) >= 1:
            print("parent key = {},".format(A[parent(i)]), end=" ")
        if left(i) <= H:
            print("left key = {},".format(A[left(i)]), end=" ")
        if right(i) <= H:
            print("right key = {},".format(A[right(i)]), end=" ")
        print("")



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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  cin >> n;
  vector<pair<long long, long long>> P(n);
  for (auto &p : P) {
    long long x, y;
    cin >> x >> y;
    p = {x, y};
  }

  auto p1 = P[0];
  for (auto &p : P) {
    if (p.first + p.second > p1.first + p1.second) {
      p1 = p;
    }
  }

  auto p2 = P[0];
  for (auto &p : P) {
    if (-p.first + p.second > -p2.first + p2.second) {
      p2 = p;
    }
  }

  auto p3 = P[0];
  for (auto &p : P) {
    if (-p.first - p.second > -p3.first - p3.second) {
      p3 = p;
    }
  }

  auto p4 = P[0];
  for (auto &p : P) {
    if (p.first - p.second > p4.first - p4.second) {
      p4 = p;
    }
  }

  long long res = -1;
  for (auto &p : P) {
    for (auto &r : vector<pair<long long, long long>>({p1, p2, p3, p4})) {
      res = max(res, abs(p.first - r.first) + (p.second - r.second));
    }
  }

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

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


bool dp[110000] = {false}; // dp[i] : i番目までの文字列が作れるか？


string N;

int main(){
    cin >> N;
    int one = 0; // 1の数
    int zero = 0; // 0の数
    for(int i=0;i<N.size();++i){
        N[i]=='0' ? zero++ : one++;
    }
    cout << min(zero,one) * 2 << endl;
    return 0;
}


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

typedef struct{
  int k;
  int l;
  int r;
} Tree;

void insert(int, int);
void chu(int);
void sen(int);
void find(int,int);
Tree t[500001];
int get;
int main()
{
  char s[8];
  int m;
  int num,t;
  int i;
  
  scanf("%d", &m);
  
  int count=0;
  for(i=0; i<m; i++){
    scanf("%s", &s);
    if(s[0]=='i'){ 
      scanf("%d", &num); 
      insert(count, num); 
      count++; 
    }
    if(s[0]=='f'){
      scanf("%d",&t);
      find(t,0);
      
    }
    if(s[0]=='p'){
      if(count>0) chu(0);
      printf("\n");
      if(count>0) sen(0);
      printf("\n");
    }
  }
  
  return 0;
  
}

void chu(int p){
  if(t[p].l>=0) chu( t[p].l);
  printf(" %d", t[p].k);
  if(t[p].r>=0) chu( t[p].r);
}

void sen(int p){
  printf(" %d", t[p].k);
  if(t[p].l>=0) sen(t[p].l);
  if(t[p].r>=0) sen(t[p].r);
}

void insert(int count, int z){
  int x=0, y;
  if(count<1) x=-1;
  
  t[count].k = z;
  t[count].l = -1;
  t[count].r = -1;
  
  while(x>=0){
    y = x; 
    if(z < t[x].k)x = t[x].l; 
    else x = t[x].r; 
  }
  if(count<1){}
  else if(z < t[y].k)t[y].l = count; 
  else t[y].r = count; 
  
}

void find(int num,int c){
  if (c==-1){
    printf("no\n");
  }
  else if (t[c].k==num){
    printf("yes\n");
  }
  else if (t[c].k > num && t[c].l != -1){
    find(num,t[c].l);
  }
  else {
    find(num,t[c].r);
  }
}

Measured memory_bytes: 5304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll mod = 998244353;

int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<int,int>> v(K);
    for (int i = 0; i < K; ++i) {
        cin >> v[i].first >> v[i].second;
    }
 
    // 総和を N に
    --N;
    vector<ll> dp(N + 1, 0), sdp(N + 2, 0);
    dp[0] = 1, sdp[1] = 1;
    for (int n = 1; n <= N; ++n) {
        for (auto p : v) {
            int left = max(0, n - p.second);
            int right = max(0, n - p.first + 1);
            int diff = sdp[right] -sdp[left];
            if (diff < 0) diff+=mod;
            dp[n] += diff;
            dp[n]%=mod;
        }
        sdp[n+1] = sdp[n] + dp[n];
        sdp[n+1]%=mod;
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
#define begin Begin
#define next Next
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int mod=924844033,maxn=2e5+10,g0=5;
int begin[maxn],to[maxn<<1],next[maxn<<1],e;
void add_edge(int x,int y){
	to[++e]=y;
	next[e]=begin[x];
	begin[x]=e;
}
int ksm(int x,int y){
	int num=1;
	while(y){
		if(y&1) num=1ll*num*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return num;
}
int sz[maxn];
int cnt[maxn],n;
int fac[maxn],ifac[maxn];
int A[maxn<<2],B[maxn<<2];
void dfs(int x,int ff){
	sz[x]=1;
	for(int i=begin[x];i;i=next[i])
		if(to[i]!=ff){
			dfs(to[i],x);
			sz[x]+=sz[to[i]];
			cnt[sz[to[i]]]++;
			cnt[n-sz[to[i]]]++;
		}
}
int rev[maxn<<2],g[maxn<<2][2];
void init(){
	fac[0]=1;
	REP(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int ans[maxn];
int N=1;
void ntt(int *y,int flag){
	REP(i,0,N-1) if(i<rev[i]) swap(y[i],y[rev[i]]);
	for(int k=2,t=1;k<=N;k<<=1,++t)
		for(int i=0;i<N;i+=k)
			for(int j=0,x=1;j<(k>>1);++j,x=1ll*x*g[t][flag]%mod){
				int x1=y[i+j],x2=1ll*y[i+j+(k>>1)]*x%mod;
				y[i+j]=(x1+x2)%mod,y[i+j+(k>>1)]=(x1+mod-x2)%mod;
			}
}
int main(){
	n=read();
	init();
	REP(i,1,n-1){
		int x=read(),y=read();
		add_edge(x,y),add_edge(y,x);
	}
	dfs(1,0);
	REP(i,0,n) A[i]=1ll*cnt[n-i]*fac[n-i]%mod,B[i]=ifac[i];
	while(N<=n*2) N<<=1;
	REP(i,0,N-1) rev[i]=(rev[i>>1]>>1)|((i&1)*(N>>1));
	for(int k=1,t=0;k<=N;k<<=1,t++){
		g[t][1]=ksm(g0,(mod-1)/k);
		g[t][0]=ksm(g[t][1],mod-2);
	}
	ntt(A,1),ntt(B,1);
	REP(i,0,N-1) A[i]=1ll*A[i]*B[i]%mod;
	ntt(A,0);
	int inv=ksm(N,mod-2);
	REP(i,0,N-1) A[i]=1ll*A[i]*inv%mod;
	REP(i,1,n){
		ans[i]=1ll*n*fac[n]%mod*ifac[n-i]%mod;
		ans[i]=1ll*(ans[i]+mod-A[n-i])%mod*ifac[i]%mod;
	}
	REP(i,1,n) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 28160
using System;
using System.Collections;
using System.Linq;

namespace DIntegerCards
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力 N/M, Card の取得
            var inputsNM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputsNM[0];
            var m = inputsNM[1];

            var cards = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 操作一覧の取得
            var operations = new CardOperation[m];
            for (var i = 0; i < m; i++)
            {
                var inputsBC = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var b = inputsBC[0];
                var c = inputsBC[1];
                operations[i] = new CardOperation(b, c);
            }

            Array.Sort(operations);
            Array.Reverse(operations);

            var opCards = operations.SelectMany(op => Enumerable.Repeat(op.number, op.count)).Take(n).ToArray();
            var sum = cards.Concat(opCards).OrderByDescending(x => x).Take(n).Select(x => (long)x).Sum();

            // 解答の出力
            Console.WriteLine(sum);
        }

        class CardOperation : IComparable<CardOperation>
        {
            public int count, number;

            public CardOperation(int b, int c)
            {
                count = b;
                number = c;
            }

            public int CompareTo(CardOperation other)
            {
                return this.number.CompareTo(other.number);
            }
        }
    }
}


Measured memory_bytes: 31944
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;
ll ans[1000000];
int N, Q;
vector<int> G[1000000];
int x[1000000];

void dfs(ll n, ll p,ll point) {
    ans[n] = point;
    for(auto i : G[n]) {
        if (p == i) continue;
        dfs(i, n, x[i] + point);
    }
}

int main(){
    cin >> N >> Q;
    int a[N], b[N];
    rep(i, N-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    int p, y;
    rep(i, N){
        x[i] = 0;
    }
    rep(i, Q){
        cin >> p >> y;
        p--;
        x[p] += y;
    }

    dfs(0, -1,x[0]);

    rep(i, N-1){
        cout << ans[i] << " ";
    }
    cout << ans[N-1] << endl;

}

Measured memory_bytes: 49024
h, w = map(int, input().split())
s = [['.'] * (w + 2) ]
for _ in range(h):
  s.append(['.'] + list(input()) + ['.'])
s.append(['.'] * (w + 2))
for y in range(1, h + 1):
  for x in range(1, w + 1):
    if s[y][x]=="#" and s[y-1][x]=="." and s[y+1][x]=="." and s[y][x-1]=="." and s[y][x+1]==".":
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define M 10023
#define ll long long
using namespace std;

ll n, m, lista[M], soma;

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> lista[i];
		soma+= lista[i];
	}

	if(n == soma){
		cout << 0 << endl;
	}if(n < soma){
		cout << -1 << endl;
	}if(n > soma){
		cout << n-soma << endl;
	}
}

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

#define ll long long

ll N, M, I1, I2, J1, J2;
char A[1000][1000];

vector < vector < ll > > dp(1000, vector < ll > (1000, 2e9));
vector < pair < ll, ll > > dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
set < pair < ll, ll > > visited;

bool isvalid(ll i, ll j){
	return (i >= 0 && i < N && j >= 0 && j < M);
}

void update(ll i, ll j, ll cost, queue < pair < ll, ll> > &Q){
    if (i >= N || i < 0 || j >= M || j < 0 || dp[i][j] != 2e9 || A[i][j] != '.')
        return;
    Q.push({i, j});
    dp[i][j] = cost;
    for (auto d : dir)
	    update(i + d.first, j + d.second, cost, Q);
}

int main(){
	cin >> N >> M >> I1 >> J1 >> I2 >> J2;
	I1 -= 1; J1 -= 1; I2 -= 1; J2 -= 1;
	for (ll i = 0; i < N; i ++)
		for (ll j = 0; j < M; j ++)
			cin >> A[i][j];
	queue < pair < ll, ll > > Q;
	update(I1, J1, 0, Q);
	long long cost = 1;
	while (Q.size() > 0){
		ll len = Q.size();
		while (len --){
			pair < ll, ll > U = Q.front();
			Q.pop();
			ll U1 = U.first, U2 = U.second;
			for (ll j = -2; j <= 2; j++){
				for (ll k = -2; k <= 2; k ++){
					if (U1 + j == U1 && U2 + k == U2) continue;
					update(U1 + j, U2 + k, cost, Q);
				}
			}
		}
		cost += 1;
	}
	if (dp[I2][J2] == 2e9){
		cout << "-1\n";
	}else{
		cout << dp[I2][J2] << "\n";
	}
}



Measured memory_bytes: 12660
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=1e18;
lld pi=3.1415926535897932;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ans=1;
    lld i=0.0+(lld)INF;
    while(n--)
    {
        int a;
        cin>>a;
        if(a==0)
        ans=0;
        if(ans<1)
        continue;
        lld ans1=0.0+(lld)(ans),a1=0.0+(lld)(a);
        if(a==0)
        ans=0;
        else if(ans1>(i/a1))
        {
            //cout<<ans1<<" "<<i<<" "<<a1<<" "<<1/a1<<"\n";
            ans=-1;
        }
        else if((ans*a)>INF)
        ans=-1;
        else
        ans*=a;
        //cout<<ans<<"\n";
    }
   cout<<ans;
}

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

	int main() {
		int N;
		cin >> N;
		vector < int>t;
		int suma = 0;
		for (int i = 0; i < N; i++) {
			int a;
			cin >> a;
			suma += a;
			if (a % 10 != 0) {
				t.push_back(a);
			}
		}
		int minElement = *std::min_element(t.begin(), t.end());

		
		if (suma % 10 == 0 && !t.empty()) {
			suma -= minElement;
			cout << suma << endl;

		}
		else if (t.empty()) {
			cout << 0 << endl;
		}
		else cout << suma << endl;
		
		return 0;
	}	

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
#include <tuple>
using namespace std;

typedef long long ll;
vector<int> xc[100000], yc[100000];
int n, k, t1, t2, x[100000], y[100000], p[100000], vis[100000];
pair<int, int> a[100000];

int g(int x)
{
    if (p[x] != x)
        return p[x] = g(p[x]);
    return x;
}

void stb(vector<int> &a, vector<int> &b)
{
    if (a.size() > b.size())
        swap(a, b);
    for (int i : a)
        b.push_back(i);
    a = vector<int>();
}

void f(int x, int y)
{
    x = g(x);
    y = g(y);
    if (x == y)
        return;

    stb(xc[x], xc[y]);
    stb(yc[x], yc[y]);
    p[x] = y;
}

int main()
{
    memset(x, -1, sizeof x);
    memset(y, -1, sizeof y);
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> t1 >> t2;
        a[i] = {t1, t2};
    }
    for (int i = 0; i < n; ++i)
    {
        p[i] = i;
        xc[i].push_back(a[i].first);
        yc[i].push_back(a[i].second);
    }
    for (int i = 0; i < n; ++i)
    {
        int t1, t2;
        tie(t1, t2) = a[i];
        if (x[t1] != -1)
            f(i, x[t1]);
        if (y[t2] != -1)
            f(i, y[t2]);
        x[t1] = i;
        y[t2] = i;
    }
    ll sum = 0;
    for (int i = 0; i < n; ++i)
    {
        int x = g(i);
        if (!vis[x])
        {
            sort(xc[x].begin(), xc[x].end());
            sort(yc[x].begin(), yc[x].end());
            ll a = unique(xc[x].begin(), xc[x].end()) - xc[x].begin(),
               b = unique(yc[x].begin(), yc[x].end()) - yc[x].begin();
            sum += a * b;
            //cout << a << " " << b << endl;
            vis[x] = 1;
        }
    }
    cout << sum - n << endl;
}

Measured memory_bytes: 14640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

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

int main(void){
    ll a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f, a+b+c+d+e+f != 0){
        a += d;
        b += e;
        c += f;
        ll m = min(a, min(b, c));
        ll ans = 0;
        REP(i, 3){
            if(m - i < 0) continue;
            ll k = (a - i) / 3;
            k += (b - i) / 3;
            k += (c - i) / 3;
            ans = max(ans, k + i);
        }
        cout << ans << endl;
    }
	
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>

using namespace std;

int main(){


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

	return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MX = 200005, MOD = 1e9+7;
int n, k, a, ps, ns;
ll ans = 1, as[MX], rp = MOD, rn = MOD, lp = MOD, ln = MOD;
ll inv(ll a){
	ll ret = 1;
	for(int t = MOD-2; t; t /= 2, (a *= a) %= MOD){
		if(t&1) (ret *= a) %= MOD;
	}
	return ret;
}
int main(){
	scanf("%d%d", &n, &k);
	rep(i,n){
		scanf("%lld", as+i);
		if(as[i] > 0) ps++;
	}
	sort(as, as+n, [](ll a, ll b){return abs(a) < abs(b);});
	if(n == k || ((k & 1) && ps == 0)){
		rep(i,k) (ans *= as[i]) %= MOD;
		if(ans < 0) ans += MOD;
		printf("%lld\n", ans);
		return 0;
	}
	rep(i,k){
		(ans *= as[n-1-i]) %= MOD;
		if(as[n-1-i] <= 0){
			ns++;
			rn = as[n-1-i];
		}else rp = as[n-1-i];
	}
	rep(i,n-k) (as[i] <= 0 ? ln : lp) = as[i];
	if(ns & 1){
		if(ln == MOD || rp == MOD || (lp != MOD && ln * rn < lp * rp)){
			ln = lp; rp = rn;
		}
		(ans *= ln) %= MOD;
		(ans *= inv(rp)) %= MOD;
	}
	if(ans < 0) ans += MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 5360
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

int X, Y, Z, N;
vector<int> A, B, C;
vector<pi> subAB;
vector<ll> lBC, rAC;
ll lsumA, lsumB, lsumC;
priority_queue<pi, vector<pi>, greater<pi> > lsubBC;
priority_queue<pi, vector<pi>, greater<pi> > rsubAC;

int main(void) {
	cin >> X >> Y >> Z;
	
	N = X + Y + Z;
	A.resize(N);
	B.resize(N);
	C.resize(N);
	subAB.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
		subAB[i] = make_pair(A[i] - B[i], i);
	}
	sort(subAB.begin(), subAB.end());

	lsumB = lsumC = 0LL;
	lBC.resize(N, 0);
	for (int i = 0; i < Y + Z; ++i) {
		int idx = subAB[i].second;
		lsubBC.push(make_pair(B[idx] - C[idx], idx));
		lsumB += B[idx];
		if (i >= Y) {
			idx = lsubBC.top().second;
			lsubBC.pop();
			lsumC += C[idx];
			lsumB -= B[idx];
		}
		lBC[i] = lsumB + lsumC;
	}

	lsumA = lsumC = 0LL;
	rAC.resize(N, 0);
	for (int i = N - 1; i >= N - X - Z - 1; --i) {
		int idx = subAB[i].second;
		rsubAC.push(make_pair(A[idx] - C[idx], idx));
		lsumA += A[idx];
		if (i < N - X) {
			idx = rsubAC.top().second;
			rsubAC.pop();
			lsumC += C[idx];
			lsumA -= A[idx];
		}
		rAC[i] = lsumA + lsumC;
	}

	ll ans = 0;
	for (int i = Y - 1; i <= N - X - 1; ++i)
		ans = max(ans, lBC[i] + rAC[i + 1]);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 5112
#include <iostream>
#include<math.h>
using namespace std;

int main() {
    int c,d;
    while(cin>>d){
        int sum=0;
        for(int i=1; i*d<600; i++) {
            int res=i*d;
            if(i==1)
              c=d*d*d;
            else
                c=(res*res)*d;
            sum+=c;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e3 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

int n;

int main()
{

    string s;
    cin>>s;
    string res="";
    for(int i=0;i<s.length();i++)
    {
    	if(s[i]=='B')
    	{
    		if(res=="")
    		{
    			continue;
    		}
    		else
    		{
    			res=res.substr(0,res.length()-1);
    		}
    	}
    	else
    	{
    		res=res+s[i];
    	}
    }
    cout<<res<<endl;
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 4e5 + 5;

struct Tnode{
	vector <int> stop;
	int P;
	int child[26];
}Trie[maxn];

int nT = 0, root = 0;

int AddNode (void){
	++nT;
	return nT;
}

void AddWord (string s, int id){
	int r = root;
	for (int i=0; i<(int)s.size(); ++i){
		int k = s[i] - 'a';
		int l;
		if (Trie[r].child[k] == 0){
			l = AddNode ();
			Trie[r].child[k] = l;
			Trie[l].P = r;
		}
		r = Trie[r].child[k];
	}
	Trie[r].stop.pb (id);
}

int CountPrefix (string s){
	int ret = 0;
	int r = root;
	for (int i=0; i<(int)s.size()-1; ++i){
		int k = s[i] - 'a';
		ret += Trie[Trie[r].child[k]].stop.size();
		r = Trie[r].child[k];
	}
	return ret;
}
		

int sz[maxn];

void findsz (int u){
	sz[u] = Trie[u].stop.size ();
	for (int i=0; i<26; ++i){
		int to = Trie[u].child[i];
		if (to != 0){
			findsz (to);
			sz[u] += sz[to];
		}
	}
}

int f[maxn][26][26];
int dem[26][26];

void dfs (int u){
	for (int v : Trie[u].stop){
		for (int i=0; i<26; ++i){
			for (int j=0; j<26; ++j){
				f[v][i][j] = dem[i][j];
			}
		}
	}
	for (int i=0; i<26; ++i){
		if (Trie[u].child[i] == 0) continue;
		int to = Trie[u].child[i];
		for (int j=0; j<26; ++j){
			if (i == j || Trie[u].child[j] == 0) continue;
			int other = Trie[u].child[j];
			dem[i][j] += sz[other];
		}
		dfs (to);
		for (int j=0; j<26; ++j){
			if (i == j || Trie[u].child[j] == 0) continue;
			int other = Trie[u].child[j];
			dem[i][j] -= sz[other];
		}
	}
}

int cnt[maxn];
string Str[maxn];

signed main (void){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int N;
	cin >> N;
	for (int i=1; i<=N; ++i){
		cin >> Str[i];
		AddWord (Str[i], i);
	}
	for (int i=1; i<=N; ++i){
		cnt[i] = CountPrefix (Str[i]);
	}
	findsz (root);
	dfs (root);
	int Q;
	cin >> Q;
	while (Q--){
		int K;
		cin >> K;
		string str;
		cin >> str;
		int ret = 0;
		for (int i=0; i<26; ++i){
			for (int j=0; j<=i; ++j){
				ret += f[K][str[i]-'a'][str[j]-'a'];
			}
		}
		cout << ret + cnt[K] + 1<< '\n';
	}	
}	


Measured memory_bytes: 333824
mod = 10 ** 9 + 7
N = int(input())
S = input()
T = input()

ans = 1
if S[0] == T[0]:
    flag = 'tate'
    ans *= 3
else:
    flag = 'yoko'
    ans *= 6
    
for i in range(1, N):
    if S[i] == T[i]:
        if flag == 'tate':
            ans *= 2
            flag = 'tate'
        elif flag == 'yoko' or flag == 0:
            flag = 'tate'
    else:
        if flag == 'tate':
            ans *= 2
            flag = 'yoko'
        elif flag == 'yoko':
            flag = 0
        elif flag == 0:
            ans *= 3
            flag = 'yoko'

print(ans % mod)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	ll n,m; cin >> n >> m;
	// number, count
	map<ll,ll> mp;
	
	FOR(n){
		ll x; cin >> x;
		++mp[x];
	}
	
	FOR(m){
		ll b,c; cin >> b >> c;
		mp[c] += b;
	}
	
	ll ans = 0;
	while(n){
		auto itr = mp.end();
		--itr;
		ans += (*itr).first;
		if((*itr).second == 1){
			mp.erase(itr);
		} else{
			--mp[(*itr).first];
		}
		--n;
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=0;
    string s;
    cin>>s;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='o')t++;
    }
    printf("%d",700+100*t);
    return 0;
}


Measured memory_bytes: 256
program dm
  implicit none
  integer :: N,i,edge
  integer,allocatable ::A(:)
  integer,allocatable :: ans(:)

  read(*,*) N
  allocate(A(N))
  allocate(ans(N))
  read(*,*) A

  edge=0
  do i=1,n
     edge=edge-((-1)**i)*A(i)
  enddo
  ans(1)=edge/2
  do i=2,n
     ans(i)=(A(i-1)-ans(i-1))
  enddo
  do i=1,n
     write(*,'(i0)',advance='no') ans(i)*2
     write(*,'(a)',advance='no') ' '
  enddo
  write(*,*)
end program dm






Measured memory_bytes: 2688
N = int(input())
B_LIST = input().split(" ")
A = []
B = []
for i in B_LIST:
    B.append(int(i))

A.append(B[0])

for i in range(1, N - 1):
    if i == N - 1:
        a = B[N - 1]
        print(N, 555)
    else:
        if B[i] > B[i -1]:
            a = B[i -1]
        else:
            a = B[i]
    A.append(a)
    
A.append(B[N-2])

s = 0
for i in A:
    s += i
    
print(s)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,m; cin >> n >> m;
  vector<string> a(n),b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];

  rep(i,n-m+1){
    rep(j,n-m+1){
      bool ok = true;
      rep(k,m){
        if(a[i+k].substr(j,m) != b[k]) ok = false;
      }
      if(ok){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

struct edge{
  ll v, w;
};

vector<ll> dijkstra(int N, vector<vector<edge> >& G, int s) {
  vector<ll> d(N, (ll)1e+15);
    d[s] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>> > pq;
    pq.push(pair<ll, ll>(0, s));
    while (pq.size()) {
        pair<ll, ll> p = pq.top(); pq.pop();
        ll u = p.second;
        if (p.first > d[u]) continue;
        for (edge e: G[u])
            if (d[e.v] > d[u] + e.w) {
                d[e.v] = d[u] + e.w;
                pq.push(pair<ll, ll>(d[e.v], e.v));
            }
    }
    return d;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<edge> > G(N,vector<edge>());
  
  REP(i, N - 1){
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  int Q, K;
  cin >> Q >> K;
  K--;
  vector<ll> d = dijkstra(N, G, K);
  
  REP(i, Q){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << d[x] + d[y] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 11248
#include <stdio.h>

char mode[100];

int main(void)
{
	int a, k, i;
	
	k = 0;
	
	while (scanf("%d", &a) != EOF){
		
		mode[a - 1]++;
		
		if (mode [a - 1] > k){
			k = mode[a - 1];
		}
	}
	
	for (i = 0; i < 100; i++){
		
		if (k == mode[i]){
			printf("%d\n", i+1);
		}
	}
	return (0);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  A.insert(A.begin(), 0);
  A.insert(A.end(), 0);

  int sum = 0;
  for (int i = 0; i < N + 1; i++) sum += abs(A[i] - A[i + 1]);

  for (int i = 1; i < N + 1; i++) {
    int ans = 0;
    ans = sum + abs(A[i + 1] - A[i - 1]) - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]);
    cout << ans << endl;
  }
}

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

int main(){
    int m,j,k;
  string n;
cin>>m>>n;
  j=0;
  k=0;
  for(int i=0;i<m;i++){
    if(n[i]=='I'){
      k++;
    }
 if(n[i]=='D'){
   k--;
    }
    j=max(j,k);
  }
 
    cout<<j<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

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

const int N(3010), Mod(1e9 + 7);
inline void Add(int &x, int y) { x = (x + y) % Mod; }
int n, m, f[N][N][2], ans;

int main()
{
	n = read(), m = read(), f[0][0][1] = 1;
	for (int i = 1; i <= n; i++) f[0][i][0] = 1;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			// RR
			if (j < n)
			{
				Add(f[i][j][1], f[i - 1][j + 1][1]);
				if (j == 0) Add(f[i][j][1], f[i - 1][j + 1][0]);
				else Add(f[i][j][0], f[i - 1][j + 1][0]);
			}
			// BB
			if (j)
			{
				Add(f[i][j][1], f[i - 1][j - 1][1]);
				Add(f[i][j][0], f[i - 1][j - 1][0]);
			}
			// RB
			if (j)
			{
				Add(f[i][j][1], f[i - 1][j][1]);
				if (j == 1) Add(f[i][j][1], f[i - 1][j][0]);
				else Add(f[i][j][0], f[i - 1][j][0]);
			}
			// BR
			if (j < n)
			{
				Add(f[i][j][1], f[i - 1][j][1]);
				Add(f[i][j][0], f[i - 1][j][0]);
			}
		}
	}
	for (int i = 0; i <= n; i++) Add(ans, f[m][i][1]);
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int main() {
  long long N, A, B, ans;
  cin >> N >> A >> B;
  if (A < B)
    ans = max(0LL, (N - 2) * (B - A) + 1);
  else if (A == B)
    ans = 1;
  else
    ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-25 15:01:19 +0900
# LastModified: 2020-06-25 15:40:42 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    s = input()
    while s:
        s = s[:-1]
        if len(s)%2!=0:
            continue
        mid = len(s)//2
        left = s[:mid]
        right = s[mid:]
        if left==right:
            print(len(s))
            return

    


if __name__ == "__main__":
    main()


Measured memory_bytes: 8980
N,K=map(int,input().split())
Alist=list(map(int,input().split()))
already=[1]
alreadyset={1}
last=1
while True:
    if Alist[last-1] in alreadyset:
        start=already.index(Alist[last-1])
        break
    already.append(Alist[last-1])
    alreadyset.add(Alist[last-1])
    last=Alist[last-1]
roop=len(already)-start
if K-len(already)<0:
    print(already[K])
else:
    index=(K-start)%roop+start
    while not start<=index<len(already):
        index=index%roop+start
    print(already[index])

Measured memory_bytes: 32372
# 088 B
N = int(input())
a = list(map(int, input().split()))
A = 0
B = 0
aa = sorted(a)
for i in range(0, N, 2):
    A += aa[-i-1]
    if (i+2)<=N:
        B += aa[-i-2]
print(A-B)


Measured memory_bytes: 61804