akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;


int main(){
    V v(3);
    int k;
    rep(i,0,3) cin>>v[i];
    cin>>k;
    int sum=0;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    v[0]=v[0]*pow(2,k);
    rep(i,0,3) sum+=v[i];
    cout<<sum<<endl;
}

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

using namespace std;

#define MOD 1000000007
#define MODV 500000004

int n, par[200005], ver[200005], ta;
vector< int > v[200005], at[200005];
vector< long long > p[200005], sa[200005], sb[200005];
long long ans, sc[200005];

void dfs(int a) {
	if (v[a].empty()) {
		par[a] = a;
		p[a].push_back(MODV);
	} else {
		int ti;
		for (int i = 0; i < v[a].size(); i++) {
			dfs(v[a][i]);
			if (!i || p[par[v[a][i]]].size() > p[ti].size())
				ti = par[v[a][i]];
		}
		if (v[a].size() > 1) {
			for (int i = 0; i < v[a].size(); i++)
				if (ti != par[v[a][i]]) {
					ta = par[v[a][i]];
					at[i] = vector< int >(p[ta].size(), 0);
					for (int j = 0; j < p[ta].size(); j++) {
						if (ver[j] != a) {
							sa[j] = vector< long long >(1, 1);
							ver[j] = a;
						}
						at[i][j] = sa[j].size();
						sa[j].push_back(sa[j].back() * (MOD + 1 - p[ta][p[ta].size() - 1 - j]) % MOD);
					}
				}
			for (int i = 0; ver[i] == a; i++) {
				sc[i] = MOD + 1 - p[ti][p[ti].size() - 1 - i];
				// if (a == 7) printf("[%d]: %lld %lld\n", i, p[ti][p[ti].size() - 1 - i], sa[i].back());
				p[ti][p[ti].size() - 1 - i] = p[ti][p[ti].size() - 1 - i] * sa[i].back() % MOD;
				sb[i] = vector< long long >(sa[i].size(), 1);
			}
			for (int i = v[a].size() - 1; i >= 0; i--)
				if (ti != par[v[a][i]]) {
					ta = par[v[a][i]];
					for (int j = 0; j < p[ta].size(); j++) {
						sb[j][at[i][j] - 1] = sb[j][at[i][j]] * (MOD + 1 - p[ta][p[ta].size() - 1 - j]) % MOD;
						// if (a == 7) printf("[%d]: %lld %lld %lld\n", j, p[ta][p[ta].size() - 1 - j], sa[j][at[i][j] - 1], sb[j][at[i][j]], sc[j]);
						p[ti][p[ti].size() - 1 - j] = (p[ti][p[ti].size() - 1 - j] + p[ta][p[ta].size() - 1 - j] * sa[j][at[i][j] - 1] % MOD * sb[j][at[i][j]] % MOD * sc[j]) % MOD;
					}
				}
		}
		par[a] = ti;
		p[ti].push_back(MODV);
		// printf("%d: ", a); for (int i = 0; i < v[a].size(); i++) printf("%d%c", v[a][i], i == v[a].size() - 1 ? '\n' : ' ');
		// printf("%d(%d): ", a, ti); for (int i = 0; i < p[ti].size(); i++) printf("%lld%c", p[ti][i], i == p[ti].size() - 1 ? '\n' : ' ');
	}
}

int main() {
	memset(ver, -1, sizeof(ver));
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ta);
		v[ta].push_back(i);
	}
	dfs(0);
	ta = par[0];
	for (int i = 0; i < p[ta].size(); i++)
		ans += p[ta][i];
	ans %= MOD;
	for (int i = 0; i <= n; i++)
		ans = ans * 2 % MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 58360
#include <bits/stdc++.h>
using namespace std;
int N;
int64_t dp[100010][2];

void init()
{
  for (int i = 0; i < N; i++)
  {
    dp[i][0] = dp[i][1] = 1;
  }
}

