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

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

int main() {

    int n,m; cin >> n >> m;
    vector<int> a(m);
    rep(i, m) {
        cin >> a[i];
    }
    // 入力例的にa[i]の順は大小が考慮されていないので、降順ソートしておく
    sort(a.begin(), a.end(), greater<int>() );

    // 数値ごとのマッチ利用本数
    vector<int> match_num{2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6};



    // dpテーブルの作成
    // i本使う時に作れる最大の桁数を用意する
    vector<int> dp(11000, -INT_MAX);
    for(int i=1; i <= n; i++) {
        int tmp = -INT_MAX;
        rep(j, m) {
            // オーバフロー対策
            if(i-match_num[a[j]-1] < 0) continue;
            // 使い切れる数以外は0になるような工夫
            if(i-match_num[a[j]-1] == 0) {
                tmp = 1;
            } else if(dp[i-match_num[a[j]-1]] > 0) {
                tmp = max(tmp, dp[i-match_num[a[j]-1]]+1);
            }
        }
        dp[i] = tmp;
    }

    // 計算用の対策, dp[0]の時を0にしておく
    dp[0] = 0;

    // 結果を求める
    string ans = "";
    int remain = dp[n]; // 期待される桁数
    int match = n; // 残りのマッチ本数
    dp[0] = 0; // 計算用の対策, dp[0]の時を0にしておく(最後の１桁を求める時の判定用)

    while(match > 0) {
        // 大きい数から使っていく
        rep(i, m) {
            // 使いきれたらそれでおk
            if(remain-1 == dp[match-match_num[a[i]-1]] && match-match_num[a[i]-1] >= 0) {
                match -= match_num[a[i]-1];
                remain -= 1;
                ans += to_string(a[i]);
                break;
            }
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (1<<21)
const int maxn=100+10;
const int maxw=10000+10;
int n,W;
int w[maxn];
int v[maxn];
int d[maxw];
void solve()
{
    memset(d,0,sizeof(d));
    for(int i=0;i<n;i++)
    {
        for(int j=w[i];j<=W;j++)
        {
            d[j]=max(d[j],d[j-w[i]]+v[i]);
        }
    }
    printf("%d\n",d[W]);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;i++) scanf("%d%d",&v[i],&w[i]);

    solve();

    return 0;
}

Measured memory_bytes: 3260
#include<iostream>
#include<string>

using namespace std;

int A[500000] = {0};
int n, comparisons=0;

void merge(int l, int m, int r)
{
  int n1 = m - l;
  int n2 = r - m;
  int L[n1], R[n2];
  for (int i = 0; i < n1; ++i)
    L[i] = A[l+i];
  for (int i = 0; i < n2; ++i)
    R[i] = A[m+i];
  int i = 0, j = 0;
  for (int k = l; k < r; ++k) {
    if (i == n1) {
      while(j < n2) {
        A[k++] = R[j++];
        ++comparisons;
      }
      break;
    } else if (j == n2) {
      while(i < n1) {
        A[k++] = L[i++];
        ++comparisons;
      }
      break;
    } else {
      ++comparisons;
      if (L[i] <= R[j]) A[k] = L[i], ++i;
      else A[k] = R[j], ++j;
    }
  }
}

void sort(int l, int r) {
  if (l + 1 < r) {
    int m = (l+r)/2;
    sort(l, m);
    sort(m, r);
    merge(l, m, r);
  }
}

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

  sort(0, n);

  for(int i = 0; i<n; ++i) {
    if(i) cout << ' ';
    cout << A[i];
  }
  cout << endl;
  cout << comparisons << endl;
}


Measured memory_bytes: 6972
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(reversed(list(map(int, input().split()))))

ac = Counter(A)
bc = Counter(B)

am = ac.most_common(1)[0]

if am[1]+bc[am[0]] > N:
    print("No")
    exit()

j = 0

for i in range(N):
    if A[i] == B[i]:
        while B[i]==A[j] or B[j]==A[i]:
            j += 1
            j %= N
        B[i], B[j] = B[j], B[i]

print("Yes")
print(*B)

Measured memory_bytes: 147412
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include <chrono>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 998244353
#define ll long long
#define vll vector<long long>  
#define all(c) c.begin(), c.end()
// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())
// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;
using namespace std::chrono; 

const ll INF = 1e13;
int n , k;
vector<int> dp(1e5 + 10, -1);
vector<int> arr(1e3 + 10);
// void dfs(int v, vector<vector<int> >& adj, vector<bool> visited){
//     visited[v] = true;
//     for(int u: adj[v]){
//         if(!visited[u])
//             dfs(u, adj, visited);
//     }
// }

int solve(int val){
    if(dp[val] != -1)return dp[val];
    if(val == 0){
        dp[val] = 0;
        return 0;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(arr[i] <= val){
            if(solve(val-arr[i]) == 0){
                ans = 1;
                break;
            }
        }
    }
    dp[val] = ans;
    return dp[val];

}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO

    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    // for(int i=0;i<=k;i++)cout<<dp[i]<<" ";
    // cout<<endl;
    if(solve(k))cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    // for(int i=0;i<=k;i++)cout<<dp[i]<<" ";
    // cout<<endl;


    

    return 0;
}

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

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

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

  int n, m; cin >> n >> m;
  vector<bool> start(n, false), goal(n, false);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    if(a == 0) goal[b] = true;
    if(b == n-1) start[a] = true;
  }

  bool flag = false;
  rep(i, n) {
    if(start[i] && goal[i]) flag = true;
  }

  cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
  return 0;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int mem[100001][3];
