akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n;
	cin >> n;
	cout << (1110-n) << endl;
	return 0;
}


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

string itos(int n){
	stringstream ss;
	ss << n;
	return ss.str();
}
string table = "mcxi";
int value[] = {1000,100,10,1};

int from(string s){
	int num = 0;
	int ans = 0;
	for(int i = 0 ; i < s.size() ; i++){
		if(~table.find(s[i])){
			int p = table.find(s[i]);
			if(num == 0) num = 1;
			ans += value[p] * num;
			num = 0;
		}else{
			num = num * 10 + s[i] - '0';
		}
	}
	return ans + num;
}
string to(int n){
	string ans = "";
	for(int i = 0 ; i < 4 ; i++){
		int g = n / value[i];
		if(g > 1) ans += itos(g);
		if(g >= 1) ans += table[i];
		n -= g * value[i];
	}
	return ans;
}
int main(){
	int T; cin >> T;
	while(T--){
		string a,b;
		cin >> a >> b;
		cout << to(from(a)+from(b)) << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int ans=0;
  rep(i,a+1)rep(j,b+1)rep(k,c+1)
    if(i*500+j*100+k*50 == x)ans++;
  cout<<ans<<endl;

}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  int64_t ret = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ret += d.at(i) * d.at(j);
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int time[10001][1300];
int login[10001];

int main(void){
	int i,j,k;
	int N,M;
	int r,t,n,m,s;
	int q,ts,te;
	int ans,before;

	while(scanf("%d%d",&N,&M),N||M){
		scanf("%d",&r);
		memset(time,0,sizeof(time));
		before = 0;
		for(i=0;i<r;i++){
			scanf("%d%d%d%d",&t,&n,&m,&s);

			for(j=1;j<=10000;j++){
				if(login[j] > 0){
					for(k=t-1;k>=before;k--){
						time[j][k] = 1;
					}
				}
			}
			before = t;

			if(s == 0) login[m]--;
			else login[m]++;
		}

		scanf("%d",&q);
		for(i=0;i<q;i++){
			scanf("%d%d%d",&ts,&te,&m);
			ans = 0;
			for(j=ts;j<te;j++){
				ans += time[m][j];
			}
			printf("%d\n",ans);
		}
	}

	return 0;
}

Measured memory_bytes: 50000
def calc(N, X, Y):
    X -= 1
    Y -= 1
    d = {i: 0 for i in range(N)}
    for i in range(N):
        for j in range(i, N):
            e = min(
                abs(j - i),
                abs(X - i) + 1 + abs(Y - j),
                abs(Y - i) + 1 + abs(X - j)
                )
            d[e] += 1
    ans = '\n'.join([str(d[i]) for i in range(1, N)])
    return ans



(N, X, Y) = tuple([int(s) for s in input().split()])
print(calc(N, X, Y))

Measured memory_bytes: 3380
/*
ID: mckibbe1
TASK: money
LANG: C++11
*/
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#define MAXN 100001
using namespace std;
int arr[MAXN][3];
int dp[MAXN][3];
int main() {
	//freopen("cardgame.in", "r", stdin);
	//freopen("cardgame.out", "w", stdout);
	//freopen("file.in", "r", stdin);
	//freopen("file.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie();
	int N; cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	for (int i = 1; i <= N; i++) {
		for (int q = 0; q < 3; q++) {
			dp[i][q] = max(dp[i - 1][(q + 1) % 3] + arr[i][q], dp[i - 1][(q + 2) % 3] + arr[i][q]);
		}
	}
	cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n, c;
	int dp[];
	int max=0;
	int value[][];
	void run() {
		Scanner sc = new Scanner(System.in) ;
		for(;sc.hasNext();) {
			n = sc.nextInt();
			c = sc.nextInt();
			value = new int[n][4];
			max = 0;
			for(int i=0;i<n;i++) {
				while(!sc.hasNextInt())sc.next();
				for(int j=0;j<4;j++) value[i][j] = sc.nextInt();
			}
			for(int i=1;i<=3;i++) {
				dp = new int [c+1];
				fill(dp, -1);
				dp[0] = 0;
				for(int j=0;j<=c;j++) for(int k=0;k<n;k++) {
					if(dp[j]>=0 && j+value[k][0]<=c) dp[j+value[k][0]] = max(dp[j+value[k][0]], dp[j] + value[k][i]);
				}
				for(int j=c;j>=0;j--) {
					if(dp[j]>0) {
						max = max(max, dp[j]);
					}
				}
			}
			System.out.println(max);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

int main(){

	double a, b, x;
	cin >> a >> b >> x;

	double theta;
	if ((a*a*b/2) < x) {
		double h = 2.0 * (b - (x / (a*a)) );
		theta = atan(h/a);
	} else {
		double h = 2*x/(b*a);
		theta = atan(b/h);
	}

	cout << fixed;
	cout << setprecision(10) <<  theta * 180.0 / M_PI << endl; 


	return 0;
}



Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,K,S;cin>>N>>K>>S;
    if(S==1e9){
        REP(i,K)cout<<S<<" ";
        REP(i,N-K)cout<<1<<(i==N-K-1?"\n":" ");
    }
    else{
        REP(i,K)cout<<S<<" ";
        REP(i,N-K)cout<<S+1<<(i==N-K-1?"\n":" ");
    }
}

Measured memory_bytes: 1280
//saw

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,s=0,in;
  cin>>n;
  int a[n+2]={0};
  for(i=1;i<=n;i++){
    cin>>in;
    a[i]=in;
    s+=abs(a[i-1]-a[i]);
  }
  s+=abs(a[n]-a[n+1]);
  for(i=1;i<=n;i++){
    cout<<s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1])<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n,mod;
int dp[505][255];
pair<int,int> a[505];

int mul(int a,int b)
{
	return (1LL*a*b)%mod;
}

int add(int a,int b)
{
	int t=a+b;
	if(t>=mod) t-=mod;
	return t;
}

int sub(int a,int b)
{
	int t=a-b;
	if(t<0) t+=mod;
	return t;
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>mod;
	for(int i=0;i<n;i++)
	{
		for(int x=0;x<2*n;x++)
		{
			if(x*x+i*i>=n*n) break;
			a[i].first=x;
		}
		for(int x=0;x<2*n;x++)
		{
			if(x*x+i*i>4*n*n) break;
			a[i].second=x;
		}
	}
	for(int i=n;i<2*n;i++)
	{
		for(int x=0;x<2*n;x++)
		{
			if(x*x+i*i>4*n*n) break;
			a[i].first=x;
		}
		a[i].second=-1;
	}
	sort(a,a+2*n);
//	for(int i=0;i<2*n;i++)
//	{
//		cout<<a[i].first<<' '<<a[i].second<<endl;
//	}
	int res=0;
	for(int k=0;k<=n;k++)
	{
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int i=0;i<2*n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				if(a[i].second==-1)
				{
					dp[i+1][j]=add(dp[i+1][j],mul(dp[i][j],max(0,a[i].first+1-(i-j))));
				}
				else
				{
					dp[i+1][j+1]=add(dp[i+1][j+1],mul(dp[i][j],max(0,a[i].second+1-(2*n-k+j))));
					dp[i+1][j]=add(dp[i+1][j],mul(dp[i][j],max(0,a[i].first+1-(i-j))));
				}
			}
		}
		if((n-k)&1) res=sub(res,dp[2*n][k]);
		else res=add(res,dp[2*n][k]);
//		cout<<dp[2*n][k]<<endl;
	}
	cout<<res<<endl;
//	if(!(n&1)) cout<<res<<endl;else cout<<sub(0,res)<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct Data
{
	int p[3], r;
};

int main()
{
	int a, b, c;
	while(scanf("%d%d%d", &a, &b, &c), a){
		int n;
		scanf("%d", &n);
		vector<int> state(a+b+c, 2);
		vector<Data> d(n);
		
		for(int i=0; i<n; ++i){
			for(int j=0; j<3; ++j){
				scanf("%d", &d[i].p[j]);
				d[i].p[j]--;
			}
			scanf("%d", &d[i].r);
			
			if(d[i].r == 1){
				for(int j=0; j<3; ++j)
					state[d[i].p[j]] = 1;
			}
		}
		
		for(int i=0; i<n; ++i){
			if(d[i].r == 0){
				for(int j=0; j<3; ++j){
					if(state[d[i].p[j]]==1 && state[d[i].p[(j+1)%3]]==1 && state[d[i].p[(j+2)%3]]==2){
						state[d[i].p[(j+2)%3]] = 0;
						break;
					}
				}
			}
		}
		
		for(int i=0; i<a+b+c; ++i)
			printf("%d\n", state[i]);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn = 1e5 + 10;
inline int gcd(int x, int y) {return !y ? x : gcd(y, x % y);}
int n, m, ps, pt; char s[maxn], t[maxn]; map<ll, char> vis;
int main()
{
	n = read(), m = read();
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	ll ans = (ll)n / gcd(n, m) * m;
	ps = pt = 1; int lens = ans / n;
	for(int i = 1; i <= n; i ++)
		vis[ps] = s[i], ps += lens;
	int lent = ans / m;
	for(int i = 1; i <= m; i ++)
	{
		if(vis.count(pt) && vis[pt] != t[i])
			return puts("-1"), 0;
		pt += lent;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll l;cin>>l&&l;){
		vl as(l);
		rep(i,l) cin>>as[i];
		vvl dp(l+1,vl(5,INF));
		dp[0]=vl(5);

		rep(i,l){
			ll a=as[i];
			vl xs={a,a==0?2:a%2,(a+1)%2,a==0?2:a%2,a};
			rep(j,5) repi(k,j,5)
				chmin(dp[i+1][k],dp[i][j]+xs[j]);
		}
		cout<<*min_element(all(dp[l]))<<endl;
	}
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int
struct ufind {
  struct node {
    int par, rank, size;
    void init(int i) {
      par = i;
      rank = 0;
      size = 1;
    }
  };
  vector<node> nodes;
  ufind(int n) {
    nodes.resize(n);
    rep(i, n) nodes[i].init(i);
  }
  int find(int x) {
    return nodes[x].par == x ? x : (nodes[x].par = find(nodes[x].par));
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (nodes[x].rank < nodes[y].rank) {
      nodes[x].par = y;
      nodes[y].size += nodes[x].size;
    } else {
      nodes[y].par = x;
      if (nodes[x].rank == nodes[y].rank)
        nodes[x].rank++;
      nodes[x].size += nodes[y].size;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return nodes[find(x)].size; }
};
int f[505 * 505] = {};

int N;
void dump_grid() {
  return;
  // rep(i, N) rep(j, N) {
  //   cout << f[i * N + j] << " ";
  //   if (j == N - 1)
  //     cout << endl;
  // }
}
signed main() {
  cin >> N;
  auto get = [=](int x, int y) {
    if (x < 0 || x >= N || y >= N || y < 0)
      return N * N;
    return x * N + y;
  };
  ufind uf(N * N + 1);
  vector<int> P(N * N + 1);
  vector<int> used(N * N + 1);

  rep(i, N) rep(j, N) { f[get(i, j)] = min({i, j, N - i - 1, N - j - 1}); }
  int ret = 0;
  used[N * N] = true;
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, 1, 0, -1};
  map<int, int> hoge;
  rep(i, N * N) {
    cin >> P[i];
    P[i]--;
    // hoge[P[i]] = i;
  }
  rep(i, N * N) {
    int X = P[i] / N;
    int Y = P[i] % N;
    queue<pair<int, int>> que;
    ret += f[get(X, Y)];
    used[P[i]] = true;
    rep(j, 4) {
      int nx = X + dx[j];
      int ny = Y + dy[j];
      que.push(make_pair(nx, ny));
    }
    while (!que.empty()) {
      auto [cX, cY] = que.front();
      que.pop();
      bool change = false;
      rep(j, 4) {
        int nx = cX + dx[j];
        int ny = cY + dy[j];
        change |=
            chmin(f[get(cX, cY)], f[get(nx, ny)] + (used[get(nx, ny)] ? 0 : 1));
      }
      if (change) {
        rep(j, 4) {
          int nx = cX + dx[j];
          int ny = cY + dy[j];
          que.push({nx, ny});
        }
      }
    }
    dump_grid();
  }
  cout << ret << endl;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define EB				emplace_back

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

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

vector<int> G[120];
int dp[100][100];

signed main() {
	fill( dp[0], dp[100], 0 );

	int cnt = 0;
	string s;
	while( getline( cin, s ) ) {
		for( int i = 0; i < s.size(); i += 2 ) {
			if( s[i + 1] == ',' || i == s.size() - 1 ) {
				G[cnt].EB( s[i] - '0' );
			} else {
				G[cnt].EB( ( s[i] - '0' ) * 10 + s[i + 1] - '0' );
				i++;
			}
		}
		cnt++;
	}

	dp[0][0] = G[0][0];
	REP( i, cnt ) {
		REP( j, G[i + 1].size() ) {
			int add = G[i + 1][j];
			
			if( i + 1 <= cnt / 2 ) {
				if( j == 0 ) {
					dp[i + 1][j] = dp[i][j] + add;
				} else if( j == G[i + 1].size() - 1 ) {
					dp[i + 1][j] = dp[i][G[i].size() - 1] + add;
				} else {
					dp[i + 1][j] = max( dp[i][j - 1], dp[i][j] ) + add;
				}
			} else {
				dp[i + 1][j] = max( dp[i][j], dp[i][j + 1] ) + add;
			}
			
		}
	}

	cout << dp[cnt - 1][0] << endl;
	

}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

ll cal(vector<pii>& v){
	ll rtn =0;
	priority_queue<int> pq;
	int m = sz(v);
	vector<VI> kh(m+2);
	for(auto x: v) kh[min(x.first, m)].push_back(x.second);
	
	repr(i, m, 1) {
		for(auto w: kh[i]) pq.emplace(w);
		if(sz(pq)){
			rtn += pq.top();
			pq.pop();
		}
	}
	return rtn;
}

void solove(){
	int n; cin >>n;
	vector<pii> lf, rg;
	ll ans = 0;
	rep(i, n){
		int k, l, r;
		cin >>k >>l >>r;
		if(l >r){
			lf.emplace_back(k, l-r);
		}else if(l < r){
			rg.emplace_back(n-k, r-l);
		}
		ans += min(l, r);
	}
	
	ans += cal(lf) + cal(rg);
	cout << ans <<"\n";
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int t;
	cin >>t;
	rep(_g, t) solove();
	return 0;
}


Measured memory_bytes: 9468
# N：人数 M：種類
# K1：個 A1 A2 ...：好きな食べ物の数字
# K2 A1 A2
# 全員が好きな食べ物の種類数

N, M = map(int, input().split())
s = set(range(1, M+1))

for _ in range(N):
    k, *a = map(int, input().split())
    s&=set(a)
print(len(s))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int S,T,V;
    read(S),read(T),read(V);
    if(T*V>=S) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<tuple<int, int, int>> csf(n-1);
    cin >> csf;
    csf.emplace_back(0, 0, 1);
    for (int i : irange(0, n)) {
        ll ans = 0;
        for (int j : irange(i, n)) {
            int c = get<0>(csf[j]);
            int s = get<1>(csf[j]);
            int f = get<2>(csf[j]);
            if (ans <= s) {
                ans = s + c;
            } else {
                ans = (ans + f - 1) / f * f + c;
            }
        }
        cout << ans << nl;
    }
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u64,
        b: u64,
        c: u64,
    }
    let mx = std::cmp::max(a,std::cmp::max(b,c));
    println!("{}",
        if (a+b+c) - mx == mx { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
n = int(input())

s = m = int(input())

for i in range(n):
  in_car, out_car = map(int, input().split())
  
  m += in_car - out_car
  
  if m < 0:
    s = 0
    break
  else:
    s = max(s, m)

print(s)

Measured memory_bytes: 7676
A = []
P = ['o']*9
for i in range(3):
    a = [int(i) for i in input().split()]
    for j in range(3):
        A.append(a[j])

N = int(input())
for i in range(N):
    b = int(input())
    for j in range(9):
        if A[j] == b:
            P[j] = 'x'

t = 0
for i in range(3):
    if (P[i] == P[i+3] == P[i+6] == 'x') or (P[3*i] == P[3*i+1] == P[3*i+2] == 'x'):
        t += 1
        break
if (P[0] == P[4] == P[8] == 'x') or (P[2] == P[4] == P[6] == 'x'):
    t += 1

if t == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9252
#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>
#include <cassert>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)


ll gcd(ll a, ll b){
  if(a < b) swap(a,b);
  assert(a>0ll);
  if(b==0ll)return a;
  else return gcd(b,a%b);
}



int main() {
  int  T;
  cin >> T;
  ll a,b,c,d;
  bool ok;
  ll mod,r,g;
  REP(i, T){
    cin >> a >> b >> c >> d;
    ok = true;

    if(a < b){
      cout << "No" << endl;
    }else if(b > d){
      cout << "No" << endl;
    }else if(c >= b){
      cout << "Yes" << endl;
    }else{

      g = gcd(b,d);
      if (b - g + (a % g) > c)
        cout << "No" << endl;
      else cout << "Yes" << endl;
    }
  //   ok &= a >= b; //初日に買えるため
  //   ok &= a%b <= c; // c< n < bに入らない 
  //   ok &= d >= b; // d<bだと在庫は減る一方

  //   //c - b == 1なら大丈夫
  //   //上記の条件を満たし、d%b==0なら大丈夫
  //   if( d%b>0ll    && c < b - 1ll ){
  //     // p = (a - b) % c ; //最初に追加される本数
  //     // q = d % b;       // d>=bより q <
  //     mod = gcd(b,d % b);
  //     r = ((a - b) % c) % mod;
      
  //     // ok &= !( (c - r) / mod * mod + mod + r < b);
  //     ok &= (r + b - mod) % b <= c;
  //   }

  //   if(ok)cout << "Yes" << endl;
  //   else cout << "No" << endl; 
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=200005;
struct Node{
	int x,id;
}a[N];
int n,rk[N],b[N];
bool cmp(Node x,Node y)
{
	return x.x<y.x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i].x),b[i]=a[i].x,a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) rk[a[i].id]=i;
//	for(int i=1;i<=n;i++) cout<<rk[i];
	int v1,v2;
	for(int i=1;i<=n;i++)
	  if(rk[i]==n/2) v1=b[i];
	    else if(rk[i]==n/2+1) v2=b[i];
	for(int i=1;i<=n;i++)
	  if(rk[i]<=n/2) printf("%d\n",v2);
	    else printf("%d\n",v1);
	return 0;
}

Measured memory_bytes: 5376
import java.util.*;
	import java.lang.Math;
    public class Main
	{
		public static void main(String args[])
		{
			Scanner scan=new Scanner(System.in);
			int n = scan.nextInt();
			if(n%2==0)
				System.out.println(n/2);
			else
				System.out.println((n+1)/2);
		}
	}
	

Measured memory_bytes: 23764
//
//  main.cpp
//  TestC
//
//  Created by CHEN SINYU on 2020/02/22.
//  Copyright © 2020 CHEN SINYU. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <stdio.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    string s;
    cin >> s;
    ll cnt = 0;
    rep(i,0,s.size()) {
        cnt += (ll)(s[i] - '0');
    }
    if(cnt%9 == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3716
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

int main(){
  long long int h,n;
  cin>>h>>n;
  vector<pair<int,int>> spells(n);//dmg,cost
  int maxDmg=INT_MIN;
  for(auto &x:spells){
    cin>>x.first>>x.second;
    maxDmg=max(maxDmg,x.first);
  }
  vector<int> dp(h+1+maxDmg,INT_MAX);
  dp[0]=0;
  for(int i=1;i<h+1+maxDmg;i++){
    for(auto x:spells){
      if(i-x.first>=0&&dp[i-x.first]!=INT_MAX)
        dp[i]=min(dp[i],dp[i-x.first]+x.second);
    }
  } 
  int ans=INT_MAX;
  for(int i=h;i<h+1+maxDmg;i++){
    ans=min(ans,dp[i]);
  }
  cout<<ans<<"\n";  
  return 0;
}

Measured memory_bytes: 384
from functools import reduce
from copy import deepcopy

n = int(input())

def dadd(t, s): 
    for k,v in s.items():
        t[k] = t.get(k, 0) + v 
    return t

def pfd(c, i): 
    for j in range(2, i // 2 + 1): 
        if i % j == 0:
            d = i // j
            return dadd(deepcopy(c[j]), c.get(d, dict()))
    return { i: 1 } 

p,c = {},{}
for i in range(2, n + 1): 
    q = pfd(c, i)
    c[i] = q 
    dadd(p, q)

tot = reduce(lambda a,v: a * (v + 1), p.values(), 1)
print(tot % (10 ** 9 + 7)) 

Measured memory_bytes: 3936
#include<stdio.h>
#include<stdlib.h>
#define M 10000

main(){
  int i,j,a;
   unsigned short *b,*d;
  int c[M+1];
  scanf("%d",&a);
   b = malloc(sizeof(short)*a+1);
  d =  malloc(sizeof(short)*a+1);
 for(i=0;i<=M;i++){
    c[i]=0;
  }
  for(j=0;j<a;j++){
    scanf("%d",&b[j+1]);
    c[b[j+1]]++;
  }
 
  for(i=1;i<=M;i++){
    c[i]=c[i]+c[i-1];
  }
  for(j=a;j>=1;j--){
    d[c[b[j]]]=b[j];
    c[b[j]]--;
  }
  
  for(i=1;i<a;i++){
    printf("%d ",d[i]);
  }
  printf("%d\n",d[a]);
  return 0;
  }
  

Measured memory_bytes: 8456
/*
    Author : RAJON BARDHAN
    AUST CSE 27th Batch
    All my programming success are dedicated to my mom , dad , little sister madhobi , teachers , friends and love TANIA SULTANA RIMY

    Problem Name :
    ALGORITHM :
*/

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

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define memo(a,b) memset(a,b,sizeof(a))
#define INF 1e9
#define EPS 1e-8
#define PI 3.14159265358979323846

typedef long long ll ;
typedef unsigned long long ull ;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

const int blockSZ = 600 ;
int arr[100000+10] , BLOCK[600] ;

int getID(int index)
{
    return index / blockSZ ;
}

void update(int index,int value)
{
    arr[index] = value ;
    int blockID = getID(index) , start = blockID*blockSZ , end = (blockID+1)*blockSZ-1 ;

    for(int i=start ; i<=end ;i++)
    {
        if(i==start) BLOCK[blockID] = arr[i] ;
        else BLOCK[blockID] = min(BLOCK[blockID],arr[i]);
    }
}

int query(int L,int R)
{
    int lid = getID(L) , rid = getID(R) ;
    if(lid==rid)
    {
        int mn = 2147483647 ;
        for(int i=L;i<=R;i++) mn = min(mn,arr[i]);
        return mn ;
    }
    int mn1 = 2147483647 , mn2 = 2147483647 , mn3 = 2147483647 ;
    for(int i=L;i<=lid*blockSZ+blockSZ-1;i++) mn1 = min(mn1,arr[i]);
    for(int i=lid+1;i<rid;i++) mn2 = min(mn2,BLOCK[i]);
    for(int i=rid*blockSZ;i<=R;i++) mn3 = min(mn3,arr[i]);

    return min(min(mn1,mn3),mn2);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int N , Q ;
    scanf("%d%d",&N,&Q);
    for(int i=0;i<N;i++) update(i,2147483647);

    while( Q-- )
    {
        int d , x , y ;
        scanf("%d%d%d",&d,&x,&y);

        switch( d )
        {
            case 0 :
                update(x,y);
                break ;
            case 1 :
                printf("%d\n",query(x,y));
                break ;
        }
    }
    return 0;
}

Measured memory_bytes: 1564
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
const ll INF=(1e16);
int n,t;
ll a[maxn],dp[maxn][20],ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=0;i<=n;i++)
	for (int j=0;j<19;j++) dp[i][j]=-INF;
	dp[0][0]=0;
	ans=-INF;
	int R;
	for (int i=1;i<=n;i++) {
		for (int j=0;j<=10;j++) {
			dp[i][j]=-INF;
			if ((i+1)/2-j<=0) continue;
			R=i-1;
			if (i==1) R=1;
			for (int k=max(0,i-10);k<R;k++) {
				t=(k+1)/2-((i+1)/2-j-1);
				//if (i==1&&j==0) printf("%d %d %lld\n",k,t,dp[k][t]);
				if (0<=t&&t<=10) {
					if (dp[k][t]!=-INF) {
						dp[i][j]=max(dp[i][j],dp[k][t]+a[i]);
					}
				}
			}
			//printf("%d %d %d %lld\n",i,j,(i+1)/2-j,dp[i][j]);
			if ((i+1)/2-j==n/2) ans=max(ans,dp[i][j]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/


Measured memory_bytes: 36532
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k,a):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r();p=map(int,f[2:].split())
  if'0'==f[0]:a+=f'{g(n,E,*p)}\n'
  else:c,d,e=p;E[c]+=[(e,d)];E[d]+=[(e,c)]
 print(a[:-1])
for e in iter(r,'0 0\n'):s(*map(int,e.split()),'')


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

using namespace std;

const int N = 1e6 + 10;

inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int last[N], root[N];
struct seg{
	int l, r;
	int val;
}tr[N * 30];
int tot;

void build(int &rt, int l, int r)
{
	rt = ++tot;
	tr[rt].val = 0; 
	if(l == r) return ;
	int mid =l + r >> 1;
	build(tr[rt].l, l, mid), build(tr[rt].r, mid + 1, r);
}

void update(int &p, int q, int x, int c, int l, int r)
{
	p = ++ tot;
	tr[p] = tr[q];
	tr[p].val += c;
	if(l == r) return ;
	int mid = l + r >> 1;
	if(x <= mid) update(tr[p].l, tr[q].l, x,c, l, mid);
	else update(tr[p].r, tr[q].r, x, c,mid + 1, r);
}

int query(int p, int q, int L, int R, int l, int r)
{
	if(L <= l && R >= r)
	return tr[q].val - tr[p].val;
	int mid = l + r >> 1;
	int res = 0;
	if(L <= mid) res += query(tr[p].l, tr[q].l, L, R, l, mid);
	if(R >  mid) res += query(tr[p].r, tr[q].r, L, R, mid + 1, r);
	return res;
}

int main()
{
	int n, m;
	n = read(); m = read();
	build(root[0], 0, n);
	for (int i = 1; i <= n; i ++)
	{
		int x;
		x = read();
		update(root[i], root[i - 1], last[x], 1, 0, n);
		last[x] = i;	
	}
	while(m --)
	{
		int x, y;
		x = read(), y = read();
		printf("%d\n", query(root[x - 1], root[y], 0, x - 1, 0, n));
	}
}

Measured memory_bytes: 136816
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 1e9

int d[101][101];
int n;

void init(){
	for(int i = 0; i < 101; i++){
		for(int j = 0; j < 101; j++)	d[i][j] = INF;
	}
}

void solve(){
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		}
	}
}

int main(void){
	int np;
	init();
	cin >> n;
	for(int i = 0; i < n; i++){
		int v, e;
		cin >> v >> e;
		for(int j = 0; j < e; j++){
			int t;
			cin >> t;
			d[v][t] = 1;
		}
	}
	solve();
	cin >> np;
	for(int i = 0; i < np; i++){
		int s, g, ttl;
		cin >> s >> g >> ttl;
		if(d[s][g] != INF && d[s][g] + 1 <= ttl){
			printf("%d\n", d[s][g] + 1);
		}else{
			printf("NA\n");
		}
	}
  return 0;
}

Measured memory_bytes: 1188
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	int ans = 0;
	int tmp;
	cin >> n >> m;
	for (int i = 1; i*i <= m; i++) {
		if (m%i == 0) {
			tmp = m / i;
			if (i < n) {
				if (tmp < n) {
					tmp = 0;
				}
				else {
					tmp = i;
				}
			}
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    let n = read_i64();
    let xs = read_vec_i64();
    let mut lower = 2;
    let mut upper = 2;
    for &x in xs.iter().rev() {
        lower = (lower + (x-1)) / x * x;
        upper = ((upper) / x + 1) * x - 1;
        if upper < lower {
            println!("-1");
            return;
        }
    }
    println!("{} {}", lower, upper);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec_i64<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 8444
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    int N, cnt = 0; cin >> N;
    map<string, int> mp;
    REP(i, N){
        string s; cin >> s;
        ++mp[s];
        chmax(cnt, mp[s]);
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        if(itr->second == cnt)
            cout << itr->first << "\n";
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

  
int main() {
  int H,W;
  cin >> H >> W;
  vvi G(H,vi(W));
  int w_cnt = 0;
  rep(i,H) {
    string w;
    cin >> w;
    rep(j,W) {
      if(w[j] == '.') {
        G[i][j] = 1;
        w_cnt++;
      } else {
        G[i][j] = 0;
      }
    }
  }
  vvi d(H,vi(W,-1));
  d[0][0] = 0;
  auto isinRoad = [&](int w, int h) {
    if(w < 0 || w >= W) {
      return false;
    }
    if(h < 0 || h >= H) {
      return false;
    }
    return G[h][w] == 1;
  };
  
  queue<pair<pair<int,int>,int>> que;
  auto next = [&](int w, int h,int d) {
    int dw[] = {-1,1,0,0};
    int dh[] = {0,0,-1,1};
    rep(x,4) {
      if(isinRoad(dw[x]+w,dh[x]+h)) {
          que.push(pair<P,int>(P(dw[x]+w,dh[x]+h),d+1));
        }
    }
  };
  next(0,0,0);
  while(!que.empty()) {
    pair<P,int> pos = que.front();
    int w = pos.first.first;
    int h = pos.first.second;
    int dis = pos.second;
    que.pop();
    if(d[h][w] != -1) {
      continue;
    }
    d[h][w] = dis;
    next(w,h,dis);
  }
  if(d[H-1][W-1] == -1) {
    cout << -1 << endl;
    return 0;
  }
  cout << w_cnt - d[H-1][W-1] - 1 << endl;
  return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int MAX_FACT = 2000000;
ll fact[MAX_FACT];

ll M;

ll pow_mod(ll a,ll n){
  ll cur=1;
  ll mul=a;
  while(n){
    if(n%2)cur=(cur*mul)%M;
    mul=(mul*mul)%M;
    n/=2;
  }
  return cur;
}

ll div_mod(int a){
  return pow_mod(a,M-2);
}

// factを前計算
void calcFact(){
  fact[0]=1;
  for(int i=1;i<MAX_FACT;i++)
    fact[i]=(fact[i-1]*i)%M;
}

// aCbのmodを計算
// 計算量はO(log(fact[a])+log(fact[a-b]))程度
ll comb(ll a,ll b){
  if(a<0||b<0)return 0;
  else if(a<b)return 0;
  else if(b==0)return 1;
  ll res=fact[a];
  res=(res*div_mod(fact[b]))%M;
  res=(res*div_mod(fact[a-b]))%M;
  return res;
}

int N;

// dp[j][i] = j杯のラーメンに、iまでの具材を1つ以下分割してのせる場合の個数
ll dp[3010][3010];
ll rec(int j, int i){
    if(dp[j][i] >= 0) return dp[j][i];
    if(j == 0) return 1;
    if(j == i) return 1;
    ll res = (rec(j-1, i-1) + (rec(j, i-1) * (j + 1)) % M) % M;
    return dp[j][i] = res;
}

ll pow2[10000100];
// powpow2[i] = 2^(2^i)
ll powpow2[10100];

int main(){

    cin >> N >> M;
    calcFact();

    memset(dp, -1, sizeof(dp));

    pow2[0] = 1;
    for(int i = 1; i < 10000010; i++)
        pow2[i] = (pow2[i - 1] * 2) % M;

    powpow2[0] = 2;
    for(int i = 1; i < 10100; i++)
        powpow2[i] = (powpow2[i-1] * powpow2[i-1]) % M;

    int sign = 1;
    ll tot = 0;
    for(int i = 0; i <= N; i++){
        ll way = 0;
        for(int j = 0; j <= i; j++){
             // cout << j << "," << i << "," << rec(j, i) << endl;
            ll tmp = (((rec(j, i) * powpow2[N - i]) % M) * pow2[(N-i)*j]) % M;
            way = (way + tmp) % M;
        }
        tot += sign * ((way * comb(N, i)) % M);
        if(tot < M) tot += M;
        tot %= M;
        sign *= -1;
    }
    cout << tot << endl;

    return 0;
}


Measured memory_bytes: 164864
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep(x, k+1){
    rep(y, k+1){
      if(x + y > s || x + y + k < s) continue;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[20][100000];
int main(){
	int n,m;	cin>>n>>m;
	vector<int> a(m);
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(i>=a[0])	dp[0][i]=dp[0][i-a[0]]+1;
		else 	dp[0][i]=1;
	}
	for(int i=1;i<m;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=a[i]){
				dp[i][j]=min(dp[i][j],dp[i-1][j-a[i]]+1);
				dp[i][j]=min(dp[i][j],dp[i][j-a[i]]+1);
			}
		}
	}
	cout<<dp[m-1][n]<<endl;
	return 0;
}

Measured memory_bytes: 7176
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,b,c;
signed main()
{
	cin>>a>>b>>c;
	rep(i,10){
		cout<<a*c-b<<endl;
		c=a*c-b;
	}
}

Measured memory_bytes: 256
X, Y = map(int,input().split())

if (X+Y)%3 != 0 or X+Y == 0:
    print(0)
    exit()

n = int((2*Y-X)/3)
m = int((2*X-Y)/3)

if n < 0  or m < 0:
    print(0)
    exit()

mod = 10**9+7


def comb(n, r, mod):
    x=y=1
    for i in range(r):
        x *= n; y *= r
        x %= mod; y %= mod
        n -= 1; r -= 1
    return x * pow(y, mod - 2, mod) % mod

print(comb(n+m, n, mod))


Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

i64 gcd(i64 a, i64 b) { return b ? gcd(b, a % b) : a; }

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> x(N + 1);
  cin >> x.back();
  F0R(i, N) {
    cin >> x[i];
  }
  sort(rng(x));
  int a;
  F0R(i, N) {
    int b = x[i + 1] - x[i];
    if (i) a = gcd(a, b);
    else a = b;
  }
  cout << a;
}
#endif


Measured memory_bytes: 3696