akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n;
  cin >> n;

  string s;
  cin >> s;

  vvi ta(n,vi(10,-1));
  vi ne(10,-1);
  rrep(i,n-1,-1){
    rep(j,10)
      ta[i][j] = ne[j];
    ne[s[i]-'0']=i;
  }

  i64 ans = 0;
  rep(i,10){
    if(ne[i]==-1) continue;
    i64 cur1 = ne[i];
    rep(ii,10){
      if(ta[cur1][ii]==-1) continue;
      i64 cur2 = ta[cur1][ii];
      rep(iii,10){
        if(ta[cur2][iii]==-1) continue;
        ans++;
      }
    }
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 3840
import sys
N,K = map(int,input().split())
tele = list(map(int,input().split()))
k = 1
flag = [0]*N
goal = tele[0]
miti = [1]
while (flag[goal-1])!=1:
    k += 1
    miti.append(goal)
    flag[goal-1] = 1
    goal = tele[goal-1]
    if k == K:
        print(goal)
        sys.exit()

a = miti.index(goal)
loop = k-a
ans = miti[(K-a)%loop+a]

print(ans)

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

typedef pair<long long, long long> pi;

long long h, w, nx, ny, g[9][9], v[9][9], dx[]={1, 0}, dy[]={0, 1};
char c;
queue<pi> q;
int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> c;
			if(c == '#') g[i][j] = 0;
			else g[i][j] = 1;
		}
	}
	q.push(pi(0, 0));
	while(!q.empty()){
		pi f = q.front(); q.pop();
		v[f.first][f.second] = 1;
		for(int i = 0; i < 2; i++){
			nx = f.first+dx[i];
			ny = f.second+dy[i];
			if(nx < 0 || ny < 0 || nx >= h || ny >= w || g[nx][ny] == 1 || v[nx][ny] == 1) continue;
			q.push(pi(nx, ny));
			break;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(g[i][j] == 0 && v[i][j] == 0){
				cout << "Impossible";
				return 0;
			}
		}
	}
	cout << "Possible";
}

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

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int x = in.nextInt();
        int a = in.nextInt();
        System.out.println(x < a ? 0 : 10);
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}

