akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		
		int A[] = new int[n];
		int B[] = new int[n];
		int C[] = new int[n];
		
		
		for(int i = 0; i< n ; i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0; i< n ; i++){
			B[i] = sc.nextInt();
		}
		for(int i = 0; i< n ; i++){
			C[i] = sc.nextInt();
		}
		
		
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		
		
		int AB[] = new int[n];
		int ai = 0;
		int bi = 0;
		
		for( ; ai < n; ){
//			System.out.println(ai + " " + bi);
			if(A[ai] < B[bi]){
				AB[bi]++;
				ai++;
			}else{
				bi++;
				if(bi == n){
					break;
				}
				AB[bi] = AB[bi-1];
			}
		}
		bi ++;
		for(;bi < n ; bi ++){
			AB[bi] = AB[bi-1];
		}
//		System.out.println(Arrays.toString(A));
//		System.out.println(Arrays.toString(B));
//		System.out.println(Arrays.toString(AB));

		long BC[] = new long[n];
		bi = 0;
		int ci = 0;
		for( ;bi < n ; ){
			if(B[bi] < C[ci]){
				BC[ci] += AB[bi];
				bi++;
			}else{
				ci++;
				if(ci == n){
					break;
				}
				BC[ci] = BC[ci-1];
			}
		}

		ci ++;
		for(;ci < n ; ci ++){
			BC[ci] = BC[ci-1];
		}
//		System.out.println(Arrays.toString(BC));
		
		long res = 0L;
		for(int i = 0 ; i < n ; i++){
			res = res+ BC[i];
		}
		System.out.println(res);
		
	}
}


Measured memory_bytes: 94016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  string s;
  cin >> s;
  int n = s.length();

  int count = 1;
  FOR(i,1,n-1){
    if(s[i-1]!=s[i]){
      count++;
    }
  }

  cout << count-1 << endl;

}



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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b, t;
	cin >> a >> b >> t;
	int ans = 0, newA = a;
	for (int i = 0; i < t + 1; i++) {
		if (i == newA) {
			ans += b;
			newA += a;
		}
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n,m; cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}





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

int main(void) {
	int64_t N;
	int64_t h, n, w;
	int64_t bunbo, bunsi;
	if (scanf("%" SCNd64, &N) != 1) return 1;
	for (h = 1; h <= 3500; h++) {
		for (n = 1; n <= 3500; n++) {
			bunsi = N * h * n;
			bunbo = 4 * h * n - N * n - N * h;
			if (bunsi > 0 && bunbo > 0 && bunsi % bunbo == 0) {
				printf("%" PRId64 " %" PRId64 " %" PRId64 "\n", h, n, bunsi / bunbo);
				return 0;
			}
		}
	}
	puts("not found");
	return 0;
}

/*

4/N = 1/h + 1/n + 1/w

4/N = (nw + hw + hn)/(hnw)

4hnw = N(nw + hw + hn)

(4hn - Nn - Nh)w = Nhn

w = (Nhn) / (4hn - Nn - Nh)

*/


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
using namespace std;