int arr[100001][3];

int dp(int n, int s)
{
	if(n==1)
		return arr[n][s];
	if(n<=0)
		return mod;
	if(mem[n][s]!=-1)
		return mem[n][s];
	int best;
	if(s==0)
	best= arr[n][s]+max(dp(n-1,1),dp(n-1,2));
	if(s==1)
	best= arr[n][s]+max(dp(n-1,0),dp(n-1,2));
	if(s==2)
	best= arr[n][s]+max(dp(n-1,1),dp(n-1,0));
	mem[n][s]=best;
	return best;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    // int i;
    f1(i,1,n+1)
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    f1(i,0,100001)
    memset(mem[i],-1,sizeof(mem[i]));
    cout<<max({dp(n,0),dp(n,1),dp(n,2)});
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n || m){
		vector<vector<int> > vec(n+1);
		int a,b;
		rep(i,m){
			cin>>a>>b;
			vec[a].push_back(b);
			vec[b].push_back(a);
		}
		vector<int> invited;
		rep(i,vec[1].size()){
			invited.push_back(vec[1][i]);
		}
		rep(i,vec[1].size()){
			rep(j,vec[vec[1][i]].size()){
				if(vec[vec[1][i]][j]!=1)invited.push_back(vec[vec[1][i]][j]);
			}
		}
		sort(invited.begin(),invited.end());
		invited.erase(unique(invited.begin(),invited.end()),invited.end());
		cout<<invited.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1376
X, K, D = map(int, input().split())

X = abs(X)

a = X // D
d1 = X - (D * a)
d2 = X - (D * (a + 1))
 
if X - (D * K) >= 0:
    ans = X - (D * K)
else:
    if (K-a) % 2 == 0:
        ans = d1
    else:
        ans = d2

print(abs(ans))


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 3) {
    rep(j, 3) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b[i];

  vector<vector<bool>> c(3, vector<bool>(3, false));
  rep(k, n) {
    rep(i, 3) {
      rep(j, 3) {
        if (b[k] == a[i][j]) {
          c[i][j] = true;
        }
      }
    }
  }

  rep(i, 3) {
    if (c[i][0] && c[i][1] && c[i][2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(j, 3) {
    if (c[0][j] && c[1][j] && c[2][j]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (c[0][0] && c[1][1] && c[2][2]) {
    cout << "Yes" << endl;
    return 0;
  }
  if (c[0][2] && c[1][1] && c[2][0]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;


  
  return 0;
}

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

int main() {
	int X;
	cin >> X;

	if (X >= 1800) {
		cout << 1 << endl;
	} else if (X >= 1600) {
		cout << 2 << endl;
	} else if (X >= 1400) {
		cout << 3 << endl;
	} else if (X >= 1200) {
		cout << 4 << endl;
	} else if (X >= 1000) {
		cout << 5 << endl;
	} else if (X >= 800) {
		cout << 6 << endl;
	} else if (X >= 600) {
		cout << 7 << endl;
	} else if (X >= 400) {
		cout << 8 << endl;
	}

	return 0;
}


Measured memory_bytes: 3632
import sys
input=sys.stdin.readline

# 整数bをa進数で表現した時の各桁の和
# (ex. 7,6 => (6**1)*1 + (6**0)*1 => 1+1=2
def func(n,a):
    x = 0
    while n > 0:
        x += n%a
        n //= a
    return x

def main():
    N = int(input())
    mi = N
    for i in range(N+1):
        mi = min(mi, func(i,6) + func(N-i,9))
    print(mi)
    
if __name__ == '__main__':
    main()


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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e12;
  while (l+1<r) {
    ll c = (l+r)/2;
    bool ok = [&]{
      ll s = 0;
      rep(i,n) {
        s += max(0ll, a[i]-c/f[i]);
      }
      return s <= k;
    }();
    if (ok) r = c; else l = c;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        ArrayList<Integer> a = new ArrayList<>();
        ArrayList<String> op = new ArrayList<>();
        ArrayList<Integer> b = new ArrayList<>();
        
        while(true){
            String[] line = br.readLine().split(" ");
            if ("?".equals(line[1])) {
                break;
            }
            a.add(Integer.parseInt(line[0]));
            op.add(line[1]);
            b.add(Integer.parseInt(line[2]));
        }
        for(int i=0;i<a.size();i++){
            if("+".equals(op.get(i))){
                System.out.println(a.get(i) + b.get(i));
            }else if("-".equals(op.get(i))){
                System.out.println(a.get(i) - b.get(i));
            }else if("*".equals(op.get(i))){
                System.out.println(a.get(i) * b.get(i));
            }else if("/".equals(op.get(i))){
                System.out.println(a.get(i) / b.get(i));
            }
        }
    }
}



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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 2 * N;

int n;
char s[N];
int res[N];

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	
	for (int i = n; i; i -- )
	{
		int cntL = 0, p = i;
		while (p && s[p] == 'L') p -- , cntL ++ ;
		
		int r = p + 1, l = p;
		
		if (!p) break;
		int cntR = 0;
		while (p && s[p] == 'R') p -- , cntR ++ ;
		
		// cout << cntR << ' ' << cntL << endl;
		
		int s = cntR + cntL;
		if (s % 2 == 0) res[l] = res[r] = s / 2;
		else if (cntR % 2)
		{
			res[l] = max(s / 2 + 1, s / 2);
			res[r] = min(s / 2 + 1, s / 2);
		}
		else
		{
			res[l] = min(s / 2 + 1, s / 2);
			res[r] = max(s / 2 + 1, s / 2);
		}
		
		i = p + 1;
	}
	
	for (int i = 1; i <= n; i ++ ) printf("%d ", res[i]);
    return 0;
}

Measured memory_bytes: 896
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define mod 998244353
#define bug cout<<"HY"<<endl
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define numize(A) A.numize(unique(A.begin(), A.end()) - A.begin())
typedef pair<int,int> P;
int power(int a,int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return (power((a*a)%mod,b/2))%mod;
    return (a*(power((a*a)%mod,b/2))%mod)%mod;
}
int modInv(int n)
{
    return power(n, MOD-2);
}
int nCr(int n, int r, int p=MOD)
{
   if (r==0)
      return 1;
    int Fact[n+1];
    Fact[0] = 1;
    for (int i=1 ; i<=n; i++)
    {
        Fact[i] = (Fact[i-1]*i)%p;
    }
    return (((Fact[n]* modInv(Fact[r])) % MOD) *(modInv(Fact[n-r]) % MOD)) % MOD;
}
double PI=3.14159265359;
void solve()
{
	int n;
	cin>>n;
	if(n>=30)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
int32_t main()
{
    boost;
    int  t=1;
    // cin>>t;
    while(t--)
    {
    	solve();
    }
}


Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#include<sstream>
#define h 100
#define ll  long long
#define pb push_back
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int n, i, ans=1000,l, m, p;
  cin>>n;
  vector<ll int>a(n);
  for(i=0;i<n;i++)
  cin>>a[i];
  l=a[0];
  for(i=1;i<n;i++) 
  {
  		if(l<a[i]) 
  		{
  			m=((ans/l)*l);
  			p=a[i]*(ans/l);
  			ans+=p-m;
  			l=a[i];
  		} 
  		else l=a[i];
  } 
  cout<<ans<<endl;
  return 0;
} 


Measured memory_bytes: 3656
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr,pr> ppr;
bool DP[2][257][22][22];

int main() {
	// your code goes here
	int x,y,n;
	char data;
	while(cin >> x>>y && x!=0){
		int price[10]={};
		int start[10]={};
		int end[10]={};
		int maxim=0;
		int num,sx,sy,dx[]={0,0,1,-1,0},dy[]={1,-1,0,0,0};
		int maps[22][22]={};
		for(int i=0;i<22;i++)
			for(int j=0;j<22;j++)
				maps[i][j]=-1;
		for(int i=1;i<=y;i++)
			for(int j=1;j<=x;j++){
				cin >> data;
				if(data=='.')
				maps[i][j]=-1;
				else if(data=='P'){
				maps[i][j]=-1;
				sx=j;
				sy=i;
				}
				else
				maps[i][j]=data-'0';
			}
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> num;
			cin >> price[num] >> start[num] >> end[num];
		}
		queue<ppr>  qu;
		qu.push(ppr(pr(sx,sy),pr(0,0)));
		while(!qu.empty()){
			int px=qu.front().first.first,py=qu.front().first.second,t=qu.front().second.second,p=qu.front().second.first;
			qu.pop();
			DP[t%2][p][px][py]=false;
			for(int i=0;i<4;i++){
				int nx=px+dx[i],ny=py+dy[i];
				if(maps[ny][nx]!=-1 && start[maps[ny][nx]]<=t && end[maps[ny][nx]]>t)
				p|=(int)pow(2,maps[ny][nx]);
			}
			
			if(t<100)
			for(int i=0;i<5;i++){
				int nx=px+dx[i],ny=py+dy[i];
				if(nx>=1 && nx<=x && ny>=1 && ny<=y &&maps[ny][nx]==-1 && !DP[(t+1)%2][p][nx][ny]){
				qu.push(ppr(pr(nx,ny),pr(p,t+1)));
				DP[(t+1)%2][p][nx][ny]=true;
				}
			}
			if(t==100){
				int c=0;
				for(int i=0;i<10;i++)
					if(p&(int)pow(2,i))
					c+=price[i];
				maxim=max(maxim,c);
			}
		}
		cout << maxim << endl;
	}
	return 0;
}

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

int main()
{
	int H, W;
	cin >> H >> W;
	string s[H];
	for(int i = 0; i < H; i++){
		cin >> s[i];
	}

	for(int i = 0; i < H; i++){
		cout << s[i] << endl;
		cout << s[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int K;
    cin >> K;
    int odds = K / 2 + (K % 2 == 1 ? 1 : 0);
    int even = K / 2;
    cout << odds * even << endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
alist,blist = [],[]
for i in range(m):
    a,b=map(int,input().split())
    alist.append(a)
    blist.append(b)

uf = UnionFind(n)
for i in range(m):
    uf.union(alist[i]-1,blist[i]-1)

roots = uf.roots()
rootsize = [uf.size(rt) for rt in roots]
print(max(rootsize))

Measured memory_bytes: 103964
import java.util.Scanner;

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

    long x = scanner.nextLong();
    long count = x / 11 * 2;
    x -= x / 11 * 11;
    if (x > 6) count += 2;
    else if (x > 0) count++;
    System.out.println(count);
  }
}


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

using namespace std;

int main(int argc, char *argv[]) {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

static int
solve(int N, vector<int> a)
{
  vector<char> check(N);
  int ret = 0;
  int button = 1;
  while (button != 2)
  {
    if (check[button - 1])
    {
      return -1;
    }
    check[button - 1] = 1;
    button = a[button - 1];
    ret++;
  }
  return ret;
}

int
main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int n = 0; n < N; n++)
  {
    cin >> a[n];
  }
  cout << solve(N, a) << endl;
  return 0;
}


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

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    auto cmp = compress(A);

    int ans = 1e9;
    for(int mn : cmp){
        vector<int> avail;
        vector<int> len;
        for(int i=0; i<=N; i++){
            if(i<N && mn <= A[i]){
                len.push_back(A[i]);
            }else{
                sort(len.begin(), len.end());
                int sz = len.size();
                for(int j=0; j<sz-K+1; j++) avail.push_back(len[j]);
                len.clear();
            }
        }
        sort(avail.begin(), avail.end());
        if(avail.size() >= Q) ans = min(ans, avail[Q-1] - mn);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 500005
using namespace std;
int n,m,l,r,a[N],dp[N][27],f[N],p[N][27];
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;i++)
		a[i]=s[i]-'a'+1;
	for (int i=0;i<=26;i++) dp[n+1][i]=10000000;
	f[n+1]=n+1;
	for (int i=n;i>=1;i--)
	{
		dp[i][a[i]]=i;
		for (int j=a[i]+1;j<=26;j++)
		{
			if (dp[i][j-1]<=n)
				dp[i][j]=dp[dp[i][j-1]+1][j-1];
			else dp[i][j]=10000000;
		}
		if (dp[i][26]<=n)
			dp[i][0]=dp[dp[i][26]+1][26];
		else dp[i][0]=10000000;
		for (int j=1;j<a[i];j++)
		{
			if (dp[i][0]<=n)
				dp[i][j]=dp[dp[i][0]+1][j];
			else dp[i][j]=10000000;
		}
		if (dp[i][0]<=n) p[i][0]=dp[i][0]+1;
		else p[i][0]=10000000;
	}
	p[n+1][0]=10000000;
	for (int i=1;i<=20;i++)
		for (int j=1;j<=n+1;j++)
			if (p[j][i-1]!=10000000) p[j][i]=p[p[j][i-1]][i-1];
			else p[j][i]=10000000;
	
	scanf("%d",&m);
	while(m--)
	{
		scanf("%d%d",&l,&r);
		for (int j=20;j>=0;j--)
		{
			if (p[l][j]<=r+1) l=p[l][j];
		}
		puts(l==r+1?"Yes":"No");
	}
	//while(1);
}

Measured memory_bytes: 110464
def main():
    L, R = map(int, input().split())
    ans = float('INF')
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
            if ans == 0:
                print(ans)
                return
    print(ans)


main()


Measured memory_bytes: 2940
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	count := 0
	for i := a; i <= b; i++ {
		s := strconv.Itoa(i)
		if s[0] == s[4] && s[1] == s[3] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc105/tasks/abc105_d


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class cumsum1d:  # 一次元累積和クラス
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]


from collections import Counter
N, M = read_ints()
A = read_ints()

# 素直にl,rを全探索はできない
# 累積和を割れば0sumrangesの亜種
A_cum = cumsum1d(A)
tmp = []
for a in A_cum.ls_accum:
    tmp.append(a % M)
cnts = Counter(tmp)

ans = 0
for c in cnts.values():
    ans += c * (c - 1) // 2

print(ans)


Measured memory_bytes: 60836
#include <iostream>
#include <string>
using namespace std;
long long A,B;
int K,i,j;
int main(){
    cin >> A >> B >> K;
    if(B - A <= K){
        for(i = A;i <= B;i++){
            cout << i << endl;
        }
    }else{
        for(i = A;i < A + K; i++){
            cout << i << endl;
        }
        for(j = B - K + 1; j <= B; j++){
            if(j >= i){
                cout << j << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int cnt[1005];
int flag[1005];

int main(){
	int n;
	
	cin >> n;
	
	REP(i,n+1) flag[i] = 1;
	
	FOR(i,2,n+1){
		int base;
		
		if (flag[i]){
			base = i;
			
			while (base <= n){
				base += i;
				flag[base] = 0;
			}
		}
	}
	
	//REP(i,n+1) cout << flag[i] << endl;
	
	FOR(i,2,n+1){
		FOR(j,2,i+1){
			int tmp = i;
			
			if (flag[j]){
				while (tmp%j == 0){
					tmp /= j;
					cnt[j]++;
				}
			}
		}
	}
	
	ll ans = 1;
	
	//REP(i,n+1) cout << cnt[i] << endl;
	
	FOR(i,2,n+1){
		ans *= cnt[i]+1;
		ans %= MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int a, b, q;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> q;
  vector<ll> s(a);
  vector<ll> t(b);

  REP(i, a) cin >> s[i];
  REP(i, b) cin >> t[i];

  REP(i, q) {
    ll x;
    cin >> x;

    auto its = lower_bound(s.begin(), s.end(), x);
    auto itt = lower_bound(t.begin(), t.end(), x);

    ll ss = its == s.begin() ? *its : *(its - 1);
    ll ts = itt == t.begin() ? *itt : *(itt - 1);

    ll se = its == s.end() ? *(its - 1) : *its;
    ll te = itt == t.end() ? *(itt - 1) : *itt;

    ll d1 = min(abs(x - ss), abs(x - ts)) + abs(ss - ts);
    ll d2 = min(abs(x - ss), abs(x - te)) + abs(ss - te);
    ll d3 = min(abs(x - se), abs(x - te)) + abs(se - te);
    ll d4 = min(abs(x - se), abs(x - ts)) + abs(se - ts);
    cout << min({d1, d2, d3, d4}) << endl;
  }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    string s, t;
    int Q;
    cin >> s >> Q;
    int cnt = 0;
    while(Q--) {
        int q;
        cin >> q;
        if(q == 1) {
            cnt++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            f += cnt;
            f %= 2;
            if(f == 1)
                t.push_back(c);
            else
                s.push_back(c);
        }
    }
    if(cnt % 2 == 1) {
        reverse(ALL(s));
        cout << s << t << endl;
    } else {
        reverse(ALL(t));
        cout << t << s << endl;
    }

    return 0;
}


Measured memory_bytes: 980
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
using namespace std;
const int MAX=100000;
const int INF=(1<<29);

vector<int >G[MAX];
list<int >out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
  queue<int >q;
  q.push(s);
  V[s]=true;
  while(!q.empty()){
    int u=q.front();
    q.pop();
    out.push_back(u);
    
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      indeg[v]--;
      if(indeg[v]==0&&!V[v]){
	V[v]=true;
	q.push(v);
      }
    }
  }
}
void tsort(){
  for(int i=0;i<N;i++){
    indeg[i]=0;
  }
  for(int u=0;u<N;u++){
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      indeg[v]++;
    }
  }
  
  for(int u=0;u<N;u++){
    if(indeg[u]==0&&!V[u]) bfs(u);
  }
  
  for(list<int>::iterator it=out.begin(); it!=out.end();it++){
    cout<<*it<<endl;
  }
}

int main(){
  int s,t,M;
  cin>>N>>M;
  for(int i=0;i<N;i++){
    V[i]=false;
  }for(int i=0;i<M;i++){
    cin>>s>>t;
      G[s].push_back(t);
    }
  
  tsort();
  
  return 0;
}



Measured memory_bytes: 6188
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int x = readint;
    int a = readint;
    int b = readint;

    /*
    int donut = (x - a) / b;
    writeln(x - a - b * donut);
    */

    writeln((x - a) % b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
//using namespace __gnu_pbds;
bool comp(pll a, pll b){
        return a.y < b.y;
    }   
int main(){
	IOS;
	ll n;
	cin >> n;
	pll a[n + 1];
	loop(i, 1, n + 1)
		cin >> a[i].x >> a[i].y;
	if(n % 2 == 1){
		sort(a + 1, a + n + 1);
		ll l = a[ (n + 1) / 2].x;
		sort(a + 1, a + n + 1, comp);
		ll r= a[(n + 1) / 2].y;
		cout << r - l + 1 << endl;
	}else{
		sort(a + 1, a + n + 1);
		ll l1 = a[ n / 2].x, l2 = a[(n / 2) + 1].x;
		sort(a + 1, a + n + 1, comp);
		ll r1 = a[ n / 2].y, r2 = a[(n / 2) + 1].y;
		
			
		ll ans = (r2 - l2 + 1) + (r1 - l1 + 1) - 1;
		cout << ans  << endl;

	}
}

Measured memory_bytes: 6720
#include<iostream>
using namespace std;
int main(void)
{
  char a[10000];
  while(cin>>a)
    {
  int countj=0,counti=0;
  for(int i=0;i<10000-2;i++)
    {
      if(a[i]=='J' && a[i+1]=='O' && a[i+2]=='I')countj++;
      else if(a[i]=='I' && a[i+1]=='O' && a[i+2]=='I')counti++;
    }
for(int i=0;i<10000;i++)
    {
      a[i]='0';
    }
  cout<<countj<<endl;
  cout<<counti<<endl;
    }
  return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(5);
  for(int i=0; i<5; i++)cin >> a[i];
  vector<int> b(5);
  for(int i=0; i<5; i++){
    b[i]=a[i]%10;
  }
  bool flag = true;
  for(int i=0; i<5; i++){
    if(b[i]!=0) flag=false;
  }
  if(flag) cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl;
  else{
    sort(b.begin(),b.end(),greater<int>());
    int min=b[0];
    for(int i=1; i<5; i++){
      if(b[i]==0)break;
      else min=b[i];
    }
    int sum=0;
    for(int i=0; i<5; i++){
      if(a[i]%10==0){
        sum+=a[i];
      }
      else{
        sum+=(a[i]/10+1)*10;
      }
    }
    cout << sum-(10-min) << endl;

  }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	int H,W; cin >> H >> W;
	char s[1000][1000];
	int d[1000][1000];
	queue <P> Q;
	
	rep(i,H)rep(j,W){
	    cin >> s[i][j];
	    if (s[i][j]=='#'){
	        Q.push({i,j});
	        d[i][j]=0;
	    }else{
	        d[i][j]=INF;
	    }
	}
	
	while (!Q.empty()) {
		int y = Q.front().first;
		int x = Q.front().second;
		Q.pop();
		for (int k=0; k<4; k++){
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == '.'&&d[ny][nx]==INF) {
				Q.push({ ny,nx });
				d[ny][nx] = d[y][x] + 1;
			}
		}
	}
	
	int ans = 0;
	rep(i,H)rep(j,W){
		if (d[i][j]==0)continue;
		ans = max(ans, d[i][j]);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int main()
{
	int q1,b,c1,c2,q2;
	while(cin >> q1 && q1)
	{
		cin >> b >> c1 >> c2 >> q2;
		
		if(c1 + c2 * (q1 - 1) > b) cout << "NA" << endl;
		else
		{
			int cnt = 1,cnt_2 = q1 - 1,res = c1 + c2 * (q1 - 1);

			while(res + c1 - c2 <= b && cnt_2 > 0)
			{
				if(cnt < q2)
				{
					res += c1 - c2;
					cnt++;
					cnt_2--;
				}
				else break;
			}

			if(cnt < q2)
			{
				while(res + c1 <= b && cnt < q2)
				{
					res += c1;
					cnt++;					
				}
			}

			while(res + c2 <= b)
			{
				res += c2;
				cnt_2++;
			}

			cout << cnt << " " << cnt_2 << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<int> vx(n);
  for (int i = 0; i < n; ++i) {
    cin >> vx[i];
  }
  
  int ans = 0;
  for (int i = 0; i < vx.size(); ++i) {
    ans += min(vx[i], abs(vx[i] - k)) * 2;
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3636
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run(){
	n := next()
	
	for i, v := range n {
		if(i%2 != 0){
			if(string(v) == "R"){
				Println("No")
				return
			}
		}else{
			if(string(v) == "L"){
				Println("No")
				return
			}
		}
	}
	Println("Yes")
	
}
 
 
// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}

func readIntArray(n int) ([]int) {
	v := make([]int, 0)
	for i := 0; i < n; i++ {
		v = append(v, nextInt())
	}
	return v
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}

Measured memory_bytes: 2816
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val n: Int = sc.nextLine.toInt
    val Array(d, x) = sc.nextLine.split(" ").map(_.toInt)
    val participants: List[Int] = List.fill(n)(sc.nextInt)
    println(participants.map(
      day => (0 to d).map(i => i * day + 1).takeWhile(i => i<=d).length
    ).sum + x)
  }

}


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

using namespace std;

using ll = long long int;

ll gcd(ll a, ll b) {
    if(a%b == 0)
        return b;

    return gcd(b, a%b);
}

int main() {
    ll N,X; cin >> N >> X;
    vector<ll> x(N);

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

    ll ans = abs(x[0] - X);

    for(int i=1;i<N;i++) {
        ans = gcd(ans, abs(x[i] - X));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
//import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
//import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		switch(s[0]) {
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
			out.println("vowel");
			break;
		default:
			out.println("consonant");
			break;
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
ll dp[105][100005];
ll  n ,w ;
ll wt[105] , v[105];
ll solve(ll curr , ll w)
{
    if(curr == 0 ) return 0 ;
    if(w <=0) return 0;
    if(dp[curr][w] !=-1) return dp[curr][w];
    ll foo = solve(curr-1 ,w);
    ll foo1 = 0;
    if(w - wt[curr] >= 0){
    foo1= v[curr] + solve(curr-1 , w-wt[curr]);
    }
    dp[curr][w] = max(foo , foo1 );
    return max(foo , foo1);
}

int main()
{
    ios;
    memset(dp , -1 , sizeof dp);
    cin >> n >> w ;
    memset(wt , 0 , sizeof wt);
    memset(v , 0  , sizeof v);
    for(ll i =1 ;i<=n;++i){
        ll x, y ;
        cin >> x>> y;
        wt[i] = x;
        v[i] = y;
    }
    ll foo = solve(n , w);
    cout << foo <<endl;
    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int64_t> v(N);
	for (int i = 0; i < N; i++) cin >> v.at(i);
	sort(v.begin(), v.end());

	bool b = false;
	int cnt = 1;
	vector<int64_t> va;

	for (int i = N - 1; i > 0; i--) {
		if (v.at(i) == v.at(i - 1)) {
			cnt++;
		}

		if ((i == 1) || (v.at(i) != v.at(i - 1))) {
			if (cnt >= 4) {
				va.push_back(v.at(i));
				b = true;
				break;
			}
			else if (cnt >= 2) {
				va.push_back(v.at(i));
				cnt = 1;

				if (va.size() > 1) {
					b = true;
					break;
				}
			}
		}

		//cout << cnt << endl;
	}

	//for (int i = 0; i < va.size(); i++) cout << va.at(i) << endl;

	if (!b) {
		cout << 0 << endl;
	}
	else {
		if (va.size() == 1) {
			cout << va.at(0) * va.at(0) << endl;
		}
		else {
			cout << va.at(0) * va.at(1) << endl;
		}
	}
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

int dp[2020][2020];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N;
    cin >> N;
    vi A(N);
    max_heap<pair<int, int>> pq;
    rep(i, 0, N) {
        cin >> A[i];
        pq.emplace(A[i], i);
    }
    memset(dp, 0, 2020 * 2020 * sizeof(dp[0][0]));

    int i = 0;
    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        int idx = p.second;
        int a = p.first;
        rep(j, 0, i + 1) {
            int l = j;
            int r = i - j;
            chmax(dp[i + 1][j], dp[i][j] + abs(N - 1 - r - idx) * a);
            chmax(dp[i + 1][j + 1], dp[i][j] + abs(idx - l) * a);
        }
        i++;
    }

    int ans = 0;
    rep(i, 0, N + 1) {
        chmax(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35620
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()

int n, m, x;

void solve()
{
	cin >> n >> m >> x;
	vector<int> cost(n);
	cost.resize(n);
	vector<vector<int>> v;
	v.assign(n, vector<int>(m));
	for (int i = 0; i < n; ++i)
	{
		cin >> cost[i];
		for (int j = 0; j < m; ++j)
		{
			cin >> v[i][j];
		}
	}
	int LIM = (1 << n);
	int mncost = (int)1e18;
	for (int mask = 0; mask < LIM; ++mask)
	{
		vector<int> fin(m, 0);
		int ct = 0;
		for (int i = 0; i < n; ++i)
		{
			if (((mask >> i) & 1))
			{
				ct += cost[i];
				for (int j = 0; j < m; ++j)
				{
					fin[j] += v[i][j];
				}
			}
		}
		bool valid = true;
		for (auto &y : fin)
			valid &= (y >= x);
		if (valid)
		{
			mncost = min(mncost, ct);
		}
	}
	if (mncost == (int)1e18)
	{
		cout << -1 << '\n';
		return;
	}
	cout << mncost << '\n';
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	//cin >> T;
	for (int i = 1; i <= T; ++i)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    int n;cin >> n;
    vector<string> v;
    rep(i,n) {
        string s;
        cin>>s;
        v.pb(s);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size();
}


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

int main()
{
	int w, a, b;
	cin >> w >> a >> b;
	if ((a + w) < b)
		printf("%d\n", b - a - w);
	else
		if ((a + w) >= b && (a < (b + w)))
			printf("0\n");
		else
			if ((b + w) == a)
				printf("0\n");
			else
				if ((b + w) < a)
					printf("%d\n", a - b - w);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  int count=0; 
  int ans=0;
  int last = s[n-1];
  sort(s.begin(), s.end());
  for(int i=last;i>0;i--){
    if(ans==0){
      for(int j=0; j<n;j++){
        if(s[j]%i != 0){
          count+=1;
        }
        if(count>1){
          count = 0;
          break;
        }
        if(j<n-1){
          continue;
        }
        ans = i;
      }
    }
  }
  cout << ans << endl;
}
      
      

Measured memory_bytes: 640
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def size(self, x):
        return -self.root[self.find_root(x)]


N, K, L = map(int, input().split())
UFc = UnionFind(N)
UFt = UnionFind(N)
for _ in range(K):
    p, q = map(int, input().split())
    UFc.unite(p, q)
for _ in range(L):
    p, q = map(int, input().split())
    UFt.unite(p, q)

gr = [0] * (N + 1)
cnt = defaultdict(int)
for i in range(1, N + 1):
    gr[i] = UFc.find_root(i) * (N + 1) + UFt.find_root(i)
    cnt[gr[i]] += 1

ans = [0] * N
for i in range(1, N + 1):
    ans[i-1] = cnt[gr[i]]

print(*ans)


Measured memory_bytes: 117224
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,pair<int,int> > P;

ll dp[110000];

int main(){
    bool C[110000];
    int N,M;
    int a;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>a;
        C[a]++;
    } 
    dp[0]=1;
    for(int i=0;i<N;i++){
        if(C[i]) continue;
        dp[i+1]+=dp[i];
        dp[i+2]+=dp[i];
        dp[i+1]%=MOD;
        dp[i+2]%=MOD;
    }
    cout<<dp[N]<<endl;
}


Measured memory_bytes: 1152
#!/usr/bin/env python
import copy

def bubble_sort(card, N):
    for i in range(0, N):
        for j in range(N-1, i, -1):
            if value(card[j]) < value(card[j-1]):
                card[j], card[j-1] = card[j-1], card[j]
    return " ".join(map(str, card))


def selection_sort(card, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if value(card[j]) < value(card[minj]):
                minj = j
        card[i], card[minj] = card[minj], card[i]
    return " ".join(map(str, card))


# check method
# insertion sort is a stable sort.
def insertion_sort(card, N):
    for i in range(1, N):
        v = card[i]
        j = i - 1
        while j >= 0 and value(card[j]) > value(v):
            card[j+1] = card[j]
            j -= 1
        card[j+1] = v
    return " ".join(map(str, card))


def value(elem):
    return elem[1]


def main():
    size = int(input())
    line = input().split()
    gold_standard = insertion_sort(copy.deepcopy(line), copy.deepcopy(size))

    bubble_ans = bubble_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(bubble_ans)
    if bubble_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')

    selection_ans = selection_sort(copy.deepcopy(line), copy.deepcopy(size))
    print(selection_ans)
    if selection_ans == gold_standard:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    main()

Measured memory_bytes: 8196