int main()
{
    int a, b;
    cin >> a >> b;
    if(a % b == 0){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m, 0));
    vector<int> B(m, 0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++) cin >> B[i];
    for (int i = 0; i < n; i++) {
        int ans = 0;
        for (int j = 0; j < m; j++) {
            ans += A[i][j] * B[j];
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3216
def solve():
    X,N = map(int,input().split())
    p = list(map(int,input().split()))

    if not (X in set(p)):
        print(X)
        return

    bucket = [False] * 102
    for i in range(N):
        bucket[p[i]] = True
    
    high = 0
    low = 0
    for i in range(X,102):
        if not bucket[i]:
            high = i
            break

    for i in range(X,0,-1):
        if not bucket[i]:
            low = i
            break

    if abs(X-high) > abs(X-low):
        print(low)
    elif abs(X-high) == abs(X-low):
        print(min(low,high))
    else:
        print(high)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 61960
import java.util.Scanner;
import java.util.stream.IntStream;

class Main{

    private static Scanner scan = new Scanner(System.in);

    public static void main(String args[]){
        int N = scan.nextInt();
        int A[] = loading(N),B[] = loading(N), C[] = loading(N);

        long[] BbtC = new long[N];
        int Cindex =0;
        for(int i=0;i<N;++i){
            while(Cindex < N && C[Cindex] <= B[i])++Cindex;
            BbtC[i] = N-Cindex;
        }
        for(int i=N-1;i>0;--i){
            BbtC[i-1] += BbtC[i];
        }

        long ans =0;
        int Bindex =0;
        for(int i=0;i<N;++i){
            while(Bindex < N && B[Bindex] <= A[i])++Bindex;
            ans += (Bindex < N ?BbtC[Bindex] : 0);
        }
        System.out.println(ans);

    }

    private static int[] loading(int N){
        return IntStream.range(0,N)
                .map(i -> scan.nextInt())
                .sorted()
                .toArray();
    }
}

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

A, B, M = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

i = 200000


for j in range(M):
    
    #c = 'c' + str(j)
    c =  list(map(int, input().split()))
    ma = c[0] - 1
    mb = c[1] - 1
    h = a[ma] + b[mb] - c[2]

    if i >= h:
        i = h

m = min(a) + min(b)

if i >= m:
    i = m

print(i)


Measured memory_bytes: 66904
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 101;
int main() {
    int n;
    cin>>n;
    vector<bool> v(N, false);
    while(n--) {
        int x;
        cin>>x;
        v[x] = true;
    }
    int nr = count_if(v.begin(), v.end(), [](bool x){return  x;});
    cout<<nr<<endl;
    return 0;
}

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

const int mxA = 1e6;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<int> count(mxA + 1);
	int n;
	cin >> n;
	vector<int> a(n);
	bool pairwise = true;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		count[a[i]]++;
	}
	vector<bool> is_prime(mxA + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 0; i <= mxA; i++) {
		if (is_prime[i]) {
			int cnt = 0;
			for (int j = i; j <= mxA; j += i) {
				cnt += count[j];
				is_prime[j] = false;
			}
			if (cnt >= 2) {
				pairwise = false;
			}
		}
	}
	if (pairwise) {
		cout << "pairwise coprime";
		return 0;
	}
	int gcd = 0;
	for (int i = 0; i < n; i++) {
		gcd = __gcd(gcd, a[i]);
	}
	if (gcd == 1) {
		cout << "setwise coprime";
	} else {
		cout << "not coprime";
	}
}



Measured memory_bytes: 11372
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 100000;
int n;
int v[MAX_N];

