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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}


//base=9973,mod=999999937LL, 1000000007LL;
struct rolling_hash{
    int mnum;
	std::string str;
    long long int base;
	std::vector<long long int> mod;
    std::vector<vector<long long int>> hash,pow;

	rolling_hash(const std::string &str,long long int base,std::vector<long long int> mod):mnum(mod.size()),str(str),base(base),mod(mod){
		int size=str.size();
		hash=std::vector<std::vector<long long int>>(mnum,std::vector<long long int>(size+1));
		pow=std::vector<std::vector<long long int>>(mnum,std::vector<long long int>(size+1));

		for(int i=0; i<mnum; ++i){
            hash[i][0]=0;
            pow[i][0]=1;
        }
        for(int i=0; i<mnum; ++i){
            long long int m=mod[i];
    		for(int j=1; j<size+1; ++j){
    			pow[i][j]=pow[i][j-1]*base%m;
    			hash[i][j]=(hash[i][j-1]*base+str[j-1])%m;
    		}
        }
	}

	long long int compute_hash(int l,int r,int i){ //[l,r)
		return (hash[i][r]-hash[i][l]*pow[i][r-l]%mod[i]+mod[i])%mod[i];
	}

    bool match(int l,int r,const std::vector<long long int> &hs){
        for(int i=0; i<mnum; ++i) if(compute_hash(l,r,mod[i])!=hs[i]) return false;
        return true;
    }
};

struct rolling_hash64{
    typedef unsigned long long int ull;
	std::string str;
    ull base;
    std::vector<ull> hash,pow;

	rolling_hash64(const std::string &str,ull base):str(str),base(base){
        int size=str.size();
        hash.resize(size+1);
        pow.resize(size+1);
        hash[0]=0;
        pow[0]=1;
        for(int i=1; i<size+1; ++i){
            pow[i]=pow[i-1]*base;
            hash[i]=hash[i-1]*base+str[i-1];
        }
	}

	ull compute_hash(int l,int r){ //[l,r)
		return hash[r]-hash[l]*pow[r-l];
	}

    bool match(int l1,int r1,int l2,int r2){
        return compute_hash(l1,r1)==compute_hash(l2,r2);
    }
};