int main()
{
  cin >> N;
  vector<int64_t> T(N), A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    cin >> T.at(i);
  }
  dp[0][0] = dp[0][1] = A[0];
  for (int i = 1; i < N; i++)
  {
    if (A[i] > A[i - 1])
    {
      dp[i][0] = dp[i][1] = A[i];
    }
    else
    {
      dp[i][1] = A[i];
    }
  }
  if (T[N - 1] < dp[N - 1][0] || dp[N - 1][1] < T[N - 1])
  {
    cout << 0 << endl;
    return 0;
  }
  dp[N - 1][0] = dp[N - 1][1] = T[N - 1];
  for (int i = N - 2; i >= 0; i--)
  {
    if (T[i] > T[i + 1])
    {
      if (T[i] < dp[i][0] || dp[i][1] < T[i])
      {
        cout << 0 << endl;
        return 0;
      }
      dp[i][0] = dp[i][1] = T[i];
    }
    else
    {
      int64_t mi = 1, ma = T[i];
      if (T[i] < dp[i][0])
      {
        cout << 0 << endl;
        return 0;
      }
      dp[i][0] = max(dp[i][0], (int64_t)1);
      dp[i][1] = min(dp[i][1], T[i]);
    }
  }
  const int64_t MOD = 1000000007;
  int64_t ans = 1;
  for (int i = 0; i < N; i++)
  {
    (ans *= (dp[i][1] - dp[i][0] + 1)) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6408
A, B, K = map(int,input().split())

L = B - A + 1

if L >= 2*K:
    for i in range(A, A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)
        
else:
    for i in range(A,B+1):
        print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringBuilder words = new StringBuilder();
			char c;
			char[] word = new char[6];
			int idx = 0;
			for (int i = 0; i < line.length(); i++) {
				c = line.charAt(i);
				if (c == ' ' || c == '.' || c == ',') {
					if (idx > 2 && idx < 7) {
						words.append(new String(Arrays.copyOf(word, idx)) + " ");
					}
					idx = 0;
				} else {
					if (idx < 6) {
						word[idx] = c;
					}
					idx++;
				}
			}
			System.out.println((words.substring(0, words.length() - 1)));
		}
	}
}

Measured memory_bytes: 16868
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 2147483647
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f

#define ll long long
#define rei register int
#define inv inline void
#define ull unsigned long long
#define il inline

#define bl putchar(' ')
#define ed putchar('\n')
#define test cout<<"this:" 

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x){
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define int long long
const int maxn=3e5+5;
const int mod=998244353;
int n,a,b,k;
int qpow(int a,int b){
	int ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod; b>>=1;
	}
	return ret;
}
int jc[maxn],iv[maxn];
void init(){
	jc[0]=1; for(rei i=1;i<=n;++i) jc[i]=jc[i-1]*i%mod;
	iv[n]=qpow(jc[n],mod-2); iv[0]=1;
	for(rei i=n-1;i>=1;--i) iv[i]=iv[i+1]*(i+1)%mod;
}
int C(int n,int m){
	return jc[n]*iv[n-m]%mod*iv[m]%mod;
}
signed main(){
	read(n),read3(a,b,k);
	init(); int ans=0;
	for(rei i=0;i<=n&&i<=k/a;++i){
		int rp=i*a,bp=k-rp;
		if(bp%b) continue;
		int bc=bp/b;
		if(bc>n) continue;
		ans=(ans+C(n,i)*C(n,bc)%mod)%mod;
	}
	write(ans),ed;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,M,X,m;cin>>N>>M>>X;
  X--;
  vector<int> road(N,0);
  REP(i,0,M){
    cin>>m;m--;
    road[m]=1;
  }
  int tmp=0,ans=INF;
  REP(i,X,N){
    tmp+=road[i];
  }
  ans=tmp;tmp=0;
  RREP(i,X,-1){
    tmp+=road[i];
  }
  ans=min(ans,tmp);
  print(ans);


}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    H1,M1,H2,M2, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    dif=H2-H1
    
    dif=60*(H2-H1)
    dif+=M2-M1
    print(dif-K)
 






if __name__ == "__main__":
    main()

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

int main(){
  int n;
  int i,j,k;
  int build[4][3][10]={{{}}};   // これで、リスト構造を作れている。
  cin >> n;
  int b,f,r,v;
  for(i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    build[b-1][f-1][r-1]+=v;  //  リストをつくるつくるときは、-1してつくる
  }
  for(i=0;i<4;i++){  // for文を用いれば、よくするミスを防げる
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout << " ";
	cout << build[i][j][k];
      }
      cout << endl;
    }
    if(i<3)cout << "####################" << endl;
  }
  return 0;
}