int main(){
  int a1[MAX_N + 1], a2[MAX_N + 1];
  REP(i, MAX_N + 1) {
    a1[i] = 0;
    a2[i] = 0;
  }
  cin >> n;
  REP(i, n) cin >> v[i];
  REP(i, n) {
    if(i % 2 == 0) {
      a1[v[i]]++;
    } else {
      a2[v[i]]++;
    }
  }

  int mva1 = 0, mva2 = 0, mia1 = 0, mia2 = 0, mv2a1 = 0, mv2a2 = 0;
  REP(i, MAX_N + 1) {
    if(mva1 <= a1[i]) {
      mv2a1 = mva1;
      mia1 = i;
      mva1 = a1[i];
    } else if(mv2a1 <= a1[i]) {
      mv2a1 = a1[i];
    }

    if(mva2 <= a2[i]) {
      mv2a2 = mva2;
      mia2 = i;
      mva2 = a2[i];
    } else if(mv2a2 <= a2[i]) {
      mv2a2 = a2[i];
    }
  }

  if(mia1 == mia2) {
    cout << n - max(mv2a1 + mva2, mva1 + mv2a2) << endl;
  } else {
    cout << n - mva1 - mva2 << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    string s; cin >> s;

    if (s.size()<2) {
        cout << "-1 -1" << endl;
        return 0;
    }
        

    for(int i=0; i<s.size()-1; i++){
        if (s[i]==s[i+1]) {
            cout << i+1 << " " << i + 2 <<endl;
            return 0;
        }
    }
    for(int i=0; i<s.size()-2; i++){
        if (s[i]==s[i+2]) {
            cout << i+1 << " " << i + 3 <<endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;

    return 0;
}

Measured memory_bytes: 512
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int idx[] = {0, 4, 6, 8};
signed main() {
    set<string> S;
    rep(bit,0,1<<4) {
        string tmp = "AKIHABARA";
        repr(k,3,0) {
            if(bit >> k & 1) {
                tmp.erase(tmp.begin() + idx[k]);
            }
        }
        // cout << tmp << endl;
        S.insert(tmp);
    }

    string s; cin >> s;
    cout << (S.count(s) ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//1-i j-1 0- i-1 j 2- i-1 j-1 
 int main()
 {
     string s,t;
     cin>>s>>t;
     int n=s.length(),m=t.length();
     long long int dp[n+1][m+1];
     long long int choice[n+1][m+1];
     
     for(int i=0;i<=n;i++)
         for(int j=0;j<=m;j++)
         dp[i][j]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(dp[i][j-1]>dp[i][j])
            {dp[i][j]=dp[i][j-1];
            choice[i][j]=1;
            }
            if(dp[i-1][j]>dp[i][j])
            {
                dp[i][j]=dp[i-1][j];
                choice[i][j]=0;
            }
            if(dp[i-1][j-1]+1>dp[i][j] and s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                choice[i][j]=2;
            }
        }
    }
    int i=n,j=m;
    string ans="";
    while(i>0 and j>0)
    {
        if(choice[i][j]==2)
        {
            ans.push_back(s[i-1]);
            i--;
            j--;
        }
        else if(choice[i][j]==1)
        j--;
        else
        i--;
        
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    
         
     
 }

Measured memory_bytes: 144328
#include <iostream>
#include <map>

using namespace std;

typedef long long llong;

int N, M;
map< int, int, greater<int> > A;

llong solve() {
	llong res = 0;

	for ( int i = 0; i < M; i++ ) {
		int B, C;
		scanf("%d %d", &B, &C);

		A[C] += B;
	}
	int n = 0;
	for ( map< int, int>::iterator it = A.begin(); n < N; it++ ) {
		res += llong(it->first) * llong(min(N - n, it->second));
		n += it->second;
	}

	return res;

}

int main() {
	scanf("%d %d", &N, &M);

	for ( int i = 0; i < N; i++ ) {
		int a;
		scanf("%d", &a);
		A[a]++;
	}

	printf("%lld\n", solve());
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N, K; cin >> N >> K;
    vec a(N); readv(a);
    int mod = 1000000007;

    mat dp(N + 1, vec(K + 2, 0));
    dp[0][1] = 1;
    REP(i, N){
        REP(j, K + 1){
            dp[i][j + 1] += dp[i][j];
            dp[i][j + 1] %= mod;
        }
        REP(j, K + 1){
            dp[i + 1][j + 1] = (dp[i][j + 1] - dp[i][max(j - a[i], 0LL)] + mod) % mod;
        }
    }
    cout << dp[N][K + 1];

    return 0;
}

Measured memory_bytes: 80256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kamol Paul
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define long long long
typedef pair < long , long > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
class BCountBalls {
public:
	void solve(std::istream& in, std::ostream& out) {
	    long n,a,b;
	    in>>n>>a>>b;
	    long r = n %(a+b);
	    long ans = n/(a+b);
	    ans *=a;
	    ans += min(a,r);
	    out<<ans<<endl;

	}
};


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	BCountBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
		ll r;
		cin>>r;
		cout<<r*r<<"\n";
		return 0;
}
	

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    if( a < 10){
        if ( b < 10){
            cout << a * b << endl;
        }
        else{
        cout << -1 << endl;
        }

    }
    else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
// #include <cctype>

using namespace std;

typedef pair<int, int> Coordinate;
typedef vector<Coordinate> Coordinates;

void output(const vector<int> &);
bool place(const vector<int> &, int pos);
void back_trace(vector<int> & queen, Coordinates & coordinates, int current, int total);
bool match(const vector<int> & queen, const Coordinates & coordinates);


int main()
{
    Coordinates coordinates;
    vector<int> queen(8);

    int n;
    cin >> n;

    coordinates.resize(n);

    int i = 0;
    while (i < n)
    {
        cin >> coordinates[i].first >> coordinates[i].second;
        i++;
    }

    back_trace(queen, coordinates, 0, 8);

}


void output(const vector<int> & queen)
{
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
            if (queen[i] == j)
                cout << 'Q';
            else
                cout << '.';
        cout << endl;        
    }


}


bool place(const vector<int> & queen, int current)
{
    for (int i = 0; i < current; i++)
        if (queen[current]==queen[i] || abs(current-i)==abs(queen[current]-queen[i]))
            return false;
    return true;
}




void back_trace(vector<int> & queen, Coordinates & coordinates, int current, int total)
{
    if (current >= total)
    {
        if (match(queen, coordinates))
            output(queen);        
    }
    else
    {
        for (int i = 0; i < total; i++)
        {
            queen[current] = i;
            if (place(queen, current))
                back_trace(queen, coordinates, current+1, total);
        }
    }

}


bool match(const vector<int> & queen, const Coordinates & coordinates)
{
    for (int i = 0; i < coordinates.size(); i++)
    {
        if (queen[coordinates[i].first] != coordinates[i].second)
            return false;
    }
    return true;
}


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

int main()
{
 long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long ans,ans1,anss;
  ans=0;
  ans1=0;
  anss=0;
  ans=max(a*c,a*d);
 // cout<<a*c<<endl;
   ans1=max(b*c,b*d);
  anss=max(ans,ans1);
  cout<<anss<<endl;
  
}


Measured memory_bytes: 3576
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a) { return (a % mod + mod) % mod; }

inline ll add(ll a, ll b) { return take_mod(a + b); }

inline ll sub(ll a, ll b) { return take_mod(a - b); }

inline ll mul(ll a, ll b) { return take_mod(a * b); }

inline ll pow(ll x, ll n) {
  ll res = 1LL;
  while (n > 0) {
    if (n & 1) res = mul(res, x);
    x = mul(x, x);
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x) { return pow(x, mod - 2); }

void make_fact(ll n) {
  fact[0] = 1;
  ll res = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = res;
    res = mul(res, i + 1);
  }
}

void make_invfact(ll n) {
  invfact[0] = 1;
  invfact[n] = mod_inv(fact[n]);
  for (int i = n - 1; i >= 1; i--) {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
}

ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); }

ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); }