void solve(){
    int n,m;
    string s;
    cin >> n >> m >> s;

    rolling_hash64 roriha(s,9973);
    vector<unsigned long long int> v;
    int l=0,r=1;
    rep(i,0,m){
        string q;
        cin >> q;
        if(q=="R++") ++r;
        if(q=="R--") --r;
        if(q=="L++") ++l;
        if(q=="L--") --l;
        v.push_back(roriha.compute_hash(l,r));
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout << v.size() << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

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

int main() {
	int N,a=0,b=0,cnt;
	cin >> N;
	cnt = N;
	vector<int> s(N);
	for(int i = 0;i < N;i++)
	{
		cin >> s.at(i);
	}
	for(int i = 0;i < N;i++)
	{
		int smax = s.at(0),mj=0;
		for(int j=1;j < cnt;j++)
		{
			if(smax < s.at(j))
			{
				smax = s.at(j);
				mj = j;
			}
		}
		if(i % 2 == 0)
		{
			a += smax;
		}
		else
		{
			b += smax;
		}
		s.at(mj) = s.at(cnt-1);
		s.pop_back();
		cnt--;
  }
	cout << a - b << endl;
}


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

int main(){
  int n,m,c;
  cin >> n >> m >> c;
  int b[m];
  for(int i=0;i<m;i++){
      cin >> b[i];
  }
  int count = 0;
  for(int i=0;i<n;i++){
      int ans = 0;
      for(int k=0;k<m;k++){
          int a=0;
          cin >> a;
          ans += a*b[k];
      }
      ans += c;
      if(ans > 0) count++;
  }
  cout << count << endl;
}

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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t A[N];
    for (int64_t i = 0; i < N; ++i) {
        std::cin >> A[i];
        if (A[i] == 0) {
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    int64_t ans = 1;
    for (int i = 0; i < N; ++i) {
        if (ans > (1000000000000000000 / A[i])) {
            std::cout << -1 << std::endl;
            return 0;
        }

        ans *= A[i];
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4400
#include <iostream>
 
using namespace std;
 
int GCD(int a, int b)
{
    if(a % b == 0) { return b; }
 
    if(b % a == 0) { return a; }
 
    if(a > b) { return GCD(a % b, b); }
 
    if(a < b) { return GCD(a, b % a); }
}
 
 
int main()
{
    int a, b;
 
    while(cin >> a >> b)
    {
int n=GCD(a,b);
        cout << n << ' ' << a/n*b << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3008
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

vector<vector<int>> g;
vector<int> as;

int solve(int cur, int parent) {
  //   cout << cur << ", " << parent << endl;

  if (g[cur].size() == 1) {
    if (parent == -1) {
      return solve(g[cur][0], cur) == as[cur] ? 0 : -1;
    }

    return as[cur];
  }

  vector<int> cs;

  for (auto &next : g[cur]) {
    if (next == parent)
      continue;
    int v = solve(next, cur);
    if (v < 0)
      return -1;

    cs.push_back(v);
  }

  int sum = 0;
  for (auto &c : cs) {
    sum += c;
  }

  int up = 2 * as[cur] - sum;

  //   cout << "**:* up " << as[cur] << ", " << sum << endl;

  if (up < 0) {
    return -1;
  }

  int conn = (sum - up) / 2;

  auto f = [&](int a, int b) {
    int t = min(a, b);
    return max(a - t, b - t);
  };

  int mi = 0, ma = 0;
  for (auto &c : cs) {
    int nmi = f(mi, c);

    nmi = min(nmi, f(ma, c));

    if (mi <= c && c <= ma) {
      int t = c;
      if (mi % 2 != t % 2) {
        t--;
      }
      if (mi <= t && t <= ma) {
        nmi = min(nmi, f(t, c));
      }
      t += 2;
      if (mi <= t && t <= ma) {
        nmi = min(nmi, f(t, c));
      }
    }

    mi = nmi;
    ma += c;
  }

  if (mi <= up && up <= ma)
    return up;

  return -1;
}

int main() {
  cin.tie(0);
  int n;
  cin >> n;

  as.resize(n);
  for (auto &a : as)
    cin >> a;

  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  auto ret = solve(0, -1);

  cout << (ret == 0 ? "YES" : "NO") << endl;

  return 0;
}

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

const int UNCALCULATED = -1;
const int MAXN = 100 + 10, MAXV = 100 * 1000 + 10;
long dp[MAXN][MAXV];
long v[MAXN], w[MAXN];

long calc(int i, int j) {
    if(j < 0)return 2e9;
    if(i == 0)
        if(j == 0)return 0;
        else return 2e9;
    if(dp[i][j] != UNCALCULATED)return dp[i][j];
    return dp[i][j] = min(w[i] + calc(i - 1, j - v[i]), calc(i - 1, j));
}

int main() {
    for(int i = 0; i < MAXN; i++) {
        for(int j = 0; j < MAXV; j++) {
            dp[i][j] = UNCALCULATED;
        }
    }
    int n, total;
    cin >> n >> total;
    for(int i = 1; i <= n; i++)cin >> w[i] >> v[i];
    for(int j = MAXV-1;j>=0;j--){
        if(calc(n,j) <= total){
            cout<<j<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

int n;
#define MAX 100005
int i_n[MAX],j_n[MAX],o_n[MAX],cnt=0;

signed main(){
	cin>>n;
	string s; cin>>s;
	s=" "+s;
	
	int j=0,o=0,i=0;
	int J=0,I=0;
	for(int k=1; k<=n; k++){
		if(s[k]=='J'){
			j++;
		}else if(s[k]=='O'){
			o++;
			I+=j;
		}else{
			i++;
			cnt+=I;
		}
		j_n[k]=j;
		i_n[k]=i;
	}
	int ii=0,oo=0;
	for(int k=n; k>=1; k--){
		if(s[k]=='I'){
			ii++;
		}else if(s[k]=='O'){
			J+=ii;
		}
	}
	
	int O=-1;
	for(int k=1; k<=n; k++){
		O=max(O, j_n[k]*(i-i_n[k]));
	}
//	cout<<cnt<<en;
//	cout<<"  "<<J<<"  "<<O<<"  "<<I<<en;
	cout<<cnt+max(J, max(O, I))<<en;
}




Measured memory_bytes: 4888
N = int(input())
Flag = False
MAXC = 0
Cout = 0
for TN in range(0,N):
    D1,D2 = (int(T) for T in input().split())
    if Flag==False and D1==D2:
        Flag = True
        Cout = 1
    elif Flag==True and D1==D2:
        Cout += 1
    elif Flag==True and D1!=D2:
        Flag = False
        MAXC = max(MAXC,Cout)
MAXC = [MAXC,max(MAXC,Cout)][Flag]
print(['No','Yes'][MAXC>=3])

Measured memory_bytes: 9204
#include<iostream>
using namespace std;
 
int main(){
 	
  int num, count = 0;
  for(int i = 0; i < 3; i++){
   	cin >> num;
    if(num == 7) count++;
  }
  if(count > 1){
    cout << "NO";
  }else cout << "YES";
}

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

#define forn(i,a,n) for(int i=a;i<(int)n;i++)
#define DRT()  int t; cin>>t; while(t--)

#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
using namespace std;

const int N = 1e3+5, MOD = 1e9+7;
vector<string> grid(N);
int dp[N][N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	forn(i,0,h){
		cin>>grid[i];
	}
	dp[0][0] = 1;
	forn(i,1,h){
		if(grid[i][0] == '#')
			dp[i][0] = 0;
		else
			dp[i][0] = dp[i-1][0];
	}
	forn(i,1,w){
		if(grid[0][i] == '#')
			dp[0][i] = 0;
		else
			dp[0][i] = dp[0][i-1];
	}
	forn(i,1,h){
		forn(j,1,w){
			if(grid[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
		}
	}
	cout<<dp[h-1][w-1]<<endl;

}
	
	



Measured memory_bytes: 5248
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
void sieve(ve <bool> &prime)
{
    ll n = 1000000;
    prime[0] = false;
    prime[1] = false;
    for (ll p = 2; p * p <= n; p++)
        if (prime[p] == true)
        {
            for (ll i = p * p; i <= n; i += p)
                prime[i] = false;
        }
}
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll x;
    cin>>x;
    ve <bool> prime(1e6+5,true);
    sieve(prime);
    rep (i,x,1e6+1)
    {
        if (prime[i])
        {
            cout<<i<<"\n";
            bb;
        }
    }

}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

struct Segment_Tree
{
	struct treenode
	{
		int left,right,num;
	};
	
	treenode tree[6000000];
	int sum_node;
	
	inline void clear()
	{
		memset(tree,0,sizeof(tree));
		sum_node=0;
		return;
	}
	
	inline void inserttree(int l,int r,int x,int& node)
	{
		if (! node)
			sum_node++,node=sum_node;
		tree[node].num++;
		if (l!=r)
		{
			int mid=(l+r)>>1;
			if (x<=mid)
				inserttree(l,mid,x,tree[node].left);
			else
				inserttree(mid+1,r,x,tree[node].right);
		}
		return;
	}
	
	inline int asktree(int l,int r,int x,int y,int node)
	{
		if ((l==x) && (r==y))
			return tree[node].num;
		int mid=(l+r)>>1;
		if (y<=mid)
			return asktree(l,mid,x,y,tree[node].left);
		if (x>mid)
			return asktree(mid+1,r,x,y,tree[node].right);
		return asktree(l,mid,x,mid,tree[node].left)+asktree(mid+1,r,mid+1,y,tree[node].right);
	}
};

Segment_Tree T0,T1;
int root0,root1;

int x[300000],y[300000];
int i,j,n,s,t;

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for (i=1;i<=n;i++)
		scanf("%d",&y[i]);
	for (i=1;i<=29;i++)
	{
		T0.clear(),T1.clear();
		root0=0,root1=0;
		for (j=1;j<=n;j++)
			if (x[j]&(1<<(i-1)))
				T1.inserttree(0,(1<<(i-1))-1,x[j]&((1<<(i-1))-1),root1);
			else
				T0.inserttree(0,(1<<(i-1))-1,x[j]&((1<<(i-1))-1),root0);
		t=0;
		for (j=1;j<=n;j++)
		{
			if (y[j]&(1<<(i-1)))
			{
				if ((1<<(i-1))-(y[j]&((1<<(i-1))-1))<=(1<<(i-1))-1)
					t=t^T1.asktree(0,(1<<(i-1))-1,(1<<(i-1))-(y[j]&((1<<(i-1))-1)),(1<<(i-1))-1,root1);
				if (0<=(1<<(i-1))-1-(y[j]&((1<<(i-1))-1)))
					t=t^T0.asktree(0,(1<<(i-1))-1,0,(1<<(i-1))-1-(y[j]&((1<<(i-1))-1)),root0);
			}
			else
			{
				if (0<=(1<<(i-1))-1-(y[j]&((1<<(i-1))-1)))
					t=t^T1.asktree(0,(1<<(i-1))-1,0,(1<<(i-1))-1-(y[j]&((1<<(i-1))-1)),root1);
				if ((1<<(i-1))-(y[j]&((1<<(i-1))-1))<=(1<<(i-1))-1)
					t=t^T0.asktree(0,(1<<(i-1))-1,(1<<(i-1))-(y[j]&((1<<(i-1))-1)),(1<<(i-1))-1,root0);
			}
		}
		if (t&1)
			s=s|(1<<(i-1));
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 142720
use std::io;

fn main() {
    let mut card = Vec::new();
    let mut flag = vec![false; 9];
    for _ in 0..3 { card.push(read::<usize>()); }
    let n = read_one::<usize>();
    for _ in 0..n {
        let b = read_one::<usize>();
        for i in 0..3 {
            for j in 0..3 {
                if card[i][j] == b { flag[i + j * 3] = true; }
            }
        }
    }

    let bingo = vec![
        vec![0, 1, 2],
        vec![3, 4, 5],
        vec![6, 7, 8],
        vec![0, 3, 6],
        vec![1, 4, 7],
        vec![2, 5, 8],
        vec![0, 4, 8],
        vec![2, 4, 6],
    ];

    for i in 0..bingo.len() {
        if bingo[i].iter().all(|&j| flag[j]) {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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


ll arr[100009];

int main(){
	int n;
	cin>>n;
	int ans = -1;
	for(ll i = 0 ; i < n ; i++){
		
		cin>>arr[i];
		if(arr[i] == 0) ans = 0;
	}
		
	if(ans == 0) cout<<"0\n";
	else {
		ll div = 1000000000000000000;
		ll mul = 1;
		for(int i = 0 ; i < n; i++) {
			div /= arr[i];
			if(div <= 0) {
				cout<<"-1\n"<<endl;
				return 0;
			}
			mul *= arr[i];
		}
		cout<<mul<<endl;
		
	}
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	cout<<(n+1)/2<<endl;
}

Measured memory_bytes: 256
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

// static const ll kIntMax = numeric_limits<ll>::infinity();
static const ll kIntMax = 0x7FFFFFFFFFFFFFFF;
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  ll n;
  cin >> n;
  VI dp = VI(n + 1, 0);
  ll min = 0;

  for (ll i = 0; i <= n; i++) {
    min = kIntMax;
    if (i < 6) {
      dp[i] = i;
      continue;
    }

    for (ll tmp = 6; tmp <= i; tmp *= 6) {
      min = (dp[i - tmp] + 1ll < min) ? dp[i - tmp] + 1ll : min;
    }
    for (ll tmp = 9; tmp <= i; tmp *= 9) {
      min = (dp[i - tmp] + 1ll < min) ? dp[i - tmp] + 1ll : min;
    }
    dp[i] = min;
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 1024
N,M = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
良い展望台です = [true]*N
$<.each{|ln|
	a,b = ln.split.map{|_| _.to_i-1 }
	良い展望台です[a] = false if H[a] <= H[b]
	良い展望台です[b] = false if H[b] <= H[a]
}
p 良い展望台です.count(true)

Measured memory_bytes: 22692
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  int n;
  cin>>n;
  v(string) s(n);
  rep(i,n) {
    cin>>s[i];
  }
  string t="abcdefghijklmnopqrstuvwxyz";
  vi T(26,100);
  vi a(26);
  rep(i,n){
    rep(j,len(s[i])){
      rep(k,26){
        if(s[i][j]==t[k]) a[k]++;
      }
    }
    rep(j,26){
      mins(T[j],a[j]);
    }
    rep(j,26){
      a[j]=0;
    }
  }
  rep(i,26){
    rep(j,T[i]){
      cout<<t[i];
    }
  }
  cout<<endl;
}

Measured memory_bytes: 3644
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };

ll gcd(ll a, ll b) {
	ll t;    // 補助変数
	while (b != 0) {          // 他方が0になるまで
		t = a % b; a = b; b = t;    // 一方を剰余に置き換える
	}
	return a;                   // 他方が0になったときの一方がGCD
}


int main(void) {

	int n;
	string t;
	int count = 0;//必ず↑
	int point = 0;

	cin >> n;
	vector<string> s(n + 1), tmp(n + 1);

	FOR(i, 1, n) {
		cin >> s[i];
		tmp[i] = s[i];
	}
	cin >> t;

	FOR(i, 1, n) {
		if (s[i].find("?") == -1) {
			if (s[i] < t) {
				count++;
			}
			else if (s[i] == t) {
				point++;
			}
		}
		else {
			FOR(j, 0, s[i].size() - 1) {
				if (s[i][j] == '?') {
					s[i][j] = 'a';
					tmp[i][j] = 'z';
				}
			}
			//cout << i << " ";
			if (s[i] == t) {
				//cout << "a" << endl;
				point++;
			}
			else if (s[i] > t) {
				//cout << "b" << endl;
			}
			else {
				if (tmp[i] >= t) {
					//cout << "c" << endl;
					point++;
				}
				else {
					count++;
					//cout << "d" << endl;
				}
			}
		}
	}
	
	FOR(i, 0, point) {
		cout << count + i+1;
		if (i != point) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    ll i;
    for(i = 1;i * i <= N;i++);
    i--;
    cout << i * i << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;
template<int mod> class ModInt
{
 private:
    lint val;
 public:
    lint value(){ return val; }
    ModInt(lint x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};
using mint=ModInt<1000000007>;

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

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

   int n,a,b; cin>>n>>a>>b;

   mint ans=mint(2).pow(n)-1;
   ans-=comb(n,a);
   ans-=comb(n,b);
   cout<<ans.value()<<endl;
   return 0;
}



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

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> counter;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        counter[a]++;
    }
    int ans = 0;
    for (auto p: counter) {
        if (p.first > p.second) {
            ans += p.second;
        } else {
            ans += p.second - p.first;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  int A = 1;  
  for (int i = 0; i < N; i++) {
    if (A + K >= 2 * A) {
    A *= 2; }
    else {
    A += K; }
  }
  cout << A << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int N = (int)S.size();
  vector<int>s(N);
  for (int i = 0; i < N; i ++) {
    s[i] = (int)S[i] - (int)'a';
  }
  int ans = 1100;
  vector<int>t(N);
  int si;
  for (int i_ = 0; i_ < 26; i_ ++) {
    for (int i = 0; i < N; i ++) t[i] = s[i];
    si = N;
    while (si > 0) {
      bool ok = true;
      for (int i = 0; i < si; i ++) {
        if (t[i] != i_) ok = false;
      }
      if (ok) {
        break;
      }
      si --;
      for (int i = 0; i < si; i ++) {
        if (t[i + 1] == i_) t[i] = t[i + 1];
      }
    }
    ans = min(ans, N - si);
  }
  cout << ans << endl;
}



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

int main(void){
  std::string str;
  getline(std::cin,str);
  std::istringstream iss(str);
  std::stack<int> stack;
  while(iss >> str){
    if(std::all_of(str.cbegin(),str.cend(),isdigit))stack.push(std::stoi(str));
    else {
      int t=0;
      int a=stack.top();stack.pop();
      int b=stack.top();stack.pop();
      if(str=="+")t=b+a;
      if(str=="-")t=b-a;
      if(str=="*")t=b*a;
      stack.push(t);
    }
  }
  std::cout<<stack.top()<<std::endl;
  return 0;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    ll R = 0;
    ll G = 0;
    ll B = 0;
    ll tmp_R = 0;
    ll tmp_G = 0;
    ll tmp_B = 0;
    REP(i, N) {
        if(S[i] == 'R') R++;
        if(S[i] == 'G') G++;
        if(S[i] == 'B') B++;
    }

    ll cnt = 0;

    for(int i = 0; i < N - 2; ++i) {
        tmp_R = R;
        tmp_G = G;
        tmp_B = B;
        for(int j = i + 1; j < N - 1; ++j) {
            if((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
                if(j + (j - i) < N && S[j + (j - i)] == 'B') {
                    cnt = cnt + tmp_B - 1;
                } else {
                    cnt = cnt + tmp_B;
                }
            } else if((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
                if(j + (j - i) < N && S[j + (j - i)] == 'G') {
                    cnt = cnt + tmp_G - 1;
                } else {
                    cnt = cnt + tmp_G;
                }
            } else if((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B')) {
                if(j + (j - i) < N && S[j + (j - i)] == 'R') {
                    cnt = cnt + tmp_R - 1;
                } else {
                    cnt = cnt + tmp_R;
                }
            }

            if(S[j] == 'R') tmp_R--;
            if(S[j] == 'G') tmp_G--;
            if(S[j] == 'B') tmp_B--;
        }

        if(S[i] == 'R') R--;
        if(S[i] == 'G') G--;
        if(S[i] == 'B') B--;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3632
n,m=map(int,input().split())
mx =[-1 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b-1]=max(mx[b-1],a-1)
cut=-1
cn=0
for z in range(0,n):
	if cut<mx[z]:
		cut=z-1
		cn=cn+1
print(cn)

Measured memory_bytes: 6040
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
constexpr long long INF = 1LL << 60;
constexpr long long MOD = 998244353;

int n, q, x, y;
string s;
long long a[6060];

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i)
    cin >> s[i];

  vector<vector<int>> L(h + 5, vector<int>(w + 5));
  vector<vector<int>> R(h + 5, vector<int>(w + 5));
  vector<vector<int>> U(h + 5, vector<int>(w + 5));
  vector<vector<int>> D(h + 5, vector<int>(w + 5));
  for (size_t i = 0; i < h; i++)
  {
    for (size_t j = 0; j < w - 1; j++)

      if (s[i][j] == '.')
        L[i][j + 1] = L[i][j] + 1;

    for (size_t j = w - 1; j > 0; j--)
      if (s[i][j] == '.')
        R[i][j - 1] = R[i][j] + 1;
  }

  for (size_t j = 0; j < w; j++)
  {
    for (size_t i = 0; i < h - 1; i++)
      if (s[i][j] == '.')
        U[i + 1][j] = U[i][j] + 1;

    for (size_t i = h - 1; i > 0; i--)
      if (s[i][j] == '.')
        D[i - 1][j] = D[i][j] + 1;
  }

  int ans = 0;
  for (size_t i = 0; i < h; i++)
  {
    for (size_t j = 0; j < w; j++)
    {
      if (s[i][j] == '.')
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1);
    }
  }
  cout << ans;

  return 0;
}


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

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

int main(){
	ll K,T; cin>>K>>T;
	vector<ll>A(T);
	ll sum=0,ans=0;
	rep(i,T){
		cin>>A[i];
		sum+=A[i];
	}
	rep(i,T){
		if(sum-A[i]<A[i]-1) ans+=A[i]*2-1-sum;
	}
	cout<<ans;
}

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

lli n, a, b;

int main(void){
	cin >> n >> a >> b;
	if(a > b || (n == 1)&&(a != b)){
		cout << 0 << endl;
		return 0;
	}
	lli x = (n-1)*b+a;
	lli y = (n-1)*a+b;
	cout << x-y+1 << endl;
	return 0;
}


Measured memory_bytes: 3592
#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 all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    vvint m(M); // m[i] = 言語iを話す人の配列
    for (size_t i = 0; i < N; i++)
    {
        int k;
        cin >> k;
        for (size_t j = 0; j < k; j++)
        {
            int L;
            cin >> L;
            L--;
            m[L].push_back(i);
        }
    }
    for (size_t i = 0; i < M; i++)
    {
        for (auto &&j : m[i])
        {
            uf.unite(m[i][0], j);
        }
    }
    cout << ((uf.size(0) == N) ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 4608
N = int(input())
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = 0
for i in range(N):
    C += min(A[i]+A[i+1], B[i])
    A[i+1] += min(A[i] - B[i], 0)
    if A[i+1] < 0:
        A[i+1] = 0
print(C)

Measured memory_bytes: 18624
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
	    long n = sc.nextLong();
		int x = sc.nextInt();
		int m = sc.nextInt();
		int[] list = new int[m];
		list[0] = x;
		HashMap<Long, Integer> hm = new HashMap<Long, Integer>();
		int from = 0;
		int to = 0;
		hm.put((long)x, 0);
		for(int i = 1; i < m; i++){
		    long tmp = (long)(list[i-1]%m)*(list[i-1]%m)%m;
		    if(hm.containsKey(tmp)){
		        from = hm.get(tmp);
		        to = i-1;
		        break;
		    }else{
		        list[i] = (int)tmp;
		        hm.put(tmp, i);
		    }
		}
		//System.out.println(Arrays.toString(list));
		//System.out.println("from:" + from);
		//System.out.println("to:" + to);
		
		// 計算
		long result = 0;
		for(int i = 0; i < from; i++){
		    result += list[i];
		}
		int cnt = to - from + 1;
		long sum  = 0;
		for(int i = from; i <= to; i++){
		    sum += list[i];
		}
		result += (n - from)/cnt*sum;
		for(int i = 0; i < (n - from)%cnt; i++){
		    result += list[i+from];
		}
		
		
		// 出力
		System.out.println(result);
		
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 32668
package main

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

func mergeSort(elems []int) ([]int, int) {
	if len(elems) <= 1 {
		return elems, 0
	}
	left := 0
	right := len(elems) - 1
	mid := (left + right) / 2
	sortedL, countL := mergeSort(elems[left : mid+1])
	sortedR, countR := mergeSort(elems[mid+1 : right+1])
	sorted := make([]int, len(elems))
	i := 0
	count := 0
	for len(sortedL) > 0 && len(sortedR) > 0 {
		if sortedL[0] <= sortedR[0] {
			sorted[i] = sortedL[0]
			sortedL = sortedL[1:]
		} else {
			count += len(sortedL)
			sorted[i] = sortedR[0]
			sortedR = sortedR[1:]
		}
		i++
	}
	if len(sortedL) > 0 {
		for _, v := range sortedL {
			sorted[i] = v
			i++
		}
	} else {
		for _, v := range sortedR {
			sorted[i] = v
			i++
		}
	}
	return sorted, count + countL + countR
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}
	_, inversions := mergeSort(elems)
	fmt.Println(inversions)
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	rs := make([]int, n)
	for i, _ := range rs {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		rs[i] = x
	}
	return rs, nil
}



Measured memory_bytes: 10644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int x3,y3,x4,y4;
    x3=x2-y2+y1;
    y3=y2+x2-x1;
    x4=x1+y1-y2;
    y4=y1-x1+x2;
    
    
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}


Measured memory_bytes: 256
# TODO:review test cases (https://www.dropbox.com/sh/arnpe0ef5wds8cv/AAAk_SECQ2Nc6SVGii3rHX6Fa?dl=0)

n = int(input())
Strings = [input() for _ in range(n)]

# f = open('sub1_19.txt')
# n = int(f.readline().replace('\n',''))
# Strings = [f.readline().replace('\n','') for _ in range(n)]

dic = {}

for s in Strings:
    if s not in dic.keys():
        dic[s] = 1
    else:
        dic[s] += 1

maxValue = max(dic.values())
ans = []

for s in dic:
    if dic[s] == maxValue:
        ans.append(s)

ans.sort()
for s in ans:
    print(s)

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

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;

    sort(a.begin(), a.end());
    ans += a[a.size() - 1];
    ll cnt = 2;
    int pos = a.size() - 2;
    while (cnt < n) {

        rep(i, 2) {
            ans += a[pos];
            cnt++;
            if (cnt == n) break;
        }
        pos--;
    }

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

Measured memory_bytes: 4808
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;


typedef long long int ll;

int A, P;

int main() {
	cin >> A >> P;
	int sum = A * 3 + P;
	cout << sum / 2 << endl;


}

Measured memory_bytes: 256
//🅰🅸🅸🆂🅼🅴
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <numeric>
#include <stdlib.h>

using namespace std;

typedef long long ll;

const int AI1 = 10005;
const int AIMAX = 1e6 + 1;

int main()
{
    int n; cin >> n;
    int l[n];
    int r[n];
    for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
    sort(l, l + n);
    sort(r, r + n);
    cout << r[0] + l[0] - 1 + l[n - 1] - l[0] + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
d = Counter(A)
Q = int(input())
ans = sum(A)
for i in range(Q):
    b, c = map(int, input().split())
    ans += (c-b) * d[b]
    d[c] += d[b]
    d[b] = 0
    print(ans)

Measured memory_bytes: 23964
import collections
 
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
s=set()
cnt=collections.Counter(arr)
 
for i in range(n):
 if arr[i] in s:
   continue
 if cnt[arr[i]]>=2:
   s.add(arr[i])
 for j in range(2,10**6//arr[i]+1):
   s.add(arr[i]*j)
ans=0
for i in range(n):
 if arr[i] in s:
   continue
 ans+=1
 
print(ans)

Measured memory_bytes: 103036
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef long long ll;
 
using namespace std;

int main(){
  int N,Ma,Mb;
  cin >> N >> Ma >> Mb ;
  int a[N],b[N],cost[N];
  int dp[41][450][450];
  rep(i,41){
    rep(j,450){
      rep(k,450)  dp[i][j][k]=INF;
    }
  }
  int ans=INF;
  
  dp[0][0][0]=0;
  rep(i,N){
    cin >> a[i] >> b[i] >> cost[i];
  }
  rep(i,N){
    rep(j,400){
      rep(k,400){
        if(dp[i][j][k]==INF) continue;
        dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
        dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+cost[i]);
      }
    }
  }
  int ta=Ma,tb=Mb;
  do{
    ans=min(ans,dp[N][ta][tb]);
    ta+=Ma;
    tb+=Mb;
  }while(ta<=400&&tb<=400);
  if(ans==INF){
    cout << "-1" << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    int N, K;
    int a[110]; 
    cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> a[i];
    sort(a, a + N, greater<int>());
    int L = 0; 
    for (int i = 0; i < K; ++i)
      L += a[i]; 
    cout << L << endl;
}

Measured memory_bytes: 256
n=gets.chomp.to_i

t=Array.new(n){Array.new(n)} # t[i][j]:=i->j
t[0][0]=0
(1...n).each do |i|
  c, s, f=gets.split.map(&:to_i)
  t[i][i]=0
  i.times do |j|
    k=[0, (t[j][i-1]-s+(f-1))/f].max
    t[j][i]=s+f*k+c
  end
end

n.times{|j| puts t[j][n-1]}

Measured memory_bytes: 3708
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  if num+B < M:
    money += A*B
    num += B
  elif num+B == M:
    money += A*B
    break
  elif num+B > M:
    money += A*(M-num)
    break
print(int(money))

Measured memory_bytes: 23008
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int x,y;
    cin >> x >> y;
    int ans=0;
    if(x==y && x==1)ans=400000;
    int value[3]={300000,200000,100000};
    if(x<=3)ans+=value[x-1];
    if(y<=3)ans+=value[y-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
const int MAXN = 201010;
const int mod = 998244353;
char ch[MAXN];
LL dp[4][4], roll[4][4];
int sum, flag = 1;

LL x = 1, y, ans = 1;
int main(){
    scanf("%s", ch);
    for(int i = 0; ch[i]; i ++){
        sum += ch[i] - 'a',sum %= 3;
        if(ch[i] != ch[0])
            flag = 0;
    }
    if(flag){
        printf("1");
        return 0;
    }
    else if(strlen(ch) == 3){
        if(ch[0] == ch[2])
            ans = 7;
        int cnt = 0;
        if(ch[0] != ch[1])
            cnt ++;
        if(ch[2] != ch[1])
            cnt ++;
        if(ch[0] != ch[2])
            cnt ++;
        if(cnt == 3){
            ans = 3;
        }
        if(ans != 7 && cnt == 2){
            ans = 6;
        }
        printf("%d", ans);
        return 0;
    }
    dp[0][0] = dp[1][1] = dp[2][2] = 1;
    for(int i = 1; ch[i]; i ++){
        for(int j = 0; j < 3; j ++){
            for(int k = 0; k < 3; k ++){
                for(int p = 0; p < 3; p ++){
                    if(k == p)
                        continue;
                    roll[(j+p)%3][p] += dp[j][k];
                }
            }
        }
        for(int j = 0; j < 3; j ++){
            for(int k = 0; k < 3; k ++){
                dp[j][k] = roll[j][k] % mod;
                roll[j][k] = 0;
            }
        }
    }
    for(int i = 1; ch[i]; i ++){
        x *= 3;
        x %= mod;
        if(ch[i] == ch[i-1])
            ans = 0;
    }
    for(int i = 0; i < 3; i ++){
        y += dp[sum][i];
        y %= mod;
    }
    ans += x - y + mod;
    ans %= mod;
    printf("%lld", ans);
}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	int n;
	cin >> n;
	ll a[n],x,y;
	ll sum=0;
	FOR(i,n){
		cin >> x >> y;
		a[i]=x+y;
		sum+=-y;
	}
	sort(a,a+n);
	int i=n-1;
	while(i >= 0){
		sum+=a[i];
		i-=2;
	}
	cout << sum;


	return 0;
}

Measured memory_bytes: 4292
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():
	m,d = LI()
	print(m if m <= d  else m-1)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3444
# https://atcoder.jp/contests/abc083/tasks/abc083_b


N, A, B = gets.split.map(&:to_i)

vs = (1..N).select do |i|
  k = i.to_s.chars.map(&:to_i).reduce(&:+)
  k.between?(A, B)
end
ans = vs.reduce(&:+)

puts ans


Measured memory_bytes: 1916