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

const int N = 2e3 + 5;
const int MOD = 1e9 + 7;

int n, m;
int a[N], b[N];
int dp[N][N];

int recur(int i, int j)
{
    if(i > n)
        return 0;

    if(j > m)
        return 0;

    int &ans = dp[i][j];

    if(ans != -1)
        return ans;

    if(a[i] == b[j])
        ans = 1 + recur(i + 1, j) + recur(i, j + 1);
    else
        ans = recur(i + 1, j) + recur(i, j + 1) - recur(i + 1, j + 1);

    ans += MOD;
    ans %= MOD;
    return ans;
}

int32_t main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    int ans = recur(1, 1);
    ans++;
    ans %= MOD;
    cout << ans;
    return 0;
}


Measured memory_bytes: 31872
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;
//using Graph = vector<vector<int>>;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
LL sum(LL a, LL b){
    LL cnt=0;
    cnt=(b-a+1)*(a+b)/2;
    return cnt;
}
/*LL yaku(int x){
    vector<pair<LL, LL> a=[];
    LL xh;
    if(x==1){
        pair<LL, LL> tmp;
        tmp=MP(1,1);
        return tmp;
    }
    else{
        FOR(i, 1, x/2+1){
            if(x%i==0){
                a.append(MP(i,x/i));
            }
        }
    }
    return a;

}*/
LL cul(int a, int b){
    LL f = pow(a,4)+pow(a,3)*b+pow(a,2)*pow(b,2)+a*pow(b,3)+pow(b,4);
    return f;
} 
int main(){
    VI a(3);
    REP(i,3){
        cin >> a[i];
    }
    SORT(a);
    REP(i,3){
        cout << a[i];
        if(i==2) continue;
        cout << ' ';
    }
    cout << endl;
}
    





Measured memory_bytes: 3160
s = list(input())
fl = []
fr = []
l = len(s)
count = 0
ans = [0] * l
for c in s:
    if c == "R":
        count = 0
    else:
        count += 1
    fl.append(count)
for c in reversed(s):
    if c == "L":
        count = 0
    else:
        count += 1
    fr.append(count)
fr = list(reversed(fr))

for i, v in enumerate(s):
    if v == "R":
        if fr[i] % 2 == 0:
            ans[i + fr[i]] += 1
        else:
            ans[i + fr[i] - 1] += 1
    else:
        if fl[i] % 2 == 0:
            ans[i - fl[i]] += 1
        else:
            ans[i - fl[i] + 1] += 1

print(" ".join(map(str, ans)))

Measured memory_bytes: 16152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    
    map <string ,int> booll;

    string tmp1,tmp2,tmp3;
    cin >> tmp1 >> tmp2;
    cin >> booll[tmp1] >> booll[tmp2];

    cin >> tmp3;
    booll[tmp3]--;

    cout << booll[tmp1] << " " << booll[tmp2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll t; cin >> n >> t;
  vector<ll> T(n); rep(i, n) cin >> T[i];
  ll ans = 0;
  rep(i, n) {
    if(i == n-1) ans += t;
    else ans += t - max(0LL, t+T[i]-T[i+1]);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define r(i,n) for(int i = 1; i<=n; i++)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

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

int main() {
  int k,sum=0;
  cin >> k;
  r(i,k){
    r(j,k){
      r(h,k){
        sum+=gcd(i,gcd(j,h));
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;

namespace CsTest
{
    public class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            for(int i = 1; i < str.Length; ++i)
                if(str[i-1] == str[i])
                {
                    Console.WriteLine("Bad");
                    return;
                }

            Console.WriteLine("Good");
        }
    }
}

Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static class Node {
		int p = -1, l, r;
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			int l = Integer.parseInt(st.nextToken());
			int r = Integer.parseInt(st.nextToken());
			if (nodes[id] == null) nodes[id] = new Node();
			nodes[id].l = l;
			nodes[id].r = r;
			if (l != -1) {
				if (nodes[l] == null) nodes[l] = new Node();
				nodes[l].p = id;
			}
			if (r != -1) {
				if (nodes[r] == null) nodes[r] = new Node();
				nodes[r].p = id;
			}
		}
		int rootId = -1;
		for (int i = 0; i < n; i++) {
			if (nodes[i].p == -1) {
				rootId = i;
				break;
			}
		}
		
		System.out.println("Preorder");
		preOrder(nodes, rootId);
		System.out.println();
		System.out.println("Inorder");
		inOrder(nodes, rootId);
		System.out.println();
		System.out.println("Postorder");
		postOrder(nodes, rootId);
		System.out.println();
	}

	private static void preOrder(Node[] nodes, int u) {
		if (u == -1) return;
		System.out.print(" " + u);
		preOrder(nodes, nodes[u].l);
		preOrder(nodes, nodes[u].r);		
	}
	
	private static void inOrder(Node[] nodes, int u) {
		if (u == -1) return;
		inOrder(nodes, nodes[u].l);
		System.out.print(" " + u);
		inOrder(nodes, nodes[u].r);
	}

	private static void postOrder(Node[] nodes, int u) {
		if (u == -1) return;
		postOrder(nodes, nodes[u].l);
		postOrder(nodes, nodes[u].r);
		System.out.print(" " + u);
	}
}



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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF 1000000001
//536,870,912 * 2

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	long N;
	cin >>N;
	vector<vector<long>> A(N, vector<long> (N));
	vector<vector<long>> B;
	for (long i=0; i<N; i++)
		for (long j=0; j<N; j++) {
			cin >>A.at(i).at(j);
			if (0!=A.at(i).at(j))
				B.push_back({A.at(i).at(j), i, j});
		}
	sort(B.begin(), B.end());
	vector<vector<long>> AA(N, vector<long> (N, INF));
	vector<vector<long>> BB;
	for (long i=0; i<N; i++)
		AA.at(i).at(i)=0;
	for (long i=0; i<B.size(); i++) {
		long D=B.at(i).at(0);
		long X=B.at(i).at(1);
		long Y=B.at(i).at(2);
		if (D<AA.at(X).at(Y)) {
			BB.push_back({X, Y, D});
			AA.at(X).at(Y)=D;
			AA.at(Y).at(X)=D;
			for (long Z=0; Z<N; Z++) {
				if (INF==AA.at(Z).at(X))
					continue;
				for (long W=0; W<N; W++) {
					if (INF==AA.at(Y).at(W))
						continue;
					long DD=AA.at(Z).at(W);
					if (DD<=D)
						continue;
					long DDD=AA.at(Z).at(X)+D+AA.at(Y).at(W);
					if (DD>DDD) {
						AA.at(Z).at(W)=DDD;
						AA.at(W).at(Z)=DDD;
					}
				}
			}
		} else if (D==AA.at(X).at(Y)) {
			continue;
		} else {
			cout <<-1 <<endl;
			return 0;
		}
	}
	long S=0;
	for (long i=0; i<BB.size(); i++)
		S +=BB.at(i).at(2);
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 7604
#include "bits/stdc++.h"
using namespace std;
#define INF (1 << 29)

const int MAX_V = 1000;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;

int prim() {
	for (int i = 0; i<V; i++) {
		mincost[i] = INF;
		used[i] = false;
	}
	mincost[0] = 0;
	int res = 0;

	while (true) {
		int v = -1;
		// Xに属さない頂点のうちXからの辺のコストが最小になる頂点を探す
		for (int u = 0; u<V; u++) {
			if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
		}

		if (v == -1) break;
		used[v] = true;     // 頂点vをXに追加
		res += mincost[v];  // 辺のコストを加える

		for (int u = 0; u<V; u++) {
			mincost[u] = min(mincost[u], cost[v][u]);
		}
	}
	return res;
}


int main() {
	cin >> V;

	for (int i = 0; i<V; i++) {
		for (int j = 0; j<V; j++) {
			int e; cin >> e;
			cost[i][j] = (e == -1) ? INF : e;
		}
	}

	cout << prim() << endl;
}



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

int main() {
	int n;
	cin >> n;
	int a[n];

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

	for (int j = 0; j < n / 2; j++){
		swap(a[j], a[n - j - 1]);
	}

	for (int k =0; k < n; k++){
		cout << a[k];
		if (k != n - 1) cout << " ";
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 3080
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String... args) {

        Scanner sc = new Scanner(System.in);
        String w = sc.next();

        List<String> s = Arrays.asList(w.split(""));

        String res = "Yes";
        for (int i=0;i<s.size();i++) {
            List<String> l = Arrays.asList(w.split(""));
            int cnt = 0;
            for (String val:l) {
                if (s.get(i).equals(val)) {
                    cnt = cnt + 1;
                }
            }
            if (cnt % 2 != 0) {
                res = "No";
                break;
            }
        }

        System.out.println(res);
    }

}

Measured memory_bytes: 10320
#include<bits/stdc++.h>
using namespace std;
struct Node
{
	string s;
	int times;
};
Node data[200005];
bool cmp(Node a,Node b)
{
	return a.s<b.s;
}
string dang;
int max1;
int main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>data[i].s;
	}
	sort(data,data+n,cmp);
	for(int i=0;i<n;i++)
	{
		dang=data[i].s;
		int j;
		for(j=i+1;j<n;j++)
		{
			if(data[j].s==dang)
			{
				continue;
			}
			else break;
		}
		data[i].times=j-i;
		i=j-1;
	}
	for(int i=0;i<n;i++)
	{
		if(data[i].times>max1)
		{
			max1=data[i].times;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(data[i].times==max1)
		{
			cout<<data[i].s<<'\n';
		}
	}
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A;
  A.push_back(0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  A.push_back(0);

  long long orgdist = 0;
  for (int i = 1; i <= N + 1; i++) {
    orgdist += abs(A[i] - A[i-1]);
  }

  for (int i = 1; i <= N; i++) {
    if (A[i-1] <= A[i] && A[i] <= A[i+1] ||
        A[i+1] <= A[i] && A[i] <= A[i-1]) {
      cout << orgdist << endl;
    } else if (
      A[i-1] <= A[i] && A[i+1] <= A[i-1] ||
      A[i] <= A[i-1] && A[i-1] <= A[i+1]
      ) {
      cout << orgdist - 2*abs(A[i] - A[i-1]) << endl;
    } else {
      cout << orgdist - 2*abs(A[i+1] - A[i]) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int64 dist(int64 x1, int64 y1, int64 x2, int64 y2) {
    return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
    int64 n,m;
    cin >> n >> m;
    vector<int64> a(n);
    vector<int64> b(n);
    vector<int64> c(m);
    vector<int64> d(m);
    for (int64 i=0; i<n; i++) cin >> a[i] >> b[i];
    for (int64 i=0; i<m; i++) cin >> c[i] >> d[i];


    for (int64 i=0; i<n; i++) {
        int64 ans = 0;
        int64 dist_min = LONG_MAX;
        for (int64 j=0; j<m; j++) {
            int64 dist1 = dist(a[i], b[i], c[j], d[j]);
            if (dist_min > dist1) {
                dist_min = dist1;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

		int a=0,b=0,c=0;
		int m;
		for(int i=1;i<=10;i++)
		{
			cin>>m;
			if(m>=a)
			{
				int temp;
				temp=b;
				b=a;
				c=temp;
				a=m;
				
			}
			else if(m>=b)
			{
				int z;
				c=b;
				b=m;
			}
			else if(m>=c)
			{
				c=m;
			}
			
		}
		cout<<a<<endl;
		cout<<b<<endl;
		cout<<c<<endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int max3(int a, int b, int c){
  return max(a, max(b, c));
}

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int counter = 0; int maxi;
  if(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
    maxi = max3(A, B, C);
    cout << (3*maxi - (A+B+C))/2 << endl;
  }
  else if(A % 2 == 1 && B % 2 == 1 && C % 2 == 1){
    maxi = max3(A, B, C);
    cout << (3*maxi - (A+B+C))/2 << endl;
  }
  else if(B % 2 == C % 2){
    B++; C++;
    maxi = max3(A, B, C);
    cout << (3*maxi - (A+B+C))/2+1 << endl;
  }
  else if(C % 2 == A % 2){
    A++; C++;
    maxi = max3(A, B, C);
    cout << (3*maxi - (A+B+C))/2+1 << endl;
  }
  else{
    B++; A++;
    maxi = max3(A, B, C);
    cout << (3*maxi - (A+B+C))/2+1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
	
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
	
bool solve() {
	int big = 1000000000;
	int s; cin >> s;
	int x[3],y[3];
	x[0] = y[0] = 0;
	x[1] = 1e9; y[1] = 1;
	if (s % big == 0) {
		y[2] = s/big; x[2] = 0;
	} else {
		y[2] = s/big + 1; x[2] = big * y[2] - s;
	}
	REP (i,3) cout << x[i] << " " << y[i] << " "; cout << endl;
}
	
signed main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	solve();
}

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

using namespace std;

// #define mod 1000000007
// #define mod1 9982
#define int  long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define endl "\n"

const int maxn=2e5+5;

void solve()
{
    int n;
    cin>>n;
    int mod=0;
    for(int i=1;i<=n;i++)
    {
        mod=(mod*10+7)%n;
        if(mod==0)
        {
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int32_t main()
{
    fio;
    int t;
    // cin>>t;
    t=1;
    while(t--)
        solve(); 
}

/*
./a.out <input.txt > output.txt
*/


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string s[3];
    int n[3];
    n[0]=0;
    n[1]=0;
    n[2]=0;
    cin >> s[0]>>s[1]>>s[2];
    int t=0;
    while(true){
      if(n[t]>=s[t].size()){
        cout <<char(t+65);
        return 0;
      }
      n[t]+=1;
      t=s[t][n[t]-1]-97;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import time

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def find(node, key):
    if node is None:
        return False
    elif node.key == key:
        return True
    elif node.key > key:
        return find(node.left, key)
    else:
        return find(node.right, key)

def delete(node, key):
    if node is not None:
        if node.key == key:
            reconstTree(node)
        elif node.key > key:
            delete(node.left, key)
        else:
            delete(node.right, key)

def reconstTree(node):
    if node.left is None and node.right is None:
        #print "-----leaf-----"
        #print node.key
        if node.parent.left == node:
            node.parent.left = None
        else:
            node.parent.right = None
    elif node.left is not None and node.right is not None:
        #print "-----both-----"
        #print node.key
        sib = node.right
        while sib.left is not None:
            sib = sib.left
        node.key = sib.key
        reconstTree(sib)
    elif node.left is not None:
        #print "-----left-----"
        #print node.key
        if node.parent.left == node:
            node.parent.left = node.left
        else:
            node.parent.right = node.left
        node.left.parent = node.parent
    else:
        #print "-----right-----"
        #print node.key
        if node.parent.left == node:
            node.parent.left = node.right
        else:
            node.parent.right = node.right
        node.right.parent = node.parent

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "p":
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
        else:
            com = line.split()
            if com[0][0] == "i":
                insert(Node(int(com[1])))
            elif com[0][0] == "f":
                if find(root, int(com[1])):
                    print "yes"
                else:
                    print "no"
            else:
                delete(root, int(com[1]))

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

bitset<(size_t)1e9> b;
int main(void) {
    int64_t N;
    int64_t sum;
    cin >> N;
    
    vector<pair<int64_t,int64_t>> ab(N);
    for(int i=0;i<N;i++) {
        cin >> ab[i].second >> ab[i].first;
    }

    sort(ab.begin(), ab.end());
    
    sum = 0;
    for(int i=0;i<N;i++) {
        sum += ab[i].second;
        if(sum> ab[i].first) {
            cout << "No\n";
            return 0;
        }
    }    

    cout << "Yes\n";
    return 0;
}


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

using namespace std;

int main()
{
    long int N, A, B, C, D;
    string S;
    bool pass = false;
    bool enable = true;

    cin >> N >> A >> B >> C >> D;
    cin >> S;

    S.push_back('#');

    // スタートからゴールまで岩が2連続以上でないこと
    int count = 0;
    int space = 0;
    // Aの場合
    for(long int i=A-1; i<C; i++){
        if(S[i]=='#'){
            count++;
        }
        else{
            count = 0;
        }

        //2連続以上ある
        if(count>1){
            enable = false;
            break;
        }
    }

    // Bの場合
    for(long int i=B-1; i<D; i++){
        if(S[i]=='#'){
            count++;
        }
        else{
            count = 0;
        }

        //2連続以上ある
        if(count>1){
            enable = false;
            break;
        }
    }

    for(long int i=B-2; i<D+1; i++){
        if(S[i]=='.'){
            space++;
        }
        else{
            space = 0;
        }

        if(space>2){
            pass = true;
            break;
        }
    }

    // AがBを追い越す場合のスペース
    if(C>D && !pass){
        enable = false;
    }

    if(enable){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int x = sc.nextInt();

        for (int i = x; i <= 110000; i++) {
            if (isPrime(i)) {
                System.out.println(i);
                return;
            }
        }
    }

    public static boolean isPrime(int n) {
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<ll> as(n);
	rep(i, n)cin >> as[i];
	double sum = 0;
	rep(i, n)sum += as[i];
	ll ng = 0;
	rep(i, n) {
		if (as[i] < sum / (4 * m)) {
			ng++;
		}
	}
	ll ok = n - ng;
	if (ok >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
vector<ll>date;
void dfs(ll x,ll a,ll b,ll c){
if(x>N){
  return;
}
  if (a >= 1 && b >= 1 && c >= 1){
    date.push_back(x);
  }
  dfs(x*10+3,a+1,b,c);
  dfs(x*10+5,a,b+1,c);
  dfs(x*10+7,a,b,c+1);
  }
  
int main(){
  cin>>N;
  
  dfs(0,0,0,0);
  
  cout<<date.size()<<endl;
 
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,h,a[200000],b[200000];
int main(){
    cin >> n >> h;
    REP(i,n) {
        cin >> a[i] >> b[i];
    }

    ll maxa = 0;
    REP(i,n) {
        maxa = max(a[i],maxa);
    }

    sort(b,b + n);


    ll ans = 0;
    RREP(i,n) {
        if(maxa > b[i]) {
            break;
        }

        h -= b[i];
        ans++;
        if(h < 1) {
            cout << ans << endl;
            return 0;
        }
    }

    ans += ((h + maxa - 1) / maxa);
    cout << ans << endl;
    return 0;
}



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

int main(void) {
  char s[100];
  char t[100];
  int leng1;
  int leng2;
  int judge = 1;
  scanf("%s", s);
  scanf("%s", t);
  leng1 = strlen(s);
  leng2 = strlen(t);
  for(int i = 0; i < leng1; i++) {
    if(s[i] != t[i]) {
      judge = 0;
    }
  }
  if(judge == 1 && leng2 - leng1 == 1) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int n, a;
  cin >> n;
  vector<int> p(n);

  for (int i = 0; i < n; i++){
    cin >> a;
    p.at(i) = a;
  }
  int ans = 0;
  int curMin = 1e9;
  for (int i = 0; i < n; i++) {
    curMin = min(curMin, p[i]);
    if(curMin == p[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1152
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<usize>();
    let M = read::<usize>();

    let mut As: Vec<Vec<char>> = Vec::new();
    for i in 0..N {
        let S = read_String_Vec();
        As.push(S);
    }

    let mut Bs: Vec<Vec<char>> = Vec::new();
    for i in 0..M {
        let S = read_String_Vec();
        Bs.push(S);
    }

    for h in 0..(N-M+1) {
        'label: for w in 0..(N-M+1) {
            let mut matching = true;
            for hh in 0..M {
                for ww in 0..M {
                    if As[h+hh][w+ww] != Bs[hh][ww] {
                        matching = false;
                        continue 'label;
                    }
                }
            }
            if matching {
                println!("Yes");
                return;
            }
        }

    }

    println!("No");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> LL;
#define EPS (1e-10)
LL A;
int N;

void viewLine(LL a){
  cout <<"view LINE"<<endl;
  for(int i=0;i<(int)a.size();i++){
    printf("%.8lf %.8lf\n",a[i].real(),a[i].imag());
  }
}
void inputLine(LL &l){
  int m;
  cin >> m;
  int px,py;
  cin >> px >> py;
  for(int i=1;i<m;i++){
    int x,y;
    cin >> x >> y;
    l.push_back(P(x,y)-P(px,py));
    px = x; py = y;
  }
}


P rotate(P p,double theta){
  theta = theta * M_PI / 180.0;
  double x = real(p) * cos( theta ) - imag(p) * sin( theta );
  double y = real(p) * sin( theta ) + imag(p) * cos( theta );
  return P(x,y);
}

LL rotate(LL l,double theta){
  for(int j=0;j<(int)l.size();j++){    
    l[j] = rotate(l[j], 90.0);
  }
  return l;
}

bool eqv(P a,P b){
  return fabs(a.real()-b.real())<EPS && fabs(a.imag()-b.imag())<EPS;
}

LL reverse(LL b){
  LL r;
  for(int i=(int)b.size()-1;i>-1;i--){
    r.push_back(-b[i]);
  }
  return r;
}

bool check(LL a,LL b){
  if( a.size() != b.size() ) return false;
  for(int i=0;i<4;i++){
    bool f=true;
    for(int j=0;j<(int)a.size();j++){
      if( !eqv(a[j],b[j]) ) f=false;
    }
    if(f) return true;
    a = rotate(a,90.0);
  }
  return false;
}

bool isCheck(LL a,LL b){
  return check(a,b) || check(a,reverse(b));
}


int main(){
  while( cin >> N && N ) {
    A.clear();

    inputLine(A); 
    /*  
   viewLine(A);
   viewLine(A=rotate(A,90.0));
   viewLine(A=rotate(A,90.0));
   viewLine(A=rotate(A,90.0));
    */
    for(int i=0;i<N;i++){
      LL B;
      inputLine(B);
      // view(B);
      if( isCheck(A,B) ) cout << i+1 << endl;
    }
    cout << "+++++"<<endl;

  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <cassert>
#define maxW 200005
 
using namespace std;
typedef long long ll;
int H,W,n;
vector <int> blocks[maxW];
int main(){
  scanf("%d%d%d",&H,&W,&n);
  for(int i = 1;i <= n;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    blocks[y].push_back(x);
  }
  for(int i = 1;i <= W;i++){
    blocks[i].push_back(H + 1);
    sort(blocks[i].begin(),blocks[i].end());
  }
  int cx = 1;
  int ans = blocks[1][0] - 1;
  for(int i = 2;i <= W;i++){
    cx++;
    while(cx <= H && binary_search(blocks[i].begin(),blocks[i].end(),cx)) cx++;
    if(cx <= H){
      ans = min(ans,*lower_bound(blocks[i].begin(),blocks[i].end(),cx) - 1);
    }else break;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 11392
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

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

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	char A, B;
	cin >> A >> B;

	char ans;
	if (A == 'H') ans = B;
	else ans = (B == 'H') ? 'D' : 'H';

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


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
dp = [True for _ in range(a[-1] + 1)]
pre = -1
for i in a:
    if i == pre:
        dp[i] = False
        continue
    for j in range(i * 2, a[-1] + 1, i):
        dp[j] = False
    pre = i
ans = 0
for i in a:
    if dp[i] == True:
        ans += 1
print(ans)

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

using namespace std;

int main(void) {
	int k, n;
	cin >> k >> n;
	int ans = 0;
	vector<int> a(n);
	int max_d=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i != 0) {
			max_d = max(a[i] - a[i - 1], max_d);
		}
	}

	max_d = max(max_d, k + a[0] - a[n - 1]);
	ans = k - max_d;

	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
inline int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
typedef long long ll;

int n,K;
int a[200010];
int p[200010];
bool cmp(int x,int y){
	if (a[x]^a[y]) return a[x]<a[y];
	return x<y;
}
struct Rec{
	int l,r,L,R;
}A[200010],B[200010]; int Atot,Btot;
ll ans;
int main()
{
	//freopen("data.in","r",stdin);
	//freopen("A.out","w",stdout);

	n=read(),K=read(); ans=n;
	for (int i=1;i<=n;i++) a[i]=read(),p[i]=i;
	sort(p+1,p+n+1,cmp);
	int pos=1,T;  //next considered; cur val
	while (1){
		if (!Atot){
			if (pos>n) break;
			T=a[p[pos]];
		}
		Btot=0;
		for (int i=1;i<=Atot;i++){
			while (pos<=n&&a[p[pos]]==T&&p[pos]<A[i].l)
				B[++Btot]=(Rec){p[pos],p[pos],1,1},pos++;
			B[++Btot]=A[i];
		}
		while (pos<=n&&a[p[pos]]==T)
			B[++Btot]=(Rec){p[pos],p[pos],1,1},pos++;
		Atot=Btot; for (int i=1;i<=Atot;i++) A[i]=B[i];
		for (int i=1,lst=-1,Ltot=0;i<=Atot;i++){
			if (i==1||A[i].l-1!=A[i-1].r) lst=i,Ltot=0;
			if (i-lst+1>=K) Ltot+=A[i-K+1].L;
			ans+=1LL*Ltot*A[i].R;
		}
		Btot=0;
		for (int i=1,j;i<=Atot;i=j+1){
			for (j=i;j+1<=Atot&&A[j].r+1==A[j+1].l;j++);
			if (j-i+1<K) continue;
			int t=(j-i+1)/K;
			for (int s=1,cur=K;s<=t;s++){
				B[++Btot]=(Rec){A[i].l+s-1,A[i].l+s-1,0,0};
				while (cur<=j-i+1&&cur/K==s){
					B[Btot].R+=A[i+cur-1].R;
					B[Btot].L+=A[j-cur+1].L;
					cur++;
				}
			}
			for (int a=Btot-t+1,b=Btot;a<b;swap(B[a++].L,B[b--].L));
			B[Btot].r=A[j].r;
		}
		Atot=Btot; for (int i=1;i<=Atot;i++) A[i]=B[i];
		for (int i=1,lst=-1,Ltot=0;i<=Atot;i++){
			if (i==1||A[i].l-1!=A[i-1].r) lst=i,Ltot=0;
			if (i-lst+1>=K) Ltot+=A[i-K+1].L;
			ans-=1LL*Ltot*A[i].R;
		}
		T++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7360
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int q;
    while (cin >> q, q != -1) {
        double x = q / 2.0;
        double eps = 0.00001 * q;
        while (eps <= abs(x*x*x - q)) {
            x = x - (x*x*x - q) / (3*x*x);
        }
        cout.precision(6);
        cout << fixed << x << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

struct segtree {
	int size;
	vector<int> maxs;

	void init(int n) {
		size = 1;
		while (size < n) size *= 2;
		maxs.assign(2*size, 0);
		return;
	}

	void set(int pos, int val, int x, int lx, int rx) {
		if (rx - lx == 1) {
			maxs[x] = val;
			return;
		}
		int mid = (lx + rx) / 2;
		if (pos < mid) set(pos, val, 2*x + 1, lx, mid);
		else set(pos, val, 2*x + 2, mid, rx);
		maxs[x] = max(maxs[2*x + 1], maxs[2*x + 2]);
		return;
	}

	void set(int pos, int val) {
		return set(pos, val, 0, 0, size);
	}

	int calc_max(int l, int r, int x, int lx, int rx) {
		if (l <= lx && rx <= r) {
			return maxs[x];
		}
		if (rx <= l || r <= lx) return 0;
		int mid = (lx + rx) / 2;
		int left_max = calc_max(l, r, 2*x + 1, lx, mid);
		int right_max = calc_max(l, r, 2*x + 2, mid, rx);
		return max(left_max, right_max);
	}

	int calc_max(int l, int r) {
		return calc_max(l, r, 0, 0, size);
	}
};

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {
		
	// }
	int n;
	cin >> n;
	segtree st;
	vector<int> height(n), beauty(n); int max_height = 0;
	for (int i = 0; i < n; i++) {
		cin >> height[i];
		if (height[i] > max_height) max_height = height[i];
	} 
	for (int i = 0; i < n; i++) {
		cin >> beauty[i];
	}
	vector<int> dp(max_height + 1);
	st.init(max_height + 1);
	// dp[i] = max_beauty of flowers where max height is i
	for (int flower = 0; flower < n; flower++) {
		int best_val = st.calc_max(0, height[flower]);
		dp[height[flower]] = beauty[flower] + best_val;
		st.set(height[flower], dp[height[flower]]);
	}
	cout << st.calc_max(0, max_height + 1) << endl;

	return 0;
}

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

#define lol long long

int cost(int *,int, int, int);

int main() {

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	
	int ans=cost(a,1,2,3);
	if (ans > cost(a, 1, 3, 2)) ans = cost(a, 1, 3, 2);
	if (ans > cost(a, 2, 1, 3)) ans = cost(a, 2, 1, 3);
	if (ans > cost(a, 2, 3, 1)) ans = cost(a, 2, 3, 1);
	if (ans > cost(a, 3, 1, 2)) ans = cost(a, 3, 1, 2);
	if (ans > cost(a, 3, 2, 1)) ans = cost(a, 3, 2, 1);


	cout << ans;
	return 0;
}

int cost(int *arr,int a, int b, int c) {

	return abs(arr[b-1] - arr[a-1]) + abs(arr[c-1] - arr[b-1]);
};

Measured memory_bytes: 256
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        x: usize, y: usize, a: usize, b: usize, c: usize,
        p: [usize; a],
        q: [usize; b],
        r: [usize; c],
    }

    let mut vs = vec![];
    for i in 0..a {
        vs.push((p[i], 0));
    }
    for i in 0..b {
        vs.push((q[i], 1));
    }
    for i in 0..c {
        vs.push((r[i], 2));
    }
    vs.sort();
    vs.reverse();
    let mut cnt = vec![0; 3];

    let mut ans = 0;
    for i in 0..vs.len() {
        let &(v, c) = &vs[i];
        if c == 0 && cnt[0] < x {
            cnt[0] += 1;
            ans += v;
        }
        if c == 1 && cnt[1] < y {
            cnt[1] += 1;
            ans += v;
        }
        if c == 2 {
            cnt[2] += 1;
            ans += v;
        }
        if cnt.iter().sum::<usize>() == x + y {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 17004
import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort()


c = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1, n-1):
        m = l[i_1] + l[i_2]
        i_3max = bisect.bisect_left(l, m) - 1
        c += i_3max - i_2

print(c)



Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int n;
int ans = 0;

void check(int x){
    bool f3=false, f5=false, f7=false;
    while(x!=0){
        if(x > n)break;

        int a = x % 10;
        if(a == 3)f3 = true;
        else if(a == 5)f5 = true;
        else if(a == 7)f7 = true;
        x /= 10;
    }
    if(f3 && f5 && f7)ans++;
}


void dfs(int x){
    check(x);
    if(x <= 100000000){
        dfs((10 * x) + 3);
        dfs((10 * x) + 5);
        dfs((10 * x) + 7);
    }
}

int main() {
    cin >> n;
    dfs(0);
    cout << ans << endl;
    return 0;



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
#define pb push_back
#define INF 1e5
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    
    int n;
    cin>>n;
    int A[n];
    REP(i,0,n) cin>>A[i];
    sort(A,A+n);
    bool flag=false;
    REP(i,0,n-1)
    {
    	if(A[i]==A[i+1])
    	{
    		flag=true;
    		break;
		}
	}
    if(flag) cout<<"NO\n";
    else cout<<"YES\n";
	return 0;
    
}

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

int main(){
	using namespace std;

	string A,B,C;
	string message = "NO";
	cin >> A >> B >> C;
	if(*(A.end()-1) == *B.begin() && *(B.end()-1) == *C.begin()){
		message = "YES";
	}

	cout << message << endl;

	return 0;
}


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

using namespace std;

int n, a[16], tes[16][16], x, y, rreal[16], cnt, ans;
bool ok;

// tes[a][b] is testimonial by a commenting b.

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		for (int j=0; j<a[i]; j++) {
			cin >> x >> y;
			if (y) tes[i + 1][x] = 1;
			else tes[i + 1][x] = -1;
		}
	}
	for (int i=1; i<(1 << n); i++) {
		cnt = 0; ok = 1;
		for (int j=0; j<16; j++) rreal[j] = 0;
		for (int j=0; j<n; j++) {
			if (i & (1 << j)) {
				cnt++;
				if (rreal[j + 1] == -1) ok = 0;
				rreal[j + 1] = 1;
				for (int k = 1; k <= n; k++) {
					if (tes[j + 1][k] == 1) {
						if (rreal[k] == -1) ok = 0;
						else rreal[k] = 1;
					}
					if (tes[j + 1][k] == -1) {
						if (rreal[k] == 1) ok = 0;
						else rreal[k] = -1;
					}
				}
			}
			else {
				if (rreal[j + 1] == 1) ok = 0;
				rreal[j + 1] = -1;
			}
		}
		if (ok) ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n = II()
    a = n // 2
    b = n - a
    print(a*b)
    return

#B
def B():
    x1, y1, x2, y2 = LI()
    a = x2 - x1
    b = y2 - y1
    print(x2 - b, y2 + a, x1 - b, y1 + a)
    return

#C
def C():
    n, k = LI()
    if k % 2:
        print((n // k)** 3)
    else:
        print(int((n//k)**3 + ((n-k/2)//k+1)**3))
        
    return

# D
# 解説AC
# a→bの辺に関していえばこの辺を2辺張ってしまえば2*n本で
# 2^n個のパスの組み合わせができることに気づけなかった
# i→i+1へ辺を出して長さは0 or 1<<i-1の辺を張ることで
# 和のi番目のbitを立たせるかを選ばせることができる
# さらに、Lのi番目のbitが立っているときにi番目のbitを立たせる
# もしくは最上位のbitを立たせてかつ、そのbitを除くi番目より上位の
# 立っているbitすべてを立たせたものの和を辺の長さとして辺を張ることで
# 解が得られる（はず）
def D():
    l = II()
    lBit = bin(l)[:1:-1]
    #print(lBit)
    n = len(lBit)
    ans = []
    for i in range(1, n):
        ans += [(i, i + 1, 0)] + [(i, i + 1, 1 << i - 1)]
    b = 1 << n - 1
    for i in range(n - 1):
        if lBit[-2 - i] == "1":
            ans += [(n - i - 1, n, b)]
            b += 1 << (n - i - 2)
    print(n,len(ans))
    for a in ans:
        print(*a)
    return


#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,koin=0;
	cin >> a >> b;
	for(int i=1;i<=2;i++){
			if(a>=b){
		koin+=a;
		a--;
	}else if (a<=b){
		koin+=b;
		b--;
	}
	}
	cout << koin << endl;
}

Measured memory_bytes: 256