Measured memory_bytes: 3128
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int height = sc.nextInt();
			int width = sc.nextInt();
			if (height==0) {
				break;
			}
			char[][] tile = new char[width][height];
			boolean[][] moved = new boolean[width][height];
			for (int h=0;h<height;h++) {
				String line = sc.next();
				for (int w=0;w<width;w++) {
					tile[w][h] = line.charAt(w);
				}
			}
			int x = 0,y = 0;
			while(tile[x][y]!='.' && !moved[x][y]) {
				moved[x][y] = true;
				switch (tile[x][y]) {
				case '>':
					x++;
					break;
				case '^':
					y--;
					break;
				case '<':
					x--;
					break;
				case 'v':
					y++;
					break;
				}
			}
			if (tile[x][y]=='.') {
				System.out.println(x+" "+y);
			}else{
				System.out.println("LOOP");
			}
		}
	}
}

Measured memory_bytes: 21424
#define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

llint n;
llint a, b;
llint k;
llint ans = 0;
llint mod = 998244353;

llint mod_pow(llint a, llint n, llint m) {
  llint b, t;
  //----  初期条件
  if ( n == 0 ) { return 1; }    
  //----  事前計算
  a %= m; b = a*a; b %= m;
  //----  再帰呼出
  t = mod_pow(b, n/2, m);                // nが偶数のとき
  //----  事後計算
  if ( n%2 != 0 ) { t *= a; t %= m; }    // nが奇数のときの補正
  //----  結果返却
  return t;                              // 剰余の返却(t＜mを保障)
}

llint memo[400000] = {};
llint C(llint r) {
    if (n / 2 < r) r = n - r;
    if (r == 0) return 1;
    if (memo[r] == -1) memo[r] = C(r - 1) * (n - r + 1) % mod * mod_pow(r, mod - 2, mod) % mod;
    return memo[r];
}

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

    for (int i = 0; i <= n; i++) {
        memo[i] = -1;
    }

    for (llint i = 0; i <= n; i++) {
        llint j = (k - a * i) / b;
        if (j < 0 || n < j || a * i + b * j != k) continue;
        ans = (ans + C(i) * C(j)) % mod;
    }

    cout << ans << endl;

    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll k,a,b;
	cin >>k >>a >>b;
	
	ll sm = 0;
	if(b -a >2 && k >= 2+a-1){
		ll ak= k + 1 -a;
		ll su = ak / 2;
		sm = a + (b-a)*su + (ak%2);
		//dbg(sm, su, ak);
	}

	cout << max(k+1, sm) <<"\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){

  int n;

  cin>>n;

  if(n%2==0){
    cout<<n/2-1<<endl;
  }
  else{
    cout<<(n-1)/2<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin>>n;
    ll ans = 1e12;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i) continue;
        else{
            ans = i+n/i-2;
        }
    }
    cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

A = []

nums = input().split()

for i in range(N):
    A.append(int(nums[i]))

    

flag = 1
a = 0
cnt = 0

while flag:
    flag = 0
    for i in reversed(range(a+1, N)):
        if A[i] < A[i-1]:
            A[i], A[i-1] = A[i-1], A[i]
            cnt += 1
            flag = 1
    a += 1

l = [str(i) for i in A]
print(" ".join(l))
print(cnt)


Measured memory_bytes: 5604
#include<stdio.h>

#define limit 1000000000000000000

int main(void){
    long a,b,c;
    long long k;
    scanf("%ld %ld %ld %lld",&a,&b,&c,&k);
    long long ans;
    if(k % 2)ans = b-a;
    else ans = a-b;
    if(ans > limit || ans < -limit)puts("Unfair");
    else printf("%lld",ans);
    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


int main(){
    string s,t; cin >> s >> t;
    int ans = 1e9;
    REP(i, 0, s.size()-t.size()+1){
        int mid = 0;
        REP(l, 0, t.size()){
            if(s[i+l] != t[l]){
                mid++;
            }
        }
        chmin(ans, mid);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			if ((1 == m) || (1 == n)) {
				System.out.println(1);
				return;
			}
			List<Integer> factorCounts = calcFactorCounts(m);
			int max = factorCounts.stream().mapToInt(Integer::intValue).max().getAsInt();
			long[] factorial = new long[max + n], revFactorial = new long[max + n];
			factorial[0] = 1L;
			IntStream.range(1, max + n).forEach(i -> factorial[i] = factorial[i - 1] * i % MOD);
			revFactorial[max + n - 1] = modPow(factorial[max + n - 1], MOD - 2);
			IntStream.range(0, max + n - 1).map(i -> max + n - 2 - i)
					.forEach(i -> revFactorial[i] = revFactorial[i + 1] * (i + 1) % MOD);
			long result = 1L;
			for (int b : factorCounts) {
				result = result * factorial[b + n - 1] % MOD * revFactorial[n - 1] % MOD * revFactorial[b] % MOD;
			}
			System.out.println(result);
		}
	}

	/**
	 * mの因数の数を計算する
	 * 
	 * @param m
	 * @return mの因数の数の一覧
	 */
	private static List<Integer> calcFactorCounts(int m) {
		List<Integer> result = new ArrayList<>();
		int sqrt = (int) Math.sqrt(m);
		for (int i = 2; (i <= sqrt) && (m > 1); i++) {
			if (0 == (m % i)) {
				int count = 0;
				while (0 == (m % i)) {
					m /= i;
					count++;
				}
				result.add(count);
			}
		}
		if (m > 1) {
			result.add(1);
		}
		return result;
	}

	/**
	 * n^m mod MODを計算する
	 * 
	 * @param n
	 * @param m
	 * @return n^m mod MOD
	 */
	private static long modPow(long n, long m) {
		long result = 1L;
		while (m > 0) {
			if (1 == (m & 1)) {
				result = result * n % MOD;
			}
			n = n * n % MOD;
			m >>= 1;
		}
		return result;
	}
}


Measured memory_bytes: 39244
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(),, greater<int>())
#define pb push_back
#define ll long long

int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll ans=1000,n,x=0,f=0,y;
    cin>>n;vi v(n);
    rep(i,0,n)cin>>v[i];
    rep(i,0,n-1){
        f=0;
        rep(j,i+1,n){
            if(v[j]<=v[i]){f=1;break;}
            if(v[j]>v[i]){y=j;break;}
        }
        if(f)continue;
        ans=(ans/(v[i]))*(v[y])+ans%((v[i]));
        i=y-1;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9223372036854775807 //  巨大数INF
using namespace std;

signed main() {
  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1);
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll mini = LONG_LONG_MAX;
    ll x, y;
    cin >> x >> y;
    rep(i, 1LL << 2) {
        ll val = x;
        ll count = 0;
        if(i & 1LL) {
            val *= -1;
            count++;
        }
        count += abs(abs(y) - abs(val));
        val += abs(abs(y) - abs(val));
        if(i & 2LL) {
            val *= -1;
            count++;
        }
        if(val == y) mini = min(count, mini);
    }
    cout << mini << endl;
    return 0;
}


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

long int n,a,b,ans;

int main() {
  cin >> n >> a >> b;
  if (a + b == 0) {
    ans = 0;
  }else{
    ans = (n / (a + b)) * a + min(n % (a + b), a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] values = scanner.nextLine().split(" ");
        calcurate(values);
    }

    private static void calcurate(String[] values) {
        Stack<Integer> stack = new Stack<>();

        for (int i = 0; i < values.length; i++) {
            switch (values[i]) {
            case "+":
                stack.push(stack.pop() + stack.pop());
                break;
            case "-":
                stack.push(-(stack.pop() - stack.pop()));
                break;
            case "*":
                stack.push(stack.pop() * stack.pop());
                break;
            default:
                stack.push(Integer.parseInt(values[i]));
            }
        }

        System.out.println(stack.pop());
    }
}



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

int main(){
  int n, b, f, r, v;
  int count[5][4][11] = {};

  cin >> n;

  for ( int i = 0; i < n; i++ ){
    cin >> b >> f >> r >> v;
    count[b][f][r] += v;
  }

  for ( int i = 1; i <= 4; i++ ){
    for ( int j = 1; j <= 3; j++ ){
      for ( int k = 1; k <= 10; k++ ){
        cout << " " << count[i][j][k];
      }
      cout << "\n";
    }
    if ( i != 4 ) cout << "####################\n";
  }

  return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) { cin >> v.at(i); }

    sort(all(v));

    for(size_t i = 0; 1 < v.size(); i++) {
        {
            v.at(0) = (v.at(0) + v.at(1)) / 2;
            v.erase(v.begin() + 1);
        }
    }
    rep(i, v.size()) { cout << v.at(i) << endl; }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string a, b, c, answer;
    cin >> a >> b >> c;
    answer.push_back(a.at(0));
    answer.push_back(b.at(0));
    answer.push_back(c.at(0));
    std::transform(answer.begin(), answer.end(), answer.begin(), ::toupper);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string a,b,c;
	cin>>a>>b>>c;
	string ans;
	ans+=toupper(a[0]);
	ans+=toupper(b[0]);
	ans+=toupper(c[0]);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int K,X;
    cin >> K >> X;
    if(K*500>=X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())