int main(void){
    while(true){
        int n, ans = 0;
        double total = 0, ave;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        for(int i = 0; i < a.size(); i++){
            cin >> a[i];
        }
        for(int i = 0; i < a.size(); i++){
            total += a[i];
        }
        ave = total / n;

        for(int i = 0; i < a.size(); i++){
            if((double)a[i] <= ave) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	
	int n=min(a,b);
	
	for(int i=n;i>=1;--i){
		if(a%i==0&&b%i==0) k--;
		
		if(k==0){
			cout<<i<<endl;
			return 0;
		}
	}
}//ABC120_b. 復習. 解説参考.

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
int main(){
	ll n;
	cin >> n;
	ll a[n],b[n],c[n];
	fop(i,0,n) cin >> a[i] >> b[i] >> c[i];
	ll dp[n+1][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	fop(i,1,n){
		dp[i][0] = max(dp[i-1][1] ,dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0] ,dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][1] ,dp[i-1][0]) + c[i];
	}
	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
from collections import deque
import numpy as np

n, m = list(map(int, input().split()))
edge = {}
for i in range(m):
    ai, bi = list(map(int, input().split()))
    if ai in edge:
        edge[ai].append(bi)
    else:
        edge[ai] = [bi,]
    if bi in edge:
        edge[bi].append(ai)
    else:
        edge[bi] = [ai,]
# print(edge)

is_visited = np.zeros((n+1,), dtype=np.bool)
parent = np.zeros((n+1,), dtype=np.int)

q = deque()
q.append(1)
is_visited[1] = True
while len(q) != 0:
    node = q.popleft()
    for child in edge[node]:
        if not is_visited[child]:
            is_visited[child] = True
            parent[child] = node
            q.append(child)

print('Yes')
print('\n'.join(list(map(str, list(parent[2:])))))

Measured memory_bytes: 68560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k,c=0;
    cin>>n>>m;
    if(abs(n-m)>n && n<m)
    {
        cout<<n;
        return 0;
    }
    if(n<m)
    {
        cout<<abs(n-m);
        return 0;
    }
    if(m==1)
    {
        cout<<0;
        return 0;
    }
    if(n%m==0)
    {
        cout<<0;
        return 0;
    }
    else
    {
        c = n%m;
        c= min(c,abs(c-m));
        cout<<c;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  if(S==U){
    A-=1;
  }
  else {
    B-=1;
  }
  cout<<A<<" "<<B<<endl;

return 0;  
}

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

int main()
{
    int H, W, N;
    cin >> H;
    cin >> W;
    cin >> N;

    int once = H > W ? H : W;
    for(int i=0; i<=100; i++)
    {
        if(i*once >= N)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >>n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll q;
    cin >> q;
    vector<ll> b(q), e(q), t(q);
    rep(i,0,n) cin >> b[i] >> e[i] >> t[i];

    rep(i,0,q) 
    {
        rep(j,0,e[i]-b[i])
        {
            swap(a[b[i]+j], a[t[i]+j]);
        }
    }

    rep(i,0,n)
    {
        if (i != n-1)
        cout << a[i] << ' ';
        else
        cout << a[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}


int main(){
    ll n,k,ans=0;
    cin >> n >> k;
    for (ll i=k+1;i<=n;i++){
        ll x=n/i;
        ll y=max(0LL,n%i-max(0LL,k-1));
        x*=(i-k);
        ans+=x;
        ans+=y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct edge{int to,cap,rev;};
struct Dinic{
    int n;
    vector<vector<edge>> v;
    vector<int> dist,iter;
    Dinic(int n):n(n),v(n),dist(n),iter(n){}
    void add_edge(int from,int to,int c){
        int x=v[to].size(),y=v[from].size();
        v[from].push_back({to,c,x});
        v[to].push_back({from,0,y});
    } 

    void bfs(int s){
        fill(dist.begin(),dist.end(),-1);
        queue<int> q;
        dist[s]=0;
        q.push(s);
        while(!q.empty()){
            int x=q.front();q.pop();
            for(auto& e :v[x]){
                if(e.cap&&dist[e.to]<0){
                    dist[e.to]=dist[x]+1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int x,int t,int f){
        if(x==t)return f;
        for(int& i=iter[x];i<v[x].size();++i){
            edge& e=v[x][i];
            if(e.cap&&dist[x]<dist[e.to]){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    v[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s,int t){
        int ret=0;
        while(1){
            bfs(s);
            if(dist[t]<0)return ret;
            fill(iter.begin(),iter.end(),0);
            int f;
            while((f=dfs(s,t,inf))>0)ret+=f;
        }
    }
};

int gcd(int x,int y){
    if(x<y)swap(x,y);
    return y? gcd(y,x%y) : x;
}

void solve(int n,int m){
    int a[n],b[m];
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    int s=n+m,t=n+m+1;
    Dinic dn(n+m+2);
    rep(i,n)rep(j,m){
        if(gcd(a[i],b[j])>1)dn.add_edge(i, j+n, 1);
    }
    rep(i,n)dn.add_edge(s, i, 1);
    rep(i,m)dn.add_edge(i+n, t, 1);
    cout<<dn.max_flow(s, t)<<endl;
}
int main(){
    int n,m;
    while(cin>>n>>m,max(n,m)!=0)solve(n,m);
    return 0;
}


Measured memory_bytes: 7120
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i++<n;)

ll n,m,a[100010],b[100010];
bool vis[100010]={0,1};
vector<ll> t[100010];
vector<ll> path;

ll r(){
  bool f[2]={0,0};
  for(auto i=t[*path.begin()].begin();i!=t[*path.begin()].end();i++){
    ll g=*i;
    if(!vis[g]) f[0]=1;
  }
  auto A=path.end();
  for(auto i=t[*(--A)].begin();i!=t[*A].end();i++){
    ll g=*i;
    if(!vis[g]) f[1]=1;
  }
  return (ll)2*f[0]+f[1];
}

void jo(ll Q){
  if(Q==1){
  auto A=path.end();
  for(auto i=t[*(--A)].begin();i!=t[*A].end();i++){
    ll g=*i;
    if(!vis[g]){
      path.push_back(g);
      vis[g]=1;
      return;
    }
  }
  }
  else{
  auto A=path.begin();
  for(auto i=t[*A].begin();i!=t[*A].end();i++){
    ll g=*i;
    if(!vis[g]){
      path.insert(path.begin(),g);
      vis[g]=1;
      return;
    }
  }
  }
}

int main(){
  cin>>n>>m;
  fr(i,m){
    cin>>a[i]>>b[i];
    t[a[i]].push_back(b[i]);
    t[b[i]].push_back(a[i]);
  }
  path.push_back(1);
  for(;;){
    auto A=path.end();
    ll R=r();
    if(R==0) break;
    jo(R%2);
  }
  cout<<path.size()<<endl;
  for(auto i=path.begin();i!=path.end();i++){
    cout<<*i<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 8820
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
int N;
Pol pol;
D s;
L edges[50];
D eps=1e-50;
inline D cro(P a,P b){
	return imag(conj(a)*b);
}
D aPol(Pol p){
	D ret=0;
	int n=p.size();
	rep(i,n) ret+=cro(p[i],p[(i+1)%n])/2;
	return ret;
}
P gpol(Pol p){
	P g;
	s=aPol(p);
	int n=p.size();
	rep(i,n){
		D ds=cro(p[i],p[(i+1)%n])/2;
		g+=ds/3*(p[i]+p[(i+1)%n]);
	}
	return g/s;
}
bool iLS(L l,L s){
	return cro(l.sc-l.fs,s.fs-l.fs)*cro(l.sc-l.fs,s.sc-l.fs)<eps;
}
P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
D pi=acos(-1.0);
vector<D> args,thetas;
int main(){
	cin>>N;
	rep(i,N){
		D x,y;
		cin>>x>>y;
		pol.pb(P(x,y));
	}
	rep(i,N){
		edges[i]=L(pol[i],pol[(i+1)%N]);
	}
	P g=gpol(pol);
	rep(i,N){
		args.pb(arg(pol[i]-g));
	}
	rep(i,N) rep(j,i+1){
		thetas.pb((args[i]+args[j])/2+1e-9);
		thetas.pb((args[i]+args[j])/2-1e-9);
	}
	for(D theta:thetas){
		L l=L(g,g+polar(1.0,theta));
		Pol npol;
		rep(i,N){
			if(iLS(l,edges[i])){
				npol.pb(intLL(edges[i],l));
				npol.pb(pol[(i+1)%N]);
				for(int j=i+1;;j++){
					if(j==N) j=0;
					if(iLS(l,edges[j])){
						npol.pb(intLL(edges[j],l));
						break;
					}else{
						npol.pb(pol[(j+1)%N]);
					}
				}
				break;
			}
		}
		if(abs(s/aPol(npol)-2)>1e-9){
			puts("NA");
			return 0;
		}
	}
	printf("%.12f %.12f\n",g.real(),g.imag());
}

Measured memory_bytes: 1352
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
int D=sc.nextInt();
int x=sc.nextInt();
for(int i=0;i<10;i++){
x=r*x-D;
System.out.println(x);
}
}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#define maxn 3005
using namespace std;
int dp[maxn][maxn],last[maxn][maxn];
char s[maxn],t[maxn],w[maxn];
int main(){
	scanf("%s%s",s+1,t+1);
	int n=strlen(s+1),m=strlen(t+1);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++){
		if (s[i]==t[j]) {
			if (dp[i][j]<dp[i-1][j-1]+1) dp[i][j]=dp[i-1][j-1]+1,last[i][j]=1;
		}
		if (dp[i-1][j]>dp[i][j]) dp[i][j]=dp[i-1][j],last[i][j]=2;
		if (dp[i][j-1]>dp[i][j]) dp[i][j]=dp[i][j-1],last[i][j]=3; 
	}
	int x=n,y=m;
	while (dp[x][y]){
		if (last[x][y]==1) w[dp[x][y]]=s[x],x--,y--;else
		if (last[x][y]==2) x--;else y--;
	}
	for (int i=1;i<=dp[n][m];i++)
	printf("%c",w[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 70656
n=require('fs').readFileSync('/dev/stdin','utf8').split("\n");
  for(i=a=0;i<=~~n[0];i++)for(j=0;j<=~~n[1];j++)for(k=0;k<=~~n[2];k++)if(i*500+j*100+k*50 === ~~n[3])a++
  console.log(a);

Measured memory_bytes: 7500
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Point> list = new ArrayList<Point>();
        for(int i=0;i<n;i++){
        	Point p = new Point(sc.nextInt(), sc.nextInt());
        	list.add(p);
        }

        list.sort((p, q) -> p.y - q.y);

        int time = 0;
        boolean flag = true;
        for(int i=0;i<n;i++){
        	Point p = list.get(i);
        	time += p.x;
        	if(time > p.y){
        		flag = false;
        		break;
        	}
        }

        if(flag){
        	System.out.println("Yes");
        }
        else{
        	System.out.println("No");
        }
    }
}

class Point{
	int x;
	int y;
	public Point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 107020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];
  vector<vector<bool>> d(h, vector<bool>(w, true));
  for (int i = 0; i < h; i++) {
    bool ok = true;
    for (int j = 0; j < w; j++) if (a[i][j] == '#') ok = false;
    if (ok) {
      for (int j = 0; j < w; j++) d[i][j] = false; 
    }
  }

  for (int j = 0; j < w; j++) {
    bool ok = true;
    for (int i = 0; i < h; i++) if (a[i][j] == '#') ok = false;
    if (ok) {
      for (int i = 0; i < h; i++) d[i][j] = false;
    }
  }
  vector<string> res;
  for (int i = 0; i < h; i++) {
    string tmp = "";
    for (int j = 0; j < w; j++) if (d[i][j]) tmp += a[i][j];
    if (tmp.size() > 0) res.emplace_back(tmp);
  }
  for (auto e : res) cout << e << endl;
  return 0;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define sum(a) accumulate(begin(a), end(a), 0)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
    ll N, M;
    vector<double> A;
    cin >> N >> M;

    rep(i, 0, N){
        double temp;
        cin >> temp;
        A.push_back(temp);
    }
    soR(A);
    double sum = sum(A);
    double maxI = sum / (4 * M);

    rep(i, 0, M){
        if (A[i] < maxI){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  int l;cin >> l;
  vector<string> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  string ans;
  rep(i,n){
    ans+=a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[fastout]

fn calc_score(d: usize, c: &Vec<i64>, s: &Vec<[i64; 27]>, t: &Vec<usize>) -> i64 {
    let mut res = 0;
    let mut last: [usize; 26 + 1] = [0; 26 + 1];
    for day in 1..=d {
        let now_contest = t[day];
        res += s[day][now_contest];
        last[now_contest] = day;
        for contest in 1..=26 {
            res -= c[contest] * (day - last[contest]) as i64;
        }
    }
    println!("{}", res);
    res
}

fn main() {
    // input
    input! {
        d: usize,
        _c: [i64; 26],
        _s: [[i64; 26]; d],
        _t: [usize; d],
        m: usize,
        dq: [(usize, usize); m],
    }

    let mut c = vec![0];
    c.extend(_c.iter());

    let mut s = vec![[0; 26 + 1]; d + 1];
    for day in 1..=d {
        for contest in 1..=26 {
            s[day][contest] = _s[day - 1][contest - 1]
        }
    }

    let mut t = vec![0];
    t.extend(_t.iter());

    // process
    for (day, q) in dq {
        t[day] = q;
        calc_score(d, &c, &s, &t);
    }
}


Measured memory_bytes: 4348
def solve(S):
    str_list = ["dream", "dreamer", "erase", "eraser"]
    n = 0
    while n < len(S):
        for s in str_list:
            if n:
                if S[:-n].endswith(s):
                    n += len(s)
                    break
            else:
                if S.endswith(s):
                    n += len(s)
                    break
        else:
            return False
    return True


S = input()
if solve(S):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n), r(n + 1, 0);
	rep(i, n) cin >> a[i];
	rep(i, n) r[i + 1] = r[i] + a[i];
	int ans = inf;
	rep2(i, 1, n) ans = min(abs(r[i] - r[0] - (r[n] - r[i])), ans);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

bool isPrime(int a){
    for(int i=2; i*i<=a; i++){
        if(a%i==0) return false;
    }
    return true;
}

int main() {
    int N; cin >> N;
    vector<int> P;
    for(int i=2; i<=55555; i++){
        if(isPrime(i)&&i%5==1) P.push_back(i);
    }
    for(int i=0; i<N; i++){
        cout << P[i] << endl;
    }
    
    return 0;
    
}





Measured memory_bytes: 256
//Only the Creator has given me strength!🖤
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<bitset>
typedef long long ll;
#define pi 3.1415926535897931159979635
#define pb push_back
#define vctr vector<int>
#define vvtr vector<vctr>

using namespace std;
void fastio() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    fastio();
    int x,y,c=0,t=0,w=0,r=0;
    cin>>x;
    string a; 
    while(x--){
    cin>>a;
    if(a=="AC") c++;
    else if(a=="WA") w++;
    else if(a=="TLE") t++;
    else r++;  
    }
    cout<<"AC x "<<c<<"\n";
    cout<<"WA x "<<w<<"\n";
    cout<<"TLE x "<<t<<"\n";
    cout<<"RE x "<<r<<"\n";
   

    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

int main()
{
	int N,M;
	cin >> N >> M;

	vector<vector<pair<int,lint>>> edge(N);
	for(int i=0;i<M;i++)
	{
		int a,b;
		lint c;
		cin >> a >> b >> c;
		a--;
		b--;
		c=-c;
		edge[a].push_back(make_pair(b,c));
	}

	lint dist[1010]={};
	const lint inf=1e18;
	for(int i=0;i<N;i++)
		dist[i]=inf;
	dist[0]=0;

	bool negative=false;
	for(int i=0;i<2*N;i++)
	{
		bool update=false;
		for(int j=0;j<N;j++)
		{
			if(dist[j]==inf)
				continue;

			for(auto&& k:edge[j])
			{
				if(dist[k.first]>dist[j]+k.second)
				{
					dist[k.first]=dist[j]+k.second;
					update=true;
					if(i==2*N-1 && k.first==N-1)
						negative=true;
				}
			}
		}
		if(!update)
			break;
	}

	if(negative)
		cout << "inf" << endl;
	else
		cout << -dist[N-1] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
const int maxSize=4000;
bool visited[maxSize][maxSize];
int distances[maxSize][maxSize], amount, diameter;
vector<int> graph[maxSize];
vector<tuple<int, int>> lines;
void fillingGraph()
{
	cin>>amount>>diameter;
	int vertex0, vertex1;
	for(int i=1; i<amount; ++i)
	{
		cin>>vertex0>>vertex1;
		graph[vertex0].push_back(vertex1);
		graph[vertex1].push_back(vertex0);
		lines.push_back(make_tuple(vertex0, vertex1));
	}
	return;
}
void dfs(int root, int firstPoint, int distance)
{
	visited[root][firstPoint]=true;
	for(int secondPoint : graph[firstPoint])
	{
		if(!visited[root][secondPoint])
		{
			dfs(root, secondPoint, distance+1);
		}
	}
	distances[root][firstPoint]=distance;
	return;
}
void usingDfs()
{
	for(int point=1; point<=amount; ++point)
	{
		dfs(point, point, 0);
	}
	//If a diameter of a graph is even, therefore,
	//a center of the diameter will be a point.
	if(diameter%2==0)
	{
		int evenCase=-400, evenNumber;
		for(int i=1; i<=amount; ++i)
		{
			evenNumber=0;
			for(int j=1; j<=amount; ++j)
			{
				if(distances[i][j]<=diameter/2)
				{
					++evenNumber;
				}
			}
			evenCase=max(evenCase, evenNumber);
		}
		cout<<(amount-evenCase);
	}
	//If a diameter of a graph is odd, therefore,
	//a center of the diameter will be a line.
	else
	{
		int oddCase=-400, oddNumber;
		for(auto item : lines)
		{
			oddNumber=0;
			for(int i=1; i<=amount; ++i)
			{
				int temporary=min(distances[i][get<0>(item)], distances[i][get<1>(item)]);
				if(temporary<=diameter/2)
				{
					++oddNumber;
				}
			}
			oddCase=max(oddCase, oddNumber);
		}
		cout<<(amount-oddCase);
	}
	return;
}
int main()
{
	fillingGraph();
	usingDfs();
	return 0;
}

Measured memory_bytes: 35236
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi 3.14159265358979323846264
using namespace std;

int main()
{
   ld a,b;
   ld h,m;
   cin>>a>>b>>h>>m;
   ld ang=abs((30*h)-(5.5*m));
   ld C=((ld)(ang)/(180))*pi;
   cout<<fixed<<setprecision(20)<<sqrtl((a*a)+(b*b)-(2*(a*b)*cos(C)))<<"\n";
}

Measured memory_bytes: 4088
#include<stdio.h>
int main(void){
  int N,L,S[201],i,j,aji=0,aji2=0,cou=0,min=0,min2=0,cou2=0,cou3=0;
  scanf("%d %d",&N,&L);
  min=L;
  for(i=0;i<N;i++){
    S[i]=L+i;
    min2=L+i;
    if(S[i]==0){
      cou++;
    }else{
      aji+=S[i];
    }
    if(min<0){
      min*=-1;
    }
    if(min2<0){
      min2*=-1;
      cou2=1;
    }
    if(min>min2){
      min=min2;
      if(cou2==1){
        cou3=4;
      }
    }
    aji2+=S[i];
  }



  if(cou==1){
    printf("%d",aji);
  }else{
    if(cou3==4){
    printf("%d",aji2+min);
    }else{
      printf("%d",aji2-min);
    }
  }
  return 0;
 }
      

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m1, m2, d1, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 == m2) {
        cout << "0\n";
    } else {
        cout << "1\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		String ans = "Yes";
	
		if ((a + b) < c) {
			ans = "No";
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21844
# AtCoder用のライブラリ
# 参照
# https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a


# a ** n mod m
def mod_pow(a, n, m=10 ** 9 + 7):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * a % m
        a = a * a % m
        n >>= 1
    return res


# aの-1乗をmで割ったときの商を求める
def mod_inv(a, m=10 ** 9 + 7):
    b = m
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= m
    return u


# 組み合わせ数(nCk)を計算させる。
# nを固定しながら複数のkに対して計算させることができるようにしてあるため、
# 計算量はO(max(k)*log(mod))となる。実質O(max(k))。
class ModCombination:
    def __init__(self, n, mod=10 ** 9 + 7):
        self.N = n
        self.MOD = mod
        # 組み合わせ数の分子の部分のリスト
        self.P_list = [1]
        # 組み合わせ数の分母の部分のリスト
        self.inv_fact_list = [1]

    def combination(self, r):
        if r > len(self.inv_fact_list) - 1:
            self._list_extend(r)
        return self.inv_fact_list[r] * self.P_list[r] % self.MOD

    def _list_extend(self, needed):
        now = len(self.inv_fact_list)
        while now <= needed:
            self.P_list.append(self.P_list[-1] * (self.N - now + 1) % self.MOD)
            self.inv_fact_list.append(self.inv_fact_list[-1] * mod_inv(now) % self.MOD)
            now += 1

# ここから解答ソース

S = int(input())

MOD = 10 ** 9 + 7

if S < 3:
    print(0)
    exit()
if S < 6:
    print(1)
    exit()

S_room_max = S // 3 - 1

ans = 1

for rooms in range(S_room_max):
    rooms += 1
    S_removed = S - (rooms + 1) * 3
    mc = ModCombination(S_removed + rooms)
    ans += mc.combination(rooms)
    ans %= MOD

print(ans)


Measured memory_bytes: 9264
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - 01 Matrix
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

/*
  s = na+(h-n)(w-a) = na+hw-ha-nw+na = h(w-a)-(w-2a)n
  s = mb+(w-m)(h-b) = mb+wh-wb-mh+mb = w(h-b)-(h-2b)m
 */

int main() {
  int h, w , a, b;
  scanf("%d%d%d%d", &h, &w , &a, &b);

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++)
      putchar(((y < b) ^ (x < a)) ? '1' : '0');
    putchar('\n');
  }
  return 0;
}


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

int n;
int *S;

bool hasKey(int key) {
  int left = 0, right = n;
  while(right - left > 1) {
    int mid = (right + left) / 2;
    if(S[mid] == key) return true;

    if(S[mid] < key) {
      left = mid + 1;
    }else {
      right = mid;
    }
  }
  if(S[left] == key) return true;
  return false;
}

int main() {
  cin >> n;
  S = new int[n];
  for(int i = 0; i < n; i++) cin >> S[i];

  int q;
  cin >> q;

  int ans = 0;
  for(int i = 0; i < q; i++){
    int t;
    cin >> t;
    if(hasKey(t)) ans++;
  }

  cout << ans << endl;


}

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

C=[0]*(N+1)
D=[0]*(N+1)
E=[0]*(N+1)

for i in range(N):
  C[A[i]]+=1
  D[B[i]]+=1
  E[A[i]]+=1
  E[B[i]]+=1

if max(E)>N:
  print("No")
  exit()
  
for i in range(1,N+1):
  C[i]+=C[i-1]
  D[i]+=D[i-1]

ans=0
for i in range(1,N+1):
  ans=max(ans, C[i]-D[i-1])
B=[B[(i-ans)%N] for i in range(N)]
  
print("Yes")
print(' '.join(map(str, B)))

Measured memory_bytes: 135556
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(a, n);
    }
    static void getAns(int[] a, int n)
    {
        var ans = 0;
        for (int i = 0; i < n - 1; i++)
            for (int j = i + 1; j < n; j++) ans += a[i] * a[j];
        Console.WriteLine(ans);
    }
}


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

const char Board[17] = "CODEFESTIVAL2016";

int main(){
    char s[17]={0};
    scanf("%s",s);
    int cnt=0;
    for(int i=0;i<16;++i)if(s[i] != Board[i])++cnt;
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
}

Measured memory_bytes: 26272
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin>>N;
    int A[100010];
    int mi=0;
    int small=1000000000;
    unsigned long sum=0;
    for(int i=0;i<N;++i){
        cin>>A[i];
        sum+=abs(A[i]);
        if(A[i]<0){
            mi++;
        }
        if(small>abs(A[i])){
            small=abs(A[i]);
        }
    }
    if(mi%2==0)cout<<sum<<endl;
    else cout<<sum-small-small<<endl;
}



Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s;
  int f[100][100]={0},dp[100][100]={0},y=0,z=0;
  while(cin >>s){
    for(int i=0,t=0,x=0; i<s.size(); i++){
      if(s[i]>='0' && s[i]<='9') t = t*10+s[i]-'0';
      if(s[i] == ',' || i == s.size()-1){
	f[x][y] = t;
	t = 0;
	x++;
	if(z<x) z = x;
      }
    }
    y++;
  }
  dp[0][0] = f[0][0];
  for(int i=0; i<z-1; i++){
    for(int j=0; j<z; j++){
      dp[j][i+1] = max(dp[j][i+1],dp[j][i]+f[j][i+1]);
      dp[j+1][i+1] = max(dp[j+1][i+1],dp[j][i]+f[j+1][i+1]);
    }
  }
  for(int i=z; i<2*z-1; i++){
    for(int j=0; j<z; j++){
      dp[j][i] = f[j][i]+max(dp[j][i-1],dp[j+1][i-1]);
    }
  }
  cout <<dp[0][z*2-2]<<endl;
  return 0;
}

Measured memory_bytes: 1268
def main():
  s = input()
  t = input()

  if len(t) > len(s):
    print('UNRESTORABLE')
    return

  for i in range(len(s)-len(t), -1, -1):
    flag = True

    for j in range(len(t)):
      if s[i+j] != '?' and s[i+j] != t[j]:
        flag = False
        break

    if flag == True:
      str = s[0:i].replace('?', 'a') + t + s[i+len(t):].replace('?', 'a')
      print(str)
      return

  print('UNRESTORABLE')

main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

#define INF 1000000001

using namespace std;

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    int ans[N]; fill(ans, ans + N, 0);
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            int dist = min(j - i, abs(i - X) + 1 + abs(j - Y));
            ans[dist] ++;
        }
    } 
    for(int i=1; i<N; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
    ll N; cin>>N;
    if(N%2==1){
        cout<<0<<endl;
    }else{
        ll cnt=0;
        ll t=N;
        while(t!=0){
            t/=5;
            cnt+=(t/2);
        }
        cout<<cnt<<endl;
    }
}
    

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

int n,m,k;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline int gcd(int x,int y) { return (!y)?x:gcd(y,x%y); }

inline ll calc(int c,int d,int lim)
{
	if (lim<0) return 0;
	int hh=lim/m,mx=n-d-1;
	ll res=max(0,min(mx,hh));
	hh++;
	if (hh>0&&hh<=mx&&hh*m-gcd(m-c,hh+d)-gcd(hh,c)<=lim) res++;
	hh++;
	if (hh>0&&hh<=mx&&hh*m-gcd(m-c,hh+d)-gcd(hh,c)<=lim) res++;
	return res;
}

inline ll work()
{
	ll res=0;
	int mx=k*2-2+m;
	for (int i=1;i<=m-1;i++) for (int j=0;j*i<=mx&&j<=n-2;j++)
	{
		if (j==0) res+=calc(i,j,k*2-2-i*j+gcd(j,m));
		else res+=calc(i,j,k*2-2-i*j+gcd(j,m))*2;
	}
	return res*2;
}

int main()
{
	n=rd();m=rd();k=rd();
	ll ans=work();
	swap(n,m);
	printf("%lld\n",ans+work());
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	ll n,m,x, t; cin >> n >>m >> x;
	vector<vector<ll>> a(n, vector<ll>(m));
	vector<ll> c(n);
	rep(i, n) {
		cin >> c[i]; rep(j, m) cin >> a[i][j];
	}
	
	ll ans = INF;
	rep(state, pow(2, n)) {
	  vector<int> books;
		rep(i,n) if (state >> i & 1) books.push_back(i);

		ll csum = 0;
		vector<ll> r(m);
		for (int b : books) {
		  csum += c[b];
			rep(j,m) r[j] += a[b][j];
		}

		bool ok = true;
		rep(i, m) {
		  if (r[i] < x) {ok  = false; break;}
		}

		if (ok) chmin(ans, csum);
	}

	if (ans < INF) cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>

using namespace std;
using ll = long long;

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

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


///////////////////////////////////////

ll dp[100100][15];

int main() {
    string s; cin >> s;
    int len = s.size();
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    ll mod = 1e9+7;

    for (int i = 0; i < len; i++)
    {
        if (s[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    int tmp = (j*10+k)%13;
                    dp[i+1][tmp] += dp[i][j];
                    dp[i+1][tmp] %= mod;
                }
            }
        }
        else {
            int d = s[i]-'0';
            for (int j = 0; j < 13; j++) {
                int tmp = (j*10+d)%13;
                dp[i+1][tmp] += dp[i][j];
                dp[i+1][tmp] %= mod;
            }
        }
    }
    
    cout << dp[len][5] << endl;
    
    return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
int x, n;
int p[maxn];
bool f[maxn];
int ma = 0x3f3f3f3f, id;
int main(){
    cin >> x >> n;
    for(int i = 1;i <= n;i++){
        cin >> p[i];
        f[p[i]] = 1;
    }
    for(int i = -100;i <= 101;i++){
        if(!f[i] && abs(i - x) < ma){
            ma = abs(i - x);
            id = i;
        }
    }
    cout << id << endl;
    return 0;
}

Measured memory_bytes: 3632
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#define f first
#define s second
#define ms(a, b) memset(a,b,sizeof(a))
typedef long long ll;

using namespace std;

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

    int A,B,C,D;

    cin >> A >> B >> C >> D;
    int X,Y;

    X = (A+D-1)/D;
    Y = (C+B-1)/B;

    (X>=Y) ? cout << "Yes" <<"\n" : cout << "No" << "\n";

    return 0;
}


Measured memory_bytes: 3612
//#pragma GCC optimize("O3,unroll-loops")
//#pragma loop_opt(on)
#include <bits/stdc++.h>
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    string s;
    cin >> s;
    const int sz = s.size();
    int *n = new int[sz+1]();
    Fr(i, 0, sz) n[i] = s[sz-1-i]-'0';
    Fr(i, 0, sz) {
         if (n[i] > 5 || n[i]==5 && n[i+1] > 4) { n[i] -= 10; n[i+1]++; }
    }
    int cnt = 0;
    Fr(i, 0, sz+1) cnt += abs(n[i]);
    cout << cnt << endl;

}


Measured memory_bytes: 5276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class34
    {
        static void Main()
        {
            var HA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = HA[0] / HA[1];
            if (HA[0] % HA[1] != 0) ans++;
            Console.WriteLine(ans);
        }
    }
}


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

int main()
{
  int64_t n;
  cin >> n;
  string ans;
  if (n == 0)
  {
    cout << "0\n";
    return 0;
  }

  while (n != 0)
  {
    int r = n % 2;
    if (r < 0)
      r += 2;
    n = (n - r) / (-2);
    ans += (char)('0' + r);
  }
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
}

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

int main() {
    string s;
    int n, max = 0, x = 0;

    cin >> n >> s;
    for(int i=0; i<s.size(); i++) {
        if(s[i]=='I') {
            x++;
            if(x>max) max = x;
        }
        else x--;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
//#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 LINF 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;

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


int main(void) {
	int h, w, n;
	int sr, sc;
	string s, t;
	int pos;
	bool flag = false;
	int L, R, U, D;
	

	cin >> h >> w >> n;
	cin >> sr >> sc;
	cin >> s >> t;


	L = sc;
	R = w - sc + 1;
	U = sr;
	D = h - sr + 1;


	FOR(i, 0, n - 1) {

		switch (s[i]) {
		case 'L':
			L--;
			break;
		case 'R':
			R--;
			break;
		case 'U':
			U--;
			break;
		case 'D':
			D--;
			break;
		}
		
		if (L <= 0 || R <= 0 || U <= 0 || D <= 0) {
			flag = true;
			break;
		}

		if (L<w) {
			if (t[i] == 'R') {
				L++;
			}
		}
		if (R<w) {
			if (t[i] == 'L') {
				R++;
			}
		}
		if (U<h) {
			if (t[i] == 'D') {
				U++;
			}
		}
		if (D<h) {
			if (t[i] == 'U') {
				D++;
			}
		}

	}

	if (flag) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

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

int	main()
{
	string	str;
	cin >> str;
	int	q;
	cin >> q;
	string	order;
	int	a, b;
	string	p;
	for (int i = 0; i < q; ++i) {
		cin >> order >> a >> b;
		if (order == "print")
			cout << str.substr(a, b - a + 1) << endl;
		if (order == "reverse")
			reverse(str.begin() + a, str.begin() + b + 1);
		if (order == "replace") {
			cin >> p;
			for (int j = a; j <= b; ++j) {
				str.at(j) = p.at(j - a);
			}
		}
	}
}



Measured memory_bytes: 3220
n = int(input())
s = input()

# アルファベット→int
h = {}
for i in range(26):
    h[chr(ord('a') + i)] = i

base1 = 1009
base2 = 1007
mod1 = 1000000007
mod2 = 1000000009

pow1 = [1]*(n+1)
pow2 = [1]*(n+1)
hash1 = [0]*(n+1)
hash2 = [0]*(n+1)
for i in range(n):
    hash1[i+1] = (hash1[i]+h[s[i]]) * base1 % mod1
    hash2[i+1] = (hash2[i]+h[s[i]]) * base2 % mod2
    pow1[i+1] = pow1[i] * base1 % mod1
    pow2[i+1] = pow2[i] * base2 % mod2


# [l, r)
def get(l, r):
    t1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1
    t2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2
    return (t1, t2)

from collections import deque, defaultdict


def check(k):
    # 長さk二分探索
    if k > n:
        return False
    que1 = deque()

    d = defaultdict(int)
    # 最初のk通りを入れる
    for i in range(k):
        if i+k<=n:
            a = get(i, i+k)
            que1.append(a)
        else:
            break
    for i in range(k, n-k+1):
        a = que1.popleft()
        d[a] += 1
        b = get(i, i+k)
        if d[b] > 0:
            return True
        que1.append(b)
    
    return False

left = 0
right = n

while right - left > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid

print(left)

Measured memory_bytes: 48240
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',]
C = input()
print(l[l.index(C)+1])

Measured memory_bytes: 2940