const ll INF = 1 << 30;

vll to[2505];
vll rto[2505];
bool rblFrom1[2505];
bool rblToN[2505];
bool ok[2505];

void dfs(ll v) {
  if (rblFrom1[v]) return;
  rblFrom1[v] = true;
  for (auto u : to[v]) {
    dfs(u);
  }  // u
}

void rdfs(ll v) {
  if (rblToN[v]) return;
  rblToN[v] = true;
  for (auto u : rto[v]) {
    rdfs(u);
  }  // u
}

int main() {
  ll n, m, p;
  cin >> n >> m >> p;
  vector<tuple<ll, ll, ll>> es;

  for (ll i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c -= p;
    c = -c;
    es.emplace_back(a, b, c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(n - 1);
  for (ll i = 0; i < n; i++) ok[i] = rblFrom1[i] && rblToN[i];

  {  // Bellman-Ford
    vll d(n, INF);
    ll step = 0;
    d[0] = 0;
    bool upd = true;
    while (upd) {
      upd = false;
      for (auto e : es) {
        ll a, b, c;
        tie(a, b, c) = e;
        if (!ok[a]) continue;
        if (!ok[b]) continue;
        ll newD = d[a] + c;
        if(newD < d[b]){
          upd = true;
          d[b] = newD;
        }
      }  // e
      if(step > n){
        puts("-1");
        return 0;
      }
      step++;
    }  // while

    ll ans = -d[n-1];
    chmax(ans, 0LL);
    cout << ans << endl;
  } // Bellman-Ford

  return 0;
}


Measured memory_bytes: 768
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int i;
    string S;
    string T;
    cin >> S;
    cin >> T;

    if(T.length() - S.length() != 1){cout << "No" << endl;return 0;}
    else{
        for(i=0;i<S.length();i++){
            if(T[i] != S[i]){cout << "No" << endl;return 0;}
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3088
N = int(input())
a = list(map(int, input().split()))

bl = True

amount = N * (N + 1) // 2  # 一回の操作で除去される石の量
q1, r1 = divmod(sum(a), amount)  # q: 操作の回数
if r1 != 0:
    bl = False
else:
    d = [a[(i + 1) % N] - a[i] for i in range(N)]
    d = list(map(lambda x: x - q1, d))

    cnt = 0
    for dd in d:
        if dd > 0:
            bl = False
            break
        else:
            q2, r2 = divmod(-dd, N)
            if r2 > 0:
                bl = False
                break
            else:
                cnt += q2
    bl &= (cnt == q1)

print('YES' if bl else 'NO')


Measured memory_bytes: 14436
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

	void CCout(long long x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const T& x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cerr << x[i] << (i == sz - 1 ? end : sep); } }

	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one
}

int main() {

	ll x = inp1;

	ll ans = 0;
	ans += (x / 500) * 1000;
	ans += ((x % 500) / 5) * 5;

	Cout(ans);

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
k=int(input())
logl=len(str(k))

def bfs(nowres, result=[]):
  if len(result) >= k:
    return sorted(result)
  rescand=[]
  for res in nowres:
    eq=res*10+res%10
    rescand.append(eq)
    if eq % 10>0:
      rescand.append(eq-1)
    if eq % 10<9:
      rescand.append(eq+1)
  return bfs(rescand, result+nowres)

res=bfs(list(range(1,10)))
#print(res)
print(res[k-1])

Measured memory_bytes: 112024
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).OrderBy(i => i).ToList();
            var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).OrderBy(i => i).ToList();
            var c = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).OrderBy(i => i).ToList();
            long[] memo = new long[n];
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                while (c.Any())
                {
                    if (b[i] >= c[0]) c.RemoveAt(0);
                    else break;
                }
                memo[i] = c.Count();
            }
            long now = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                now += memo[i];
                memo[i] = now;
            }
            now = 0;
            for (int i = 0; i < n; i++)
            {
                while (a[i] >= b[(int)now])
                {
                    now++;
                    if (now >= n)
                    {
                        now = n - 1;
                        memo[n - 1] = 0;
                        break;
                    }
                }
                ans += memo[now];
            }
            Console.WriteLine(ans);
        }
    }
}

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

string s;

int main() {
	cin >> s;

	int cs = -1, ce = -1;
	for (int i = 0; i < s.length();i++) {
		//cout << i << endl;
		if (cs == -1 && s[i] == 'A') {
			cs = i;
		}
		if (s[i] == 'Z') {
			ce = i;
		}
	}

	cout << ce - cs + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll gcd(ll a,ll b){if(a<b)swap(a,b);return b?gcd(b,a%b):a;}

constexpr ll MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  ll zero = 0;
  map<tuple<ll,ll>, ll> m0;
  map<tuple<ll,ll>, ll> m1;
  REP(i,n) {
    ll x,y;
    cin>>x>>y;
    ll g = gcd(abs(x), abs(y));
    if (x == 0 && y == 0) {
      ++zero;
      continue;
    }
    x /= g;
    y /= g;
    if (x < 0 || (x == 0 && y < 0)) {
      x = -x;
      y = -y;
    }
    if (y <= 0) {
      auto tmp = x;
      x = -y;
      y = tmp;
      ++m1[make_tuple(x,y)];
    } else {
      ++m0[make_tuple(x,y)];
    }
  }
  vecll p2(n+1);
  p2[0] = 1;
  REP(i,n) {
    p2[i+1] = p2[i] * 2 % MOD;
  }
  ll ans = 0;
  for(auto&&p:m0) {
    auto t = p.first;
    ll tmp = (p2[p.second] + MOD - 1) % MOD;
    tmp += (p2[m1[t]] + MOD - 1) % MOD;
    m1.erase(t);
    tmp %= MOD;
    ans = ans * (tmp + 1) % MOD + tmp;
    ans %= MOD;
  }
  for(auto&&p:m1) {
    ll tmp = (p2[p.second] + MOD - 1) % MOD;
    ans = ans * (tmp + 1) % MOD + tmp;
    ans %= MOD;
  }
  cout<<ans+zero<<endl;
  return 0;
}


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

using namespace std;

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;

  const int g = a > b ? gcd(a, b) : gcd(b, a);

  int c = 0;
  for (int i = g; i >= 1; --i) {
    if (a % i == 0 && b % i == 0) {
      ++c;
    }
    if (c == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

long long joint[65500];

int main(void)
{
	long long n;
	while (cin >> n, n){
		if (n == 0){
			return 0;
		}
		
		long long sum = 0, a;
		for (int i = 0; i < n; i++){
			cin >> a;
			sum += a;
		}
		for (int i = 0; i < n-1; i++){
			cin >> joint[i];
			sum += joint[i];
		}
		sort(joint, joint + n-1);

		long long ret = sum;
		for (int i = 0; i < n-1; i++){
			sum -= joint[i];
			ret = max(ret, sum * (i+2));
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1680
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

# 左から順に見ていく
cnt = 1

n.times do |i|
  if a[i] == cnt
    cnt += 1
  end
end

if cnt == 1
  puts -1
else
  puts n-cnt +1
end




Measured memory_bytes: 16772
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

    int** A = new int*[2];
    for(int i = 0; i < 2; i++) 
    {
        A[i] = new int[N];
        for(int j = 0; j < N; j++)
            cin >> A[i][j];
    }

    int max_candy = 0;
    for(int j = 0; j < N; j++) {
        int sum = 0;
        for(int top = 0; top <= j; top++) sum += A[0][top];
        for(int bot = j; bot < N; bot++) sum += A[1][bot];

        if(max_candy < sum) max_candy = sum;
    }
    cout << max_candy << endl;
}

Measured memory_bytes: 256
void main()
{
    long n, ma, mb;
    rdVals(n, ma, mb);
    Medicine[] m = n.rdCol!Medicine;

    long limit = 10 * n + 1;
    long[][][] dp = new long[][][](n+1, limit, limit);
    foreach (i; 0 .. n+1)
    {
        foreach (j; 0 .. 10*n+1)
        {
            dp[i][j][] = inf;
        }
    }
    dp[0][0][0] = 0;
    foreach (i, x; m)
    {
        foreach (j; 0 .. limit)
        {
            foreach (k; 0 .. limit)
            {
                if (dp[i][j][k] == inf) continue;
                dp[i+1][j+x.a][k+x.b] = min(dp[i+1][j+x.a][k+x.b], dp[i][j][k]+x.c);
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
            }
        }
    }

    long result = inf;
    foreach (i; 1 .. 51)
    {
        long a = ma * i, b = mb * i;
        if (a >= limit || b >= limit) break;
        result = min(result, dp[n][a][b]);
    }
    if (result == inf) result = -1;

    result.writeln;
}

struct Medicine
{
    long a, b, c;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 68092
import java.lang.Long.parseLong
import java.util.*


// AC回答 mutableSet から TreeSet に変えている
fun main(args:Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map(Integer::parseInt)

    val list = mutableListOf<Triple<Long, Long, Boolean>>()
    for (i in 0 until N) {
        val (S, T, X) = readLine()!!.split(" ").map(java.lang.Long::parseLong)
        list.add(Triple(S-X, X, true))
        list.add(Triple(T-X, X, false))
    }
    list.sortBy { it.first }

    val D = LongArray(Q){parseLong(readLine()!!)}
    D.sort()
    val ans = mutableListOf<Long>()

    var l = 0
    val set = TreeSet<Long>()
    for (d in D) {
        while (l != list.size) {
            var q = list[l]
            if (q.first > d)
                break
            when(q.third){
                true->set.add(q.second)
                false->set.remove(q.second)
            }
            l++
        }
        ans.add(if (set.isEmpty()) -1 else set.first())
    }
    println(ans.joinToString("\n"))
}

Measured memory_bytes: 159556
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    if(a < 1 || a > 9 || b < 1 || b > 9){
        ans = -1;
    }else{
        ans = a * b;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int N;
  int *A;
  int *BK;
  scanf("%d", &N);
  A=(int*)malloc(sizeof(int)*(N+1));
  BK=(int*)malloc(sizeof(int)*(N+1));

  for (int i=2;i<=N;i++)
    scanf(" %d", &A[i]);
  for (int i=1;i<=N;i++)
    BK[i]=0;
  for (int j=2;j<=N;j++) {
        BK[A[j]]++;
  }

  for (int i=1;i<=N;i++)
    printf("%d\n",BK[i]);

  fflush(stdout);
  free(A);
  free(BK);
  return 0;
}

Measured memory_bytes: 3036
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
/// 最小公倍数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
  double T,X;
  cin >> T >> X;
  cout << T / X << endl;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int H,W,N;
  cin>>H>>W>>N;
  vector<int> A(H*W);
  int k=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    for(int j=0;j<a;j++)
      A[k+j]=i+1;
    k+=a;
  }
  for(int i=1;i<H;i+=2)
    reverse(A.begin()+i*W,A.begin()+(i+1)*W);
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++){
      cout<<A[i*W+j];
      if(j!=W-1)
        cout<<' ';
      else
        cout<<endl;
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>

using namespace std;

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);

void solve()
{
    int n;
    cin >> n;
    vector<char> stones(n);
    int whites = 0;
    for(auto& s : stones)
    {
        cin >> s;
        if (s == 'W')
            whites++;
    }

    // suppose an ordering of RRRR...RWWW...W, count number of whites inside R partition
    int swaps = 0;
    for(int i=0; i<n-whites; i++)
        if (stones[i] == 'W')
            swaps++;
    cout << swaps << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int nCases = 1;
    // cin >> nCases;

    while(nCases--)
        solve();

    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
    /*
    int a,b;
    cin >> a;
    b=a*a;
    b=b+b*a+a;
    cout << b;
    */
   char txt1[200010],txt2[200010];
   cin >> txt1;
   cin >> txt2;
   int count=0;
   int n=strlen(txt1);
   int i;
   for(i=0;i<n;i++){
       if (txt1[i]!=txt2[i]){
           count++;
       }
   }
   cout<<count;
}

Measured memory_bytes: 3932
#include <iostream>
#include <map>
#include <vector>

using namespace std;
int main(int argc, char const *argv[]) {
  long N, M;
  cin >> N >> M;
  vector<long> A(N);
  vector<long> sum(N);
  map<long, long> mp;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0) {
      sum[i] = A[i];
    } else {
      sum[i] = sum[i - 1] + A[i];
    }
  }

  long ans = 0;
  for (int i = 0; i < N; i++) {
    long mod = sum[i] % M;
    if (mod == 0) {
      ans++;
    }
    ans += mp[mod];
    mp[mod]++;
  }

  cout << ans << "\n";

  return 0;
}


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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            long N = int.Parse(line[0]);
            int K = int.Parse(line[1]);

            for(int i=0; ; i++)
            {
                if(Math.Pow(K,i) > N)
                {
                    Console.WriteLine(i);
                    break;
                }
            }


        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  const long long mod = 1000000007;
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> x(n);
  std::vector<long long> y(m);
  for (int i = 0; i < n; ++i) {
    std::cin >> x[i];
  }
  for (int i = 0; i < m; ++i) {
    std::cin >> y[i];
  }
  std::sort(x.begin(), x.end());
  std::sort(y.begin(), y.end());
  long long x_sum = 0ull;
  long long y_sum = 0ull;
  for (int i = 0; i < n; ++i) {
    x_sum += (2 * i - n + 1) * x[i];
    x_sum %= mod;
  }
  for (int i = 0; i < m; ++i) {
    y_sum += (2 * i - m + 1) * y[i];
    y_sum %= mod;
  }
  std::cout << (x_sum * y_sum) % mod << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b;
    int ans = max(a+b, a-b);
    ans = max(ans, a*b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#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 rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  ll N;
	ll a[5];
  cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  ll tmp=a[0];
  rep(i,5){
    tmp=min(tmp,a[i]);
  }
  if(N%tmp==0) cout << (N/tmp+4);
  else cout << (N/tmp+5);
  return 0;
}


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

int main(){

    int n;
    string str[50];

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

    int alpha_cnt[26][50];

    fill(alpha_cnt[0],alpha_cnt[26],0);

    for(int i=0; i<n; i++){
        for(int j=0; j<str[i].size(); j++){
            alpha_cnt[(int)(str[i][j]-'a')][i]++;
        }
    }

    for(int i=0; i<26; i++){

        int min_elem = *min_element(alpha_cnt[i],alpha_cnt[i]+n);

        for(int j=0; j<min_elem; j++){
            cout<<((char)('a'+i));
        }
    }
    cout<<endl;

    /*for(int i=0; i<3; i++){
        for(int j=0; j<n; j++){
            cout<<alpha_cnt[i][j]<<' ';
        }
        cout<<endl;
    }*/
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d", &a,&b);
	if (a < b){
		printf("a < b\n");
	}
	else if (a > b){
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int dp[110000][3];

int main()
{
    int n;
    cin >> n;
    rep(i,n){
        int p[3];
        cin >> p[0] >> p[1] >> p[2];
        rep(j,3)rep(k,3){
            if(j == k)continue;
            dp[i+1][k] = max(dp[i+1][k],dp[i][j]+p[j]);
        }
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)
const int MOD = 1e9+7;
const int MAX = 1e5+10;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
	REP(i, 2, MAX){
		fac[i] = fac[i-1]*i % MOD;
		inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
		finv[i] = finv[i-1]*inv[i] % MOD;
	}
}

ll comb(int n, int k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	return fac[n] * (finv[k]*finv[n-k] % MOD) % MOD;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[n+1], cnt[n] = {}, doub;
	REP(i, 0, n+1){
		scanf("%d", &a[i]);
		if(++cnt[a[i]-1]>1) doub = a[i];
	}

	int sep[3] = {}, pos = 0;
	REP(i, 0, n+1){
		if(a[i]==doub) pos++;
		else sep[pos]++;
	}

	combinit();
	REP(i, 1, n+2){
		ll ans = comb(n+1, i) - comb(sep[0]+sep[2], i-1);
		printf("%ld\n", (ans+MOD)%MOD);
	}
}


Measured memory_bytes: 6760
N, M = map(int, input().split())
edges = []
for _ in range(M):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    edges.append((x, y))

class UnionFind():
    """
    UnionFindTreeのクラス
    
    Attributes:
    n: int: ノード数
    parents: そのノードが属する木の根を格納, 根の場合は-1

    """
    def __init__(self, n):
        """ノード数nで初期化"""
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """ノード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が属するグループと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):
        """xが属するグループの要素数を返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """x, yが同じグループに属するかどうかを返す"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """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):
        """{root: [そのグループの要素リスト]}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """printデバッグ用. root: [要素リスト]をstrで返す"""
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(N)
for u, v in edges:
    uf.union(u, v)
print(uf.group_count())

Measured memory_bytes: 88192