dic = {}
for i in range(N):
  si = input()
  if si in dic:
    dic[si] += 1
  else:
    dic[si] = 1

s_set = set(dic.keys())
s_set = sorted(s_set)

max = 0
for si in s_set:
  if dic[si] > max:
    max = dic[si]

for si in s_set:
  if dic[si] == max:
    print(si)

Measured memory_bytes: 105944
# coding: utf-8
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(N):
    A.append(A[i] + K)
ans = float("inf")
for i in range(1, N+1):
    ans = min(ans, A[i+N-1] - A[i])
print(ans)

Measured memory_bytes: 26000
#define _GLIBCXX_DEBUG
#define LIM 1000000007
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;

int main(void){
    int n;
    cin >> n;
    vi a(n), s(n+1);
    for(i64 &x : a) cin >> x;
    for(int i=n-1; i>0; i--){
        s[i] = a[i] + s[i+1];
        if(s[i] >= LIM) s[i] %= LIM;
    }
    i64 sum = 0;
    for(int i=0; i<n-1; i++){
        sum += a[i] * s[i+1];
        if(sum >= LIM) sum %= LIM;
    }
    cout << sum << '\n';
    return 0;
}

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------
bool cmp(pii a, pii b)
{
	return a.ff < b.ff;
}

int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------

	string s;
	getline(cin, s);

	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;

}





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


int main() {
  ll N;cin>>N;
  vector<pair<ll,ll>> A(N+1);rep(i,N) cin>>A[i+1].first;
  for(int i=1;i<=N;i++) A[i].second=i;
  A[0].first=0;A[0].second=0;
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  if(A[0].first==A[1].first){
    rep(i,N) cout << A[0].first << endl;
    return 0;
  }
  
  else{
	for(int i=0;i<A[0].second-1;i++) cout << A[0].first << endl;
    cout << A[1].first << endl;
    for(int i=1;i<=N-A[0].second;i++) cout << A[0].first << endl;
  }
}
 

