akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll N;
    cin >> N;
    map<char, ll> X={{'M',0LL}, {'A',0LL}, {'R',0LL}, {'C',0LL}, {'H',0LL}};
    rep(i, N) {
        string S;
        cin >>  S;
        char C=S[0];
        if(X.find(C)!=X.end()) X[C]++;
    }

    ll ans=0;
    rep(m,2) {
        rep(a,2) {
            rep(r,2) {
                rep(c,2) {
                    rep(h,2) {
                        if(m+a+r+c+h==3){
                            ll cnt=1;
                            if(m) cnt *= X['M'];
                            if(a) cnt *= X['A'];
                            if(r) cnt *= X['R'];
                            if(c) cnt *= X['C'];
                            if(h) cnt *= X['H'];

                            ans += cnt;
                        }
                    }
                }
            }
        }
    }

    cout << ans << nl;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

int main() {
    string s;
    cin>>s;
    int leng=s.length();
    for(int bit=0;bit<(1<<leng);bit++){
        //1<<leng-1ではダメ？
        int sum=s.at(0)-'0';
        vector<char> vec;
        for(int i=1;i<leng;i++){
            if(bit&(1<<i)){
                sum+=s.at(i)-'0';
                vec.push_back('+');
            }
            else{
                sum-=s.at(i)-'0';
                vec.push_back('-');               
            }   
        }
        //cout<<sum<<endl;
        if(sum==7){
            cout<<s.at(0);
            cout<<vec.at(0);
            cout<<s.at(1);
            cout<<vec.at(1);
            cout<<s.at(2);
            cout<<vec.at(2);
            cout<<s.at(3)<<'='<<7<<endl;
            break;
        }
    }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll h,n,a,b;
	cin >> h >> n;
	vll v(h+1,INF);
	vpll vp(n);
	rep(i,n){
		cin >> a >> b;
		vp[i]=m_p(a,b);
	}
	v[0]=0;
	for(ll i=1;i<=h;i++){
		for(ll j=0;j<n;j++){
			if(i-vp[j].first<0){
				v[i]=min(v[i],vp[j].second);
			}
			else{
				v[i]=min(v[i],v[i-vp[j].first]+vp[j].second);
			}
		}
	}
	cout << v[h] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

int A[N];
vector <int> B;

int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int n;scanf("%d",&n);
	int ans = 0;
	REP(i,n){
		int x;scanf("%d",&x);
		x--;
		A[i]=x;B.pb(x);
	}
	sort(all(B));
	REP(i,n)	A[i]=lower_bound(all(B),A[i])-B.begin();
	
	REP(i,n){
		if(abs(A[i]-i)%2)	ans++;
	}
	printf("%d\n",ans/2);
	return 0;
}



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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
vector<string>A;

vector<string>BubbleSort(vector<string>&A){
    vector<string>B=A;
    rep(i,N){
        for(int j=N-1;j>0;j--){
            if(B[j][1]<B[j-1][1])swap(B[j],B[j-1]);
        }
    }
    return B;
}

vector<string>SelectionSort(vector<string>&A){
    vector<string>B=A;
    rep(i,N){
        int mi=i;
        for(int j=i+1;j<N;j++)if(B[mi][1]>B[j][1])mi=j;
        swap(B[i],B[mi]);
    }
    return B;
}

bool isStable(vector<string>&A,vector<string>&B){
    rep(i,B.size()){
        for(int j=i+1;j<N;j++){
            if(B[i][1]!=B[j][1])continue;
            int x,y;
            rep(k,A.size()){
                if(A[k]==B[i])x=k;
                else if(A[k]==B[j])y=k;
            }
            if(x>y)return false;
        }
    }
    return true;
}

signed main(){
    cin>>N;
    rep(i,N){
        string s;cin>>s;A.pb(s);
    }

    vector<string>B=BubbleSort(A),S=SelectionSort(A);

    rep(i,B.size()){
        if(i)cout<<" ";
        cout<<B[i];
    }cout<<endl;
    if(isStable(A,B))cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    rep(i,S.size()){
        if(i)cout<<" ";
        cout<<S[i];
    }cout<<endl;
    if(isStable(A,S))cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    return 0;
}

Measured memory_bytes: 1216
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * (10 ** 6 + 1)

for i in range(n):
    cnt[a[i]] += 1

a_uniq = []

for i in range(10 ** 6 + 1):
    if cnt[i] == 1:
        a_uniq.append(i)

cnt = [0] * (10 ** 6 + 1)

for i in list(set(a)):
    for j in range(2 * i, 10 ** 6 + 1, i):
        cnt[j] = 1

ans = 0

for i in a_uniq:
    if cnt[i] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 150684
import java.util.*;
import java.util.stream.*;

public class Main{
	public static void main(String... args){ new Main().solve(); }

	public void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int pt = 0;
		int px = 0;
		int py = 0;
		int ct = 0;
		int cx = 0;
		int cy = 0;
		int condition[][] = new int[n][2];
		for(int i=0; i<n; i++){
			ct = sc.nextInt();
			cx = sc.nextInt();
			cy = sc.nextInt();
			condition[i][0] = ct - pt;
			condition[i][1] = Math.abs(cx - px) + Math.abs(cy - py);
			pt = ct;
			px = cx;
			py = cy;
		}
		long cnt = Arrays.asList(condition).stream()
			.filter(a -> {
				if((a[0] % 2) == (a[1] % 2) && a[0] >= a[1]) return true;
				return false;
			})
			.count();
		if(cnt == n) System.out.println("Yes");
		else System.out.println("No");
	}
}



Measured memory_bytes: 93752
n, m = map(int, input().split())
x = [list(map(int, input().split())) for x in range(n)]

# print(x)
x.sort()
sum = 0
yen = 0
for i in range(n):
    sum += x[i][1]
    yen += x[i][0] * x[i][1]
    if sum >= m:
        yen -= (sum-m)*x[i][0]
        break

print(yen)


Measured memory_bytes: 27464
import numba
from numba import jit
import numpy as np

#(i,j)→(i+1,j)のように動くときはアイテムを入手できる回数がリセットされる
#dp[列][今、何個アイテムを取ったか]でdpテーブルを作る
@jit
def main(r, c):
  dp = np.zeros((c+1, 4), np.int64)
  for i in range(r):
    new_dp = np.zeros((c+1, 4), np.int64)
    for j in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,j])
    dp = new_dp
    for k in range(c):
      for l in range(2, -1, -1):
        dp[k,l+1] = max(dp[k,l+1], dp[k,l]+item_map[i,k])
      for m in range(1,4):
        dp[k+1,m] = max(dp[k+1,m], dp[k,m])
  return max(dp[c-1,:])

R, C, K = map(int, input().split())
item_lis = list(list(map(int, input().split())) for i in range(K))
item_map = np.zeros((R, C), np.int64)
for i,j,k in item_lis:
  item_map[i-1,j-1] = k

print(main(R, C))


Measured memory_bytes: 228716
N,M = [int(x) for x in input().split()]
mod = 10**9 + 7
DP = [0]*(N+1)
for i in range(M):
    aa = int(input())
    DP[aa] = -1
DP[0] = 1
if DP[1] != -1:
    DP[1] = 1
for i in range(2,N+1):
    if DP[i] != -1:
        DP[i] = max(0,DP[i-1]) + max(0,DP[i-2])
ans = DP[N] % mod
print(ans)

Measured memory_bytes: 470264
s = input()
if int(s) > int(s[0] + s[0] + s[0]):
    if s[0] == '9':
        print(1111)
    else:
        print(str(int(s[0])+1) + str(int(s[0])+1) + str(int(s[0])+1))
else:
    print(s[0] + s[0] + s[0])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,N) for (int i = 0; i < N; i++) ;                                
int main() {
 int N;
 cin>>N;
 vector<int>P(N);
 for(int i=0; i<N; i++){
     cin>>P.at(i);
 }
 vector<int>A(N);
 A=P;
 sort(P.begin(),P.end());
 int count=0;
for(int i=0; i<N; i++){
    if(P.at(i)==A.at(i)){
    }
    else{
    count++;
    }
}
if(count<3){
    cout<<"YES"<<endl;
}
else
{
    cout<<"NO"<<endl;
}
}


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n,k;
std::string s;

int main(){
    INIT;
    cin >> n;
    cin >> s;
    cin >> k;

    char c = s[k-1];
    REP(i,n) {
        if(c != (char)s[i]) s[i] = '*';
    }
    OUT(s) NL;
}

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

int n,m,a[2][100000],p=0;
vector<int> e[2][100000];
bool b[100000];

int f(int v, int c){
    if(!b[v]){
        a[c][v]=0;
        for(int i=0;i<e[c][v].size();i++){
            a[c][v]=max(a[c][v], f(e[c][v][i], c)+1);
        }
        b[v]=true;
    }
    return a[c][v];
}

int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        e[0][x].push_back(y);
        e[1][y].push_back(x);
    }
    fill(b, b+n, false);
    for(int i=0;i<n;i++){
        p=f(i, 0);
    }
    fill(b, b+n, false);
    for(int i=0;i<n;i++){
        p=f(i, 1);
    }
    for(int i=0;i<n;i++){
        p=max(p, f(i, 0)+f(i, 1));
    }
    cout<<p<<endl;
}


Measured memory_bytes: 18048
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int [] x=new int [n];
		int [] y=new int [n];
		for(int i=0;i<n;i++) {
			x[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			y[i]=sc.nextInt();
		}
		int sam1=0;
		double sam2=0;
		double sam3=0;
		int sam8=0;
		for(int i=0;i<n;i++) {
			if(x[i]>=y[i]) {
				sam1+=x[i]-y[i];
				sam3+=(x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]);
			}
			else {
				sam1+=(y[i]-x[i]);
				sam3+=(y[i]-x[i])*(y[i]-x[i])*(y[i]-x[i]);
			}
			sam2+=(x[i]-y[i])*(x[i]-y[i]);
			if(i==0) {
				if(x[i]>=y[i]) {
					sam8=x[i]-y[i];
				}
				else {
					sam8=y[i]-x[i];
				}
			}
			else {
				if(x[i]>=y[i]) {
					if(sam8<x[i]-y[i]) {
						sam8=x[i]-y[i];
					}
				}
				else {
					if(sam8<y[i]-x[i]) {
						sam8=y[i]-x[i];
					}
				}
			}
		}
		sam3=Math.cbrt(sam3);
		sam2=Math.sqrt(sam2);
		System.out.println(sam1+"\n"+sam2+"\n"+sam3+"\n"+sam8);
		sc.close();
		}
	}


Measured memory_bytes: 26560
#include<stdio.h>

int main(void){
	
	int n,m,k;
	int j=100000;

	scanf("%d", &n);

	m=0 ;
	while(m++ < n){
		j*=1.05 , k=j/1000;
		if(j%1000 != 0)
			j=(k+1)*1000; 
	};

	printf("%d\n", j);

	return (0);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[10000][10000];
long long u[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=1,f=0;
  string s;
  cin >>s;
  if(s[0]==s[2]) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int k = sc.nextInt();
		int a = sc.nextInt(), b = sc.nextInt();
		boolean flag = false;
		for(int i = a; i <= b; i++)
			if(i % k == 0)
				flag = true;
		
		pw.println(flag ? "OK" : "NG");
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 32724
#include <iostream>

int solve(int a, int b)
{
  int result = 0;
  for (int i = 0; i < 2; ++i) {
    int* p = a >= b ? &a : &b;
    result += *p;
    *p -= 1;
  }
  return result;
}

int main()
{
  int a, b;
  std::cin >> a >> b;

  std::cout << solve(a, b) << std::endl;
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

ll calc(ll n, ll div, ll cdec, ll cdiv) {
    ll ans = 0;
    while(true) {
        if (n < div) {
            ans += n * cdec;
            break;
        }
        ans += (n % div) * cdec;
        ans += cdiv;
        n /= div;
    }
    return ans;
}

ll a, b, c, d, n;

ll best = 0;
map<ll, ll> mp;
ll solve(ll n) {
    if (n == 0) {
        return 0;
    }
    if (n == 1) {
        return d;
    }
    if (n == 2) {
        return min(a + d, d + d);
    }
    if (mp.find(n) != mp.end()) {
        return mp[n];
    }
    ll ans = 1e18;
    if (ld(n) * d < 1e18) {
        ans = n * d;
    }
    ans = min(ans, solve(n / 2) + (n % 2) * d + a);
    ans = min(ans, solve(n / 3) + (n % 3) * d + b);
    ans = min(ans, solve(n / 5) + (n % 5) * d + c);

    ans = min(ans, solve(n / 2 + 1) + (2 - (n % 2)) * d + a);
    ans = min(ans, solve(n / 3 + 1) + (3 - (n % 3)) * d + b);
    ans = min(ans, solve(n / 5 + 1) + (5 - (n % 5)) * d + c);
    mp[n] = ans;
    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int T;
    cin >> T;
    while(T--) {
        cin >> n >> a >> b >> c >> d;
        mp.clear();
        ll ans2 = calc(n, 2, d, a);
        ll ans3 = calc(n, 3, d, b);
        ll ans5 = calc(n, 5, d, c);
        best = min(min(ans2, ans3), ans5);
        cout << solve(n) << endl;
    }

    return 0;
}




Measured memory_bytes: 4868
#include<stdio.h>

long long int gcd(long long int n1,long long int n2);

int main(void)
{
    int n,i;

    scanf("%d",&n);

    long long t[n],gcm,maxgcm;

    scanf("%lld",&t[0]);
    maxgcm=t[0];
    for(i=1;i<n;i++){
        scanf("%lld",&t[i]);
        gcm=t[i]*(t[i-1]/gcd(t[i],t[i-1]));
        maxgcm=gcm*(maxgcm/gcd(gcm,maxgcm));
    }

    printf("%lld",maxgcm);

    return 0;
}

long long int gcd(long long int n1,long long int n2)
{
    long long int x;

    while(n2!=0){
        x=n1%n2;
        n1=n2;
        n2=x;
    }

    return n1;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

const int NMAX = int(1e6);
ll fact[NMAX+1], finv[NMAX+1], inv[NMAX+1];

void comb_init(int N) {
    // init
    REP(i, 2) {
        fact[i] = 1;
        finv[i] = 1;
        inv[i] = 1;
    }

    FOR(i, 2, N+1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

mint comb(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return mint(fact[n]) * finv[k] * finv[n-k];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, M, K;
    cin >> N >> M >> K;

    comb_init(N);

    mint ans = 0, p = 1;
    REP(k, N) {
        if (N - K - 1 <= k) ans += comb(N-1, N - k - 1) * M * p;
        p *= (M - 1);
    }

    print(ans);
    
}


Measured memory_bytes: 8316
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll near(vector<ll> &v,ll ans) {
	ll mi = INF;
	ll md;
	for(auto a :v){
		ll d = abs(2 * a - ans);
		if(d<mi){
			mi = d;
			md = a;
		}
	}
	return md;
}


int main() {
	cin >> n;
	vi v(n);
	REP(i,n) {
		cin >> v[i];
		chmax(ans, v[i]);
	}
	sort(ALL(v));
	cout << ans << " " << near(v, ans) << endl;
}

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

int main() {

  int N,sum=0; cin>>N;
 // pair<int,int> p;
  vector<pair<int,int>> P(N);
  for(int i=0; i<N; i++){
    cin>>P.at(i).first>>P.at(i).second;}
  for(int i=0; i<N; i++){
    sum+=(P.at(i).second-P.at(i).first+1);}
  
  cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long 
using namespace std; 
inline char get(){
	const int TOP=1000000;
	static char T[TOP],*x=T,*y=T;
	return x==y&&(y=(x=T)+fread(T,1,TOP,stdin),x==y)?EOF:*x++;
}
inline ll read (){
	register ll num;int sign=1;register char c;
	while (((c=get())<'0'||c>'9')&&c!='-');c=='-'?num=sign=0:num=c-48;
	while ((c=get())>='0'&&c<='9')num=(num<<3)+(num<<1)+(c-48);
	return sign?num:-num;
}
int n,ans;
int main(){
	n=read();
	for(int i=1;i<=n;++i)
		ans|=(read()%2)==1;
	if(ans)printf("first");else printf("second");
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int N=105;

int n,m;
string s[N];
int dp[N][N];
bool way[N][N][N][N];

int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	for(int k=i;k<n;k++)
	for(int l=j;l<m;l++)
		if(i==k && j==l) way[i][j][k][l]=(s[k][l]=='#');
		else if(i==k) way[i][j][k][l]=way[i][j][k][l-1]&&(s[k][l]=='#');
		else if(j==l) way[i][j][k][l]=way[i][j][k-1][l]&&(s[k][l]=='#');
		else way[i][j][k][l]=(way[i][j][k][l-1]||way[i][j][k-1][l])&&(s[k][l]=='#');
	
	memset(dp,60,sizeof(dp));
	dp[0][0]=(s[0][0]=='#');
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		if(way[0][0][i][j]) dp[i][j]=1;
	for(int i=1;i<n;i++)
		if(s[i][0]=='.')
			dp[i][0]=dp[i-1][0];
		else
		for(int j=0;j<i;j++)
			if(way[j+1][0][i][0]) dp[i][0]=dp[j][0]+1;
	for(int i=1;i<m;i++)
		if(s[0][i]=='.')
			dp[0][i]=dp[0][i-1];
		else
		for(int j=0;j<i;j++)
			if(way[0][j+1][0][i]) dp[0][i]=dp[0][j]+1;
	
	for(int i=1;i<n;i++)
	for(int j=1;j<m;j++)
		if(s[i][j]=='.')
			dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
		else
		for(int k=0;k<=i;k++)
		for(int l=0;l<=j;l++)
			if(k+l!=i+j && (way[k][l+1][i][j] || way[k+1][l][i][j])) dp[i][j]=min(dp[i][j],dp[k][l]+1);
	cout<<dp[n-1][m-1]<<'\n';
	
	return 0;
}

Measured memory_bytes: 114944
H, W = map(int, input().split())
s = [input() for i in range(H)]

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        flag = False
        for k in range(4):
            if s[i][j] == '#':
                nx = j + dx[k]
                ny = i + dy[k]
                if nx < 0 or nx >= W or ny < 0 or ny >= H:
                    continue
                if s[ny][nx] == '#':
                    flag = True
            else:
                flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')

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

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

  int cnt = 0;
  if(a%10 == 1){
    cnt++;
  }
  if(a/10%10 == 1) {
    cnt++;
  }
  if(a/100 == 1) {
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < pow(2.0, n); ++i) {
		bitset<18> a = i;
		cout << i << ':';
		for (int j = 0; j < 18; ++j) {
			if (a[j]) cout << ' ' << j;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int a[n], b[m];
    rep(i, n) scanf("%d", &a[i]);
    rep(i, m) scanf("%d", &b[i]);
    sort(a, a+n, greater<int>());
    sort(b, b+m, greater<int>());
    lint ans = 1;
    lint mod = 1e9 + 7;
    lint cnt = 0;
    int l = 0;
    int pl = 0;
    int r = 0;
    int pr = 0;
    rFor(i, n*m+1, 1){
        while(l < n && a[l] >= i) ++l;
        while(r < m && b[r] >= i) ++r;
        if(l-pl > 1 || r-pr > 1){
            printf("0\n");
            return 0;
        }
        cnt = (cnt + (l-pl) * pr + (r-pr) * pl + (l-pl)*(r-pr));
        if(a[l-1] == b[r-1] && a[l-1] == i) ans *= 1;
        else if(a[l-1] == i) ans = ans * ((l-pl) * pr % mod) % mod;
        else if(b[r-1] == i) ans = ans * ((r-pr) * pl % mod) % mod;
        else ans = (ans * cnt) % mod;
        cnt = (cnt - 1 + mod) % mod;
        pl = l;
        pr = r;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b[10],c=0,d=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b[i];
    d+=b[i];
    if(c<b[i]){
      c=b[i];
    }
  }
    if(c<d-c){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}

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

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

  const int h = S / 3600;
  const int m = (S % 3600) / 60;
  const int s = (S % 3600) % 60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    
    auto isp = [](string T){
//        cerr << T << "\n";
        int n = T.size();
        bool ok = true;
        if(n%2){
            int l = n/2-1,r = l+2;
            while(l>=0){
                ok &= T[l]==T[r];
                l--;
                r++;
            }
        }else{
            int l = n/2-1,r = l+1;
            while(l>=0){
                ok &= T[l]==T[r];
                l--;
                r++;
            }
        }
        return ok;
    };
    
    bool yes = isp(S) && isp(S.substr(0,(N-1)/2)) && isp(S.substr((N+3)/2-1,N-(N+3)/2+1));
    cout << (yes? "Yes\n":"No\n");

}

Measured memory_bytes: 256
import numpy as np
h, w = map(int, input().split())
num_array = np.zeros((h, w))
space_array = np.ones((h, w))

mine_map = np.array(
    [np.array([0 if i == "." else 1 for i in input()]) for j in range(h)])
space_array = mine_map.copy()

for i, s in enumerate(mine_map):
    for j, m in enumerate(s):
        if m == 1: # m=mass
            il, iu = i-1, i+2
            jl, ju = j-1, j+2
            il, jl = max(il, 0), max(jl, 0)
            iu, ju = min(iu, h), min(ju, w)
            num_array[il:iu, jl:ju] += 1

for i, s in enumerate(space_array):
    out = ["#" if m == 1 else str(int(num_array[i,j])) for j, m in enumerate(s)]
    print("".join(out))

Measured memory_bytes: 13636
def main():
    from itertools import accumulate

    n, q, s, *lr = open(0).read().split()
    n = int(n)
    *u, = map(int, lr)
    c = [1 if s[i] == 'C' and s[i - 1] == 'A' else 0 for i in range(n)]
    a = tuple(accumulate(c))
    ans = ''
    for i,j in zip(*[iter(u)]*2):
        ans += str(a[j-1]-a[i-1]) + '\n'
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;


bool solve(){

    int N, M , X, Y;
    cin >> N >> M >> X >> Y;
    vi x(N), y(M);
    rep(i, N)cin >> x[i];
    rep(i, M)cin >> y[i];

    for(int z = X+1; z <=Y; z++){
        bool f = true;
        for(auto a : x){
            if(a>=z)f = false;
        }
        for(auto a:y){
            if(a < z)f = false;
        }
        if(f)return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);

    bool b = solve();
    if(b) cout << "War" << "\n";
    else cout << "No War" << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n , n){
		int ans[2] = {0};
		rep(i,n){
			int a,b;
			cin >> a >> b;
			if(a==b)ans[0] += a , ans[1] += b;
			else ans[a<b] += a+b;
		}
		cout << ans[0] << " " << ans[1] << endl;
	}
}

Measured memory_bytes: 0
def main():
    N = int(input())

    user_remarks = {}

    for i in range(1, N+1):
        A = int(input())
        user_remarks[i] = []

        for _ in range(A):
            user_id, is_honest = [int(x) for x in input().split()]
            user_remarks[i].append((user_id, is_honest == 1))

    max_count = 0

    for i in range(2**N):
        honest = {}
        is_ok = True
        for x in range(N):
            # フラグが経っている時 = 正直もの
            if ((i >> x) & 1):
                honest[x+1] = True

                if is_ok:
                    # 正直者の証言チェック
                    for user_remark in user_remarks[x+1]:
                        target_user = user_remark[0]
                        target_is_honest = user_remark[1]

                        # ターゲットは正直者である場合
                        if target_is_honest:
                            # 正直者ではなかったら矛盾している
                            if not ((i >> (target_user-1)) & 1):
                                is_ok = False

                        # ターゲットが不親切な人である場合
                        if not target_is_honest:
                            # 正直者だったら矛盾している
                            if ((i >> (target_user-1)) & 1):
                                is_ok = False

        if is_ok:
            max_count = max(max_count, len(honest))

    print(max_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9236
#include<stdio.h>
int main(){
  int a[5];
  scanf("%d",&a[0]);
  scanf("%d",&a[1]);
  scanf("%d",&a[2]);
  scanf("%d",&a[3]);
  scanf("%d",&a[4]);
  int x;int b;
  for(x=0;x<5;x++){
    if(x==0){
      b=a[0]%10;
    }else if(a[x]%10<b && a[x]%10!=0) b=a[x]%10;
    if (a[x]%10!=0) a[x]=a[x]+10-(a[x]%10);
  }
  if (b!=0) printf("%d",a[0]+a[1]+a[2]+a[3]+a[4]-10+b);
  else printf("%d",a[0]+a[1]+a[2]+a[3]+a[4]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void AGC009A()
{
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i] >> B[i];
	}

	ll ct = 0;
	for (int i = N - 1; i > -1; --i)
	{
		ll x = A[i] + ct;
		int y = x % B[i];
		int z = y == 0 ? 0 : B[i] - y;
		ct += z;
	}
	cout << ct << endl;
}

int main()
{
	AGC009A();
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);



}



int main()
{
    long long a,n,b,c,d,i,m=0,x,sum=0,j,k;
    cin >> x;
    for(i=1;i<=x;i++)
    {
        for(j=1;j<=x;j++)
        {

            for(k=1;k<=x;k++)
            {

                long long p=gcd(max(i,j),min(i,j));
                //cout << "p " << p << endl;
                long long l=gcd(max(p,k),min(p,k));
                //cout << "l " << l << endl;
                sum+=l;

//cout << "i j k " << i << j << k << endl;

            }




        }




    }
    cout << sum << endl;

}


Measured memory_bytes: 3580
main :: IO ()
main = do
    [n, y] <- (map read) . words <$> getLine
    let combinations = [(a, b, n-a-b) | a <- [0..n], b <- [0..n-a], a*10000 + b*5000 + (n-a-b)*1000 == y]
    let (t1, t2, t3) = if null combinations then (-1, -1, -1)
                                            else head combinations
    putStr $ show t1 ++ " " ++ show t2 ++ " " ++ show t3 

Measured memory_bytes: 1020
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int l,r,m = 2019;
  cin >> l >> r;
  for (int i = l; i <= r; ++i)
  {
    if(i % 2019 == 0 )
    {
      cout << 0;
      return 0;
    }
  }
  l %= 2019;
  r %= 2019;
  for(int i=l;i<=r;i++)
  {
    for(int j= i+1;j<=r;j++)
    {
      if(i==j)continue;
      m=min(m,(i*j)%2019);
    }
  }
  cout << m <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n],b[n];
        for(ll i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        for(ll i=n-1;i>=2;i--)
        {
            if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2])
            {
                cout<<"Yes";
                return 0;
            }
        }
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        c[i] = a[i] + b[i];
    }
    sort(c.begin(),c.end());

    ll ans = 0;
    rep(i,n) ans -= (ll)b[i];
    for(int i = n-1; i >= 0; i -= 2)  ans += (ll)c[i];

    cout << ans << endl;
}

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

int main() {
	int k; cin >> k;
	if (k % 2 == 0) {
		printf("-1");
		return 0;
	}
	int remind = 7 % k, number = 1;
	while (remind) {
		++number;
		remind = (remind * 10 + 7) % k;
		if (number > 1000000) {
			cout << "-1" << endl;
			return 0;
		}
	}
	printf("%d\n", number);
	return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
void dfs(int node, vector<int> adj[], int dp[], bool vis[])
{
    vis[node] = true;
    for (int i = 0; i < adj[node].size(); i++) {
        if (!vis[adj[node][i]])
            dfs(adj[node][i], adj, dp, vis);

        dp[node] = max(dp[node], 1 + dp[adj[node][i]]);
    }
}
int findLongestPath(vector<int> adj[], int n)
{
    int dp[n + 1];
    memset(dp, 0, sizeof dp);
    bool vis[n + 1];
    memset(vis, false, sizeof vis);
    for (int i = 1; i <= n; i++) {
        if (!vis[i])
            dfs(i, adj, dp, vis);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    return ans;
}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int v,e;
        cin>>v>>e;
        vector<int> adj[v+1];
        for(ll i=0;i<e;i++){
            int a,b;
            cin>>a>>b;
            adj[a].push_back(b);
        }
        cout<<findLongestPath(adj,v)<<endl;
    }
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};

vector<int> G[1<<18];
vector<LL> dp1(1<<18,0);
vector<LL> dp2(1<<18,0);

LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
 
int n;

int dfs1(int u,int v){
    int ret = 1;
    for(auto g:G[u]){
        if(g==v) continue;
        ret += dfs1(g,u);
    }
    return dp1[u] = ret;
}


void dfs2(int u,int v){
    vector<LL> a;
    LL p = 1;
    for(auto g:G[u]){
        if(g==v){
            a.pb(n-dp1[u]);
        }
        else{
            a.pb(dp1[g]);
            dfs2(g, u);
        }
    }
    if(a.size() > 1){
        LL pp = 1;
        for(auto A:a){
            pp = pp * fpow(fpow(2LL, mod - 2), A) %mod;
        }
        p = (p - pp + mod)%mod;
        for(auto A:a){
            p = (p - (pp * fpow(2LL, A) %mod * (1LL - fpow(fpow(2LL, mod - 2), A) + mod %mod) %mod) + mod)%mod;
        }
    }
    else{
        p = 0;
    }
    dp2[u] = p * fpow(2LL, mod - 2) %mod;
}






int main(){
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs1(0,0);
    dfs2(0,-1);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + dp2[i])%mod;
        assert(dp2[i]>=0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 39552
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0;i<s.size();i++){
    for(int j=i;j<s.size();j++){
      string t = s.substr(i,j-i+1);
      bool f = true;
      for(auto u:t){
        if(u=='S')f = false;
      }
      if(f)ans = max(ans,(int)t.size());
    }
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    string ans[3] = {"hon", "pon", "bon"};
    int x[10] = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};

    int n;
    cin >> n;
    n %= 10;
    cout << ans[x[n]] << endl;

    return 0;
}

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

// 入力
int H, W;
vector<vector<int>> field;

// 探索
void dfs(int h, int w) {
    field[h][w] = 0;
    for (int dh = -1; dh <= 1; ++dh) {
        for (int dw = -1; dw <= 1; ++dw) {
            int nh = h + dh, nw = w + dw;
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (field[nh][nw] == 0) continue;
            dfs(nh, nw);
        }
    }
}

int main() {
    while (cin >> W >> H) {
        if (H == 0 || W == 0) break;
        field.assign(H, vector<int>(W, 0));
        for (int h = 0; h < H; ++h) for (int w = 0; w < W; ++w) cin >> field[h][w];
        
        int count = 0;
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                if (field[h][w] == 0) continue; 
                dfs(h, w);
                ++count;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3256
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // 調査対象
		int A = sc.nextInt(); // A の購読者数
		int B = sc.nextInt(); // B の購読者数

        int max = Math.min(A, B);
		int min = A + B < N ? 0 : A + B - N;
		
        System.out.println(max + " " + min);
	}
}

Measured memory_bytes: 21844
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e2 + 10 ;
string arr[maxn] ;
int n ;
set < string > st ;
int main () 
{
	cin >> n ;
	bool p = true ;
	for ( int i = 0 ; i < n ; i++ ) 
	{
		cin >> arr[i] ;
		p =  p & st.insert ( arr[i] ).second ;

	}
	cerr << p << endl;
	if ( !p ) 
	{
		cout << "No" << endl;
		return 0 ; 
	}
	string s = arr[0] ;
	for ( int i = 1 ; i < n ; i++ ) 
{
		if ( arr[i][0] != s[s.size()-1] ) 
		{
			cout << "No" << endl;
			return 0 ;
		}
		else
			s = arr[i] ;
}
	cout << "Yes" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int H, W;
string S[112];


int main(){
	
	cin>>H>>W;
	
	REP( i, H ) cin>>S[i];
	
	REP( i, H ){
		cout<<S[i]<<endl;
		cout<<S[i]<<endl;
	}
	
	return 0;

}

Measured memory_bytes: 256