Measured memory_bytes: 6404
#include<iostream>
#include<string>
using namespace std;
int main(){
	string x;
	char a[27];
	int i,count[27]={0},j;
	while(cin>>x){
		for(i=0;i<x.size();i++){
			if(isupper(x[i])){
				x[i]=tolower(x[i]);
			}
			j=x[i]-'a';
			count[j]++;
		}
	}
	for(i=0;i<26;i++){
		a[i]='a'+i;
		cout<<a[i]<<" : "<<count[i]<<endl;
	}

	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int cnt1 = 0;
        int cnt2 = 0;
        for(int j = 0; j < N; j++) {
            if(A[i] > A[j]) {
                cnt1++;
                if(i < j) {
                    cnt2++;
                }
            }
        }
        ans+=cnt2*K%INF;
        ans+=K*(K-1)/2%INF*cnt1%INF;
        ans%=INF;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
def isPrime(x):
	for i in range(2,min(x,236)):
		if x%i == 0:
			return False
	return True
n,a,p = int(input()),[],2
while n > 0:
	if isPrime(p):
		a.append(str(p))
		n -= 1
	p += 5
print(" ".join(a))


Measured memory_bytes: 2940
function Main(arg) {
    const k = arg;

    let x = 7 % k;
    let cnt = 1;
    const s = new Set();

    while(!s.has(x)){
        if(x === 0) {
            console.log(cnt);
            return;
        }
        s.add(x);
        x = (x * 10 +7) % k;
        cnt++;
    }

    console.log('-1');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 74228
#include <bits/stdc++.h>
#define ll long long
#include <stdio.h>
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define SZ(v)   ((int)((v).size()))
#define LP(c,x,n)  for(int c=x;c<n;c++)
#define MOD(a,n) ((a%n+n)%n)
#define LO(c,n,x)  for(int c=n;c>=x;c--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PB push_back
#define F first
#define S second
#define STP(x) setprecision(x)
#define MP make_pair
#define PI ( 2 * acos(0.0))
#define EPS 1e-8
#define INF 1.0/0.0
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
using namespace std;
const int OO = 0x3f3f3f3f,NegOO= -1*OO,N =1e2+5,mod =1e9+7 ;
ll dp[N][5][5][5][5],n;
// A=0,C=1,G=2,T=3
ll solve(int i,int cur,int pre,int prePre,int preeee){
    if(cur==1&&prePre==2&&preeee==0)return 0;
    if(cur==1&&pre==2&&(preeee==0||prePre==0))return 0;
    if(cur==1&&pre==0&&prePre==2)return 0;
    if(cur==2&&pre==1&&prePre==0)return 0;
    if(i==n)return 1;
    ll &rf=dp[i][cur][pre][prePre][preeee];
    if(~rf)return rf;
    rf=0;
    LP(c,0,4){
        rf+=(solve(i+1,c,cur,pre,prePre)%mod);
    }
    return rf%mod;
}
int main() {
    Yala_Besor3a;
    cin>>n;
    memset(dp,-1, sizeof(dp));
    cout<<solve(0,4,4,4,4)%mod<<endl;
    return 0;
}
// AGC
// GAC
// ACG

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

int main(){
    int n,m;
    cin >> n >> m;
    
    int R[1001];
    for(int i=1; i<=n; i++){
        R[i] = 0;
    }
    
    int A[1001],B[1001];
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    
    A[n] = 0;
    for(int j=0; j<m; j++){
        cin >> B[j];
        for(int i=0; A[i]!=0; i++){
            if(A[i]<=B[j]){
                R[i+1]++;
                break;
            }
        }
    }
    
    int res=0;
    int num=0;
    for(int r=1; r<=n; r++){
        if(res < R[r]){
            res = R[r];
            num = r;
        }
    }
    
    cout << num << endl;
}

Measured memory_bytes: 3092
program knot_puzzle
  implicit none
  integer :: n, i, j
  integer(8) :: l, a(100000)
  a = 0_8
  read(*,*) n, l
  read(*,*) a(1:n)
  j = -1
  do i = 1, n-1
    if (a(i)+a(i+1).ge.l) then
      j = i
    end if
  end do
  if (j.lt.0) then
    write(*,'(a)') "Impossible"
    stop
  end if
  write(*,'(a)') "Possible"
  do i = 1, j-1
    write(*,'(i0)') i
  end do
  do i = n-1, j, -1
    write(*,'(i0)') i
  end do
  stop
end program knot_puzzle

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main()
{
    string s;
    int d[4];
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        d[i] = s[i] - '0';
    }

    for (int i = 0; i < (1 << 3); i++)
    {
        int s = d[0];
        for (int j = 0; j < 3; j++)
        {
            if (i >> j & 1)
            {
                s += d[j + 1];
            }
            else
            {
                s -= d[j + 1];
            }
        }
        if (s == 7)
        {
            cout << d[0];
            for (int j = 0; j < 3; j++)
            {
                if (i >> j & 1)
                {
                    cout << '+';
                }
                else
                {
                    cout << '-';
                }
                cout << d[j + 1];
            }
            cout << "=7" << endl;
            break;
        }
    }
}

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

int main()
{
    string s;
    cin >> s;
    int n;
    n = s.size();
    int a = n, b = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'A')
        {
            a = min(a, i);
        }
        if (s[i] == 'Z')
        {
            b = max(b, i);
        }
    }
    
    cout <<b-a+1<< endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long

using namespace std;
struct dsu1 {
    int parent[200001],siz[200001];
    int find(int a) {
        if (parent[a] == a)
            return a;
        else
            return parent[a] = find(parent[a]);
    }

    void dsu(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b)
            return;
        if (siz[b] > siz[a])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }

    void init() {
        for (int i = 1; i <= 200000; i++) {
            siz[i] = 1;
            parent[i] = i;
        }
    }
};
int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int x,y,z;
    cin>>x>>y>>z;
    dsu1 o;
    o.init();
    for(int i=0;i<y;i++){
        int a,b;
        cin>>a>>b;
        if(o.find(o.parent[a])!=o.find(o.parent[b])){
            o.dsu(a,b);
        }
    }
    dsu1 m;
    m.init();
    for(int i=0;i<z;i++){
        int a,b;
        cin>>a>>b;
        if(m.find(m.parent[a])!=m.find(m.parent[b])){
            m.dsu(a,b);
        }
    }
    vector<int>a(x+1),b(x+1);
    map<pair<int,int>,int>ma;
    for(int i=1;i<=x;i++)
        ma[{o.find(o.parent[i]),m.find(m.parent[i])}]++;
    for(int i=1;i<=x;i++)
        cout<<ma[{o.find(o.parent[i]),m.find(m.parent[i])}]<<' ';
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;cin>>n;
  long long res = n-1;
  long long tmp = sqrt(n)+1;
  for(long long i = 1;i<=tmp;++i){
    if(n%i==0){
      res = min(res,i+n/i-2);
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [sys.stdin.readline()[:-1] for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

H, W = LI()
a = LSR(H)

#dp[H][W]
dp = [[0]*W for i in range(H)]

for i in range(W):
    if (a[0][i] == "#"):
        break
    dp[0][i] = 1
for i in range(H):
    if (a[i][0] == "#"):
        break
    dp[i][0] = 1

for i in range(1, H):
    for j in range(1, W):
        if (a[i][j] == "#"):
            continue
        if (a[i][j-1] != "#"):
            dp[i][j] += dp[i][j-1]
        if (a[i-1][j] != "#"):
            dp[i][j] += dp[i-1][j]
        if (dp[i][j] >= mod):
            dp[i][j] %= mod

print(dp[H-1][W-1])

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

typedef long long ll;

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

ll lcm(ll a, ll b)
{
        ll tmp = gcd(a, b);
        return a / tmp * b;
}

int main()
{

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

        ll l = 1;
        for (int i = 0; i < N; ++i) {
                l = lcm(l, T[i]);
        }
        cout << l << endl;
}


Measured memory_bytes: 256
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = input_string[1].rstrip()
    K = makeInt(input_string[2])
    r = S[K-1]
    rS = ""
    for t in S:
        #print(t)
        if t != r:
            rS += "*"
        else:
            rS += t
    return rS


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


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

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    cout << X * min(N, K) + max(0, (N - K)) * Y << endl;
    return 0;
}

Measured memory_bytes: 256
s=int(input())
a=[]
a.append(s)
for i in range(1,10000000):
    a1=a[i-1]
    if(a1%2==0):
        tmp=int(a1/2)        
    else:
        tmp=3*a1+1
    
    if tmp in a:
        print(i+1)
        exit()

    a.append(tmp)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,C,d[33][33],c[505][505],sd[3][33]={},ans=1e17;
  cin>>n>>C;
  Fr(i,C) Fr(j,C) cin>>d[i][j];
  Fr(i,n) Fr(j,n) cin>>c[i][j];
  Fr(k,C) Fr(i,n) Fr(j,n) sd[(i+j)%3][k]+=d[c[i][j]][k];
  Fr(i,C){
    Fr(j,C){
      Fr(k,C){
        if(i==j||j==k||k==i) continue;
        ans=min(ans,sd[0][i]+sd[1][j]+sd[2][k]);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2176
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long ul;
typedef unsigned int ui;
const ul INF = 1LL<<60;
long N,Y,x,y,z,t;

inline void solve2(){
  IN2(N,Y);
  REP(x,N+1){
    t=5000*(N-x)-(Y-10000*x);
    if(t%4000)continue;
    z=t/4000;
    if(z<0||z>N)continue;
    y=N-x-z;
    if(y<0||y>N)continue;
    OUT3(x,y,z);
    return;
  }
  OUT3(-1,-1,-1);
}

inline void solve(){
  IN2(N,Y);
  REP(x,N+1)REP(y,N-x+1){
    z=N-x-y;
    if(z<0)break;
    if(10000*x+5000*y+1000*z==Y){
      OUT3(x,y,z);
      return;
    }
  }
  OUT3(-1,-1,-1);
}

int main(int argc,char**argv){
  BEGIN;
  solve2();
  END;
}


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

using namespace std;

long MOD = 1e9 + 7;

long solve(vector<long> &dp, int n) {
    if (dp[n] > 0) return dp[n];
    else {
        dp[n] = 1;
        for (int i = 3; i <= n - 3; ++i) {
            dp[n] = (solve(dp, n - i) % MOD + dp[n]) % MOD;
        }
        return dp[n];
    }
}

int main() {
    long S;
    cin >> S;
    if (S < 3) cout << 0 << endl;
    else {
        vector<long> dp(2001, -1);
        dp[3] = 1;
        dp[4] = 1;
        dp[5] = 1;
        dp[6] = 2;
        dp[7] = 3;
        solve(dp, S);
        cout << dp[S] << endl;
    }
    return 0;
}


Measured memory_bytes: 3628