akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
bool prime[1000007];
vector<int> primes[1000007];
void work(){
	memset(prime, true, sizeof(prime));
	prime[0] = false;
	prime[1] = false;
	for(int i = 2; i <= 1000005; i++){
		if(prime[i]){
//			primes[i].push_back(i);
			for(int j = i; j <= 1000005; j += i){
				prime[j] = false;
				primes[j].push_back(i);
			}
		}
	}
}
int have_primes[1000007];
int main(){
	work();
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	bool pairwise = true;
	for(int i = 0; i < n; i++){
		int p = primes[a[i]].size();
//		cout << a[i] << " " << p << endl;
		for(int j = 0; j < p; j++){
			if(have_primes[primes[a[i]][j]] == 0){
				have_primes[primes[a[i]][j]]++;
			}else{
				pairwise = false;
				have_primes[primes[a[i]][j]]++;
			}
		}
	}
//	for(int i = 0; i <= 5; i++) cout << have_primes[i] << endl;
	if(pairwise){
		cout << "pairwise coprime" << endl;
	}else{
		for(int i = 2; i <= 1000000; i++){
			if(have_primes[i] == n){
				cout << "not coprime" << endl;
				return 0;
			}
		}
		cout << "setwise coprime" << endl;
	}
	return 0;
}

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

static const int N = 4;
static const int N2 = 16;
static const int LIMIT = 100;

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
    int sum = 0;
    for(int i = 0; i < N2; i++){
        if(pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i]-1];
    }
    return sum;
}

bool dfs(int depth, int prev){

    if(state.MD == 0) return true;
    if(depth + state.MD > limit) return false;
    int sx = state.space / N;
    int sy = state.space % N;
    Puzzle tmp;

    for(int r = 0; r < 4; r++){
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if(tx < 0 || ty < 0 || tx >= N || ty >= N){
            continue;
        }
        if(std::max(prev, r) - std::min(prev, r) == 2) continue;
        tmp = state;
        state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
        state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
        std::swap(state.f[tx*N+ty], state.f[sx*N+sy]);
        state.space = tx * N + ty;
        if(dfs(depth + 1, r)){
            path[depth] = r;
            return true;
        }
        state = tmp;
    }

    return false;

}

std::string iterative_deepning(Puzzle in){
    in.MD = getAllMD(in);

    for(limit = in.MD; limit <= LIMIT; limit++){
        state = in;
        if(dfs(0, -100)){
            std::string ans = "";
            for(int i = 0; i < limit; i++) ans += dir[path[i]];
            return ans;
        }
    }

    return "unsolvable";
}

int main(void){
    for(int i = 0; i < N2; i++){
        for(int j = 0; j < N2; j++){
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle in;

    for(int i = 0; i < N2; i++){
        std::cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }

    std::string ans = iterative_deepning(in);
    std::cout << ans.size() << std::endl;

    return 0;
}


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

using namespace std;

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        string str;
        stringstream ss;
        ss << i;
        str = ss.str();

        int t = 0;
        for(int j = 0; j < str.size(); j++){
            t += str[j] - '0';
        }
        if(t <= b && t >= a)ans += i;
    }
    cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

const int INF=2e9;

void app() {
  int h,w;
  cin>>h>>w;

  vector<int> al(h),bl(h);
  rep(i,h){
    cin>>al[i]>>bl[i];
    al[i]--;
  }
  map<int,int> sc;
  map<int,int> invcounts;
  rep(i,w){
    sc[i]=0;
  }
  invcounts.emplace(0,w);

  rep(i,h){
    int a=al[i];
    int b=bl[i];
    //cout<<a<<'~'<<b<<endl;

    int newbval=INF;
    for(auto it=sc.lower_bound(a); it!=sc.end()&&it->first<=b; it=sc.erase(it)){
      int k=it->first;
      int v=it->second;
      invcounts[v]--;
      if(invcounts[v]==0) invcounts.erase(v);
      chmin(newbval,b-k+v);
    }
    if(b<w && newbval!=INF){
      sc[b]=newbval;
      invcounts[newbval]++;
    }

    //for(auto e:sc) cout<<e.first<<':'<<e.second<<endl;

    if(invcounts.empty()){
      cout<<-1<<endl;
    }else{
      int min=invcounts.begin()->first;
      cout<<(min+i+1)<<endl;
    }
  }

}

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


Measured memory_bytes: 14340
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		long[] a = new long[N];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			if (a[i] == 0) {
				System.out.println(0);
				return;
			}
		}
		long b = a[0];
		for (int i = 1; i < N; i++) {
			if (a[i] <= 1000000000000000000L / b) {
				b *= a[i];
			} else {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 51020
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    ll n, l;
    cin >> n >> l;
    vector<ll> a(n);
    rep (i, n) cin >> a[i];

    int hozon = -1;
    rep (i, n - 1) {
        if (a[i] + a[i + 1] >= l) {
            hozon = i + 1;
        }
    }

    if (hozon == -1) cout << "Impossible" << endl;
    else {
        cout << "Possible" << endl;
        for (int i = 1; i < hozon; i++) cout << i << endl;
        for (int i = n - 1; i > hozon; i--) cout << i << endl;
        cout << hozon << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define int long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define fone for(i=0;i<n;i++)
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N          = 5000*100+1;
const ll N2      = 1000*1000+5;
const ld PI  = 3.14159265;
const ll R   = 250;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ return (a.second < b.second); }
  
signed main ()
{
  fastio();
  int n,m;
  cin>>n>>m;
  int dp[n+1][m+1];
  char a[n+1][m+1];
  fill(dp,0);
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
      cin>>a[i][j];
    }
  }
  dp[1][1]=1;
  for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=m;j++)
      {
        if(i==1 && j==1)
        {
          dp[i][j]=1;
        }
        else
        {if(a[i][j]=='#')
        {
          //cout<<i<<j;
          dp[i][j]=0;
        }
        if(a[i][j]=='.')
        {
          //cout<<"*";
          dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }}
        //cout<<dp[i][j]<<" ";
      }//cout<<endl;
    }
    cout<<dp[n][m]<<endl;


  

  return 0;
}

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

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

    string s;
    cin >> s;

    s[s.size()] = 'S';
    int cnt = 0, mx = 0;
    for(int i = 0; i <= 3; i++)
    {
        if(s[i] == 'R')
        {
            cnt++;
        }
        else
        {
            mx = max(mx, cnt);
            cnt = 0;
        }
    }
    cout << mx << '\n';


    return 0;
}


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

if (B-A)/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 <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    string a;
    int b,c;
    cin>>a;
    c=(a[0]-'0')*10+(a[1]-'0');
    b=(a[2]-'0')*10+(a[3]-'0');
    if(b>0&&b<=12){
        if(c>0&&c<=12)cout<<"AMBIGUOUS";
        else cout<<"YYMM";
    }
    else if(c>0&&c<=12)cout<<"MMYY";
    else cout<<"NA";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N=5050,OO=1e18;
pii a[N];
int dp[N][N];

int32_t main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i].f>>a[i].s;
    }
    sort(a+1,a+n+1,[](const pii&p1,const pii&p2){return p1.f+p1.s<p2.f+p2.s;});
    forn(i,n+1)forn(j,n+1)dp[i][j]=OO;
    dp[0][0]=0;
    for(int i=1;i<=n;++i){
        for(int j=0;j<=i;++j){
            dp[i][j]=dp[i-1][j];
            if(j&&a[i].f>=dp[i-1][j-1])
                upn(dp[i][j],dp[i-1][j-1]+a[i].s);
        }
    }
    for(int i=n;i>=0;--i){
        if(dp[n][i]<OO){
            cout<<i<<'\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 201020
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	cin>>n;
	cin>>s;
	ll maxh=-1e9;
	while(n--){
		if(s[x++]=='I')sum++;
		else sum--;
		maxh=max(maxh,sum);
	}
	if(maxh<0)maxh=0;
	cout<<maxh;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0LL; i < (n); i++)
using Graph = vector<vector<int>>;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    ll nb = a % b;
    return gcd(b, nb);
}

ll factorial(ll a) {
    if (a == 0) return 0;
    if (a % 2 == 0) return factorial(a / 2) + 1;
    else return 0;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    
    rep(i, n) {
        ll temp;
        cin >> temp;
        a.at(i) = temp ;        
    }

    ll num = factorial(a[0]);
    //bool flag = false;
    a[0] = a[0] >> num;
    //if (a[0] == 1) flag = true;

    rep(i, n - 1) {
        if (num != factorial(a[i + 1])) {
            cout << 0 << endl;
            return 0;
        }
        a[i + 1] = a[i + 1] >> num;
        //if (a[i + 1] == 1) flag = true;
    }

    ll res = a.at(0);
    rep(i, n - 1) {
        res = a.at(i + 1) / gcd(a[i+1], res) * res;
        if (res > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    res = res << (num - 1);
    ll ans = (m / res + 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;

void solve(){
    int n, l;
    cin >> n >> l;
    vector <string> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    for(auto i : a) cout << i;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}



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

vector <string> v;
int n, ans;
string c[101], s[4] = {"One","Two","Three","Four"};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
	cin >> n;
	for ( int I = 0; I < n; I++ )
	{
		cin >> c[I];
		int cnt = 0;
		for ( int J = 0; J < v.size(); J++ )
			if (c[I] == v[J] )
			{
				cnt++;
				break;
			}
		if ( cnt == 0 )
		{
			v.push_back(c[I]);
			ans++;
		}
	}
	cout << s[ans - 1] << endl;
}


Measured memory_bytes: 256
Imports System.Console
Module Module1
    Dim ans As Int64
    Dim max As Int64
    Dim n, k, x, t As Int64
    Sub Main()
        Dim s() As String = ReadLine().Split
        n = s(0)
        x = s(1)
        t = s(2)
        ans = n \ x
        If n Mod x <> 0 Then
            ans += 1
        End If
        ans *= t
        WriteLine(ans)
    End Sub
End Module


Measured memory_bytes: 28396
package main

import (
  "fmt"
  "os"
  "io"
)

func solve(w io.Writer, r io.Reader) {
  var N int
  var s string
  fmt.Fscan(r, &N, &s)

  var c int
  for _, h := range s {
    if h == 'R' {
      c++
      if c * 2 > N {
        fmt.Fprint(w, "Yes")
        return
      }
    }
  }
  fmt.Fprint(w, "No")
}

func main() {
  solve(os.Stdout, os.Stdin)
}

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

typedef pair<int,int> pii;

bool memo[100][100][4][11][11];
struct p {
	int y, x, d, r, l;
};

int main() {
	int N, M, A;
	cin >> N >> M >> A;
	vector<string> b(N);
	for(int i = 0; i < N; i++) {
		cin >> b[i];
	}
	queue<p> q;
	pii goal, start;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			if(b[i][j]=='S') {
				memo[i][j][0][0][0] = true;
				q.push((p){i,j,0,0,0});
				start=pii(i,j);
			}
			if(b[i][j]=='G') {
				goal=pii(i,j);
			}
		}
	}
	while(q.size()) {
		int dxy[] = {1,0,-1,0,1};
		p t = q.front(); q.pop();
		//cout << t.y << " " << t.x << " " << t.d << endl;
		for(int i = 0; i < 4; i++) {
			int nx, ny;
			ny = t.y + dxy[i];
			nx = t.x + dxy[i+1];
			if(ny < 0 || N <= ny || nx < 0 || M <= nx) continue;
			if(b[ny][nx] == '#') continue;

			if(ny==start.first && nx==start.second && i==2) continue;

			if(i==(t.d+2)%4) {
				continue; // turn
			}
			else if(i==t.d) {
				// go straight
				if(memo[ny][nx][i][t.r][t.l]) continue;
				memo[ny][nx][i][t.r][t.l] = true;
				q.push((p){ny,nx,i,t.r,t.l});
			}
			else if(b[t.y][t.x] == '.') {
				if(i+t.d==3){
					// type P
					if(t.r+1 > A) continue;
					if(memo[ny][nx][i][t.r+1][t.l]) continue;
					memo[ny][nx][i][t.r+1][t.l] = true;
					q.push((p){ny,nx,i,t.r+1,t.l});
				}
				else {
					// type Q
					if(t.l+1 > A) continue;
					if(memo[ny][nx][i][t.r][t.l+1]) continue;
					memo[ny][nx][i][t.r][t.l+1] = true;
					q.push((p){ny,nx,i,t.r,t.l+1});
				}
			}
		}
	}
	int res = -1;
	for(int i = 0; i <= A; i++) {
		for(int j = 0; j <= A; j++) {
			for(int k = 0; k < 4; k++) {
				if(memo[goal.first][goal.second][k][i][j]) {
					if(res+1) res = min(res, i+j);
					else res = i+j;
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6456
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my $s = <STDIN>;

my @c_b = ();
$#c_b = $n - 1;
my @c_w = ();
$#c_w = $n - 1;
my $c_b1 = 0;
my $c_w1 = 0;
for(my $i=0;$i<$n;$i++){
  $c_b1 += 1 if( substr($s,$i,1) eq '#' );
  $c_b[$i] = $c_b1;
  $c_w1 += 1 if( substr($s,$i,1) eq '.' );
  $c_w[$i] = $c_w1;
}

my $cnt = -1;
for(my $i=$n-1;$i>=0;$i--){
  my $cnt1 = 0;
  if( $i < $n-1 ){
    $cnt1 += $c_w[$n-1] - $c_w[$i];
  }
  if( $i > 0 ){
    $cnt1 += $c_b[$i-1];
  }
  if( $cnt == -1 || $cnt1 < $cnt ){
    $cnt = $cnt1;
  }
}

$cnt = 0 if $cnt == -1;

print "$cnt\n";

exit(0);



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

signed main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif
  int n, k;
  cin >> n >> k;
  vector<ll> w(n);
  vector<ll> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> d[i];
  }
  ll L = 0, R = 3e18;
  while (L + 1 < R) {
    ll C = (L + R) / 2;
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (C >= w[i]) {
        cnt += (C - w[i]) / d[i] + 1;
      }
      cnt = min<ll>(cnt, 3e18);
    }
    if (cnt >= k) {
      R = C;
    } else {
      L = C;
    }
  }
  cout << R << '\n';
}


Measured memory_bytes: 1792
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int f[2020]={0};
int main(){
	int n;
	string s;cin>>s;
	reverse(all(s));
	n=s.size();
	int sum=0,ans=0,m=1;
	for(int i=0;i<n;i++){
		sum=(sum+(s[i]-'0')*m%2019)%2019;
		m=m*10%2019;
		f[sum]++;
		if(sum==0)ans+=f[sum];
		else ans+=f[sum]-1;
		//cout<<sum<<" "<<f[sum]<<endl;
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n, m;
LL k;
int p[N], stk[N], res[N];
LL x[N], ans[N];
bool vis[N];
int main() {
#ifdef fwat
	freopen("data.in", "r", stdin);
#endif
	n = gi();
	rep(i, 1, n) x[i] = gi(), p[i] = i;
	scanf("%d%lld", &m, &k);
	rep(i, 1, m) {
		int x = gi();
		swap(p[x], p[x + 1]);
	}
	rep(i, 1, n) if(!vis[i]) {
		int tp = 0;
		for(int j = i; !vis[j]; j = p[j]) stk[tp++] = j, vis[j] = 1;
		for(int j = 0; j < tp; ++j) 
//		res[stk[(j + k) % tp]] = stk[j];
		res[stk[j]] = stk[(j + k) % tp];
	}
	rep(i, 1, n) ans[i] = ans[i - 1] + x[res[i]] - x[res[i] - 1];
	rep(i, 1, n) printf("%lld\n", ans[i]);
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int H,W;
  cin >> H >> W;
  
  char s[50][50];

  REP(i,H)REP(j,W)cin >> s[i][j];

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

  int c[50][50];
  REP(i,H)REP(j,W)c[i][j] = 0;

  REP(i,H)REP(j,W){
    if(s[i][j]=='#')continue;

    REP(k,8){
      int ii = i + dx[k];
      int jj = j + dy[k];

      if(ii < 0 || ii >= H)continue;
      if(jj < 0 || jj >= W)continue;

      if(s[ii][jj]=='#')c[i][j]++;
    }
  }

  REP(i,H){
    REP(j,W){
      if(s[i][j]=='#'){
        cout << '#';
      }else{
        cout << c[i][j];
      }
    }
    cout << endl;
  }

}



Measured memory_bytes: 892
def solve(pos):
  for i in range(n):
    if line[pos][i] == 1 and reach[i] == 0:
      reach[i] = 1
      solve(i)
  return

n, m = list(map(int, input().split()))
line = [[0]*n for i in range(n)]
ms = []

for i in range(m):
  a, b = list(map(int, input().split()))
  line[a-1][b-1]=1
  line[b-1][a-1]=1
  ms.append([a, b])
  
ans = 0
for i in range(m):
  line[ms[i][0]-1][ms[i][1]-1]=0
  line[ms[i][1]-1][ms[i][0]-1]=0
  reach=[0]*n
  reach[0]=1
  solve(0)
  if 0 in reach:
    ans += 1
  line[ms[i][0]-1][ms[i][1]-1]=1
  line[ms[i][1]-1][ms[i][0]-1]=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a,z,x,c,v;
int main()
{
	scanf("%d",&a);
	z=a/1000;
	x=(a/100)%10;
	c=(a/10)%10;
	v=a%10;
	if((z==x&&x==c)||(x==c&&c==v))
		printf("Yes\n");
	else
		printf("No\n");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder.XXX.A
{ 
    public class Program
    {
        public static void Main(string[] args)
        {
            var a = long.Parse(r());
            var q = a + (a * a) + (a * a * a);
            P(q.ToString());
        }

        private static StreamReader sr;
        public static int[] Ecr()
        {
            if (sr == null)
            {
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine().Split().Select(int.Parse).ToArray();
        }
        public static string Er()
        {
            if (sr == null)
            {
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine();
        }
        public static string r()
        {
            return Console.ReadLine();
        }
        public static  int[] cr()
        {
            return Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
        public static int cri()
        {
            return int.Parse(Console.ReadLine());
        }
        public static void P(string str)
        {
            Console.WriteLine(str);
        }
        public static void P(int num)
        {
            P(num.ToString());
        }
    }
}


Measured memory_bytes: 27440
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<bool,ll> mp;
ll inf =  1e9;

    ll n,m;
    vector<ll> a;
    vector<ll> s;
bool ok( ll mid ){
     bool flag = false;
     ll cnt = 0;
     for(ll i=0;i<n;i++){
	 ll tmp = mid - a[i];
	 auto it = upper_bound( a.begin() , a.end() , tmp );
	 //auto it = lower_bound( a.begin() , a.end() , tmp );
	 cnt += a.end() - it;
     }
     if( cnt <= m ) return true;
     return  false;
 }

int main(){
    cin>>n>>m;
    a = vector<ll>(n);
    s = vector<ll>(n+1);
    s[0] = 0;
    for(ll i=0;i<n;i++) cin>>a[i];
    sort( a.begin() , a.end() );
    for(ll i=0;i<n;i++) s[i+1] = s[i] + a[i];


    ll l = 0,u = 2*a[n-1]+10;
    while( u - l > 1 ){
	ll mid = ( u + l )/2;
	if( ok(mid) ){
	    u = mid;
	}else{
	    l = mid;
	}
    }

 //cout<<"l"<<l<<' '<<a.end()-lower_bound(a.begin(),a.end() , 19 )<<endl;
    if( ok(l) ){
	
    }else l++;
 //cout<<"l"<<l<<' '<<a.end()-lower_bound(a.begin(),a.end() , 19 )<<endl;
   
    //for(ll i=0;i<=n;i++)cout<<s[i]<<' ';
    //cout<<endl;
   // l++;
    ll sum = 0;
    ll cnt = 0;
    for(ll i = 0;i<n;i++){
	//ll tmp = a[i];
	auto it = lower_bound( a.begin() , a.end() , l-a[i] );
	ll size = a.end()-it;
	cnt += size;
	sum += size*a[i] + s[n]-s[n-size];
//	cout<<sum<<' '<<a[i]<<' '<<size<<' '<<s[n]-s[n-size]<<endl;
    }
   
  //  cout<<sum<<' '<<cnt<<endl;
    sum += (m-cnt)*l;

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
a=[]
for i in range(3):
  *x,=map(int,input().split())
  a+=x
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))
ans=[False for _ in range(9)]
for i in b:
    for j in a:
        if i==j:
            ans[a.index(i)]=True
if all(ans[0:3]) or all(ans[3:6]) or all(ans[6:9]):
    print("Yes")
elif all(ans[0:7:3]) or all(ans[1:8:3]) or all(ans[2:9:3]):
    print("Yes")
elif all(ans[0:5:4]) or all(ans[2:7:2]):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++) a[i] = sc.nextInt();
        for(int i = 0; i < n; i++) {
            if(i != 0) System.out.print(" ");
            System.out.print(a[n - i - 1]);
        }
        System.out.println();
    }
}



Measured memory_bytes: 26264
coin_500 = int(input())
coin_100 = int(input())
coin_50 = int(input())

target = int(input())

counter = 0


for i_500 in range(coin_500 + 1):
    # print('======= loop 500 =======')
    if i_500 * 500 > target:
        break

    for i_100 in range(coin_100 + 1):
        # print('-------- loop 100 ---------')
        if i_500 * 500 + i_100 * 100 > target:
            break

        for i_50 in range(coin_50 + 1):
            # print('........... loop 50 ..........')
            if i_500 * 500 + i_100 * 100 + i_50 * 50 == target:
                # print('match: ', i_500, i_100, i_50)
                counter += 1

print(counter)

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

/*==========type============*/
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::pair<std::string,ll> psl;

/*==========constant============*/
#define INF INT_MAX
#define INF_L LONG_MAX
#define INF_LL LLONG_MAX
#define MOD 1000000007

/*==========function============*/
#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;}

using namespace std;

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

    string s,t;
    cin >> s >> t;

    string tt = "";
    REP(i,0,t.size()-1)tt += t[i];


    string ans = s == tt ? "Yes" : "No";
    
    cout << ans << endl;

    return 0;
}    

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  cin >> n;

  vector<int> l(n);
  rep (i, 0, n)
    cin >> l[i];

  sort(l.begin(), l.end());

  int res = 0;
  rep (i, 0, n - 2) {
    rep (j, i + 1, n - 1) {
      int min_v = abs(l[i] - l[j]);
      int max_v = l[i] + l[j];
      auto it_s = upper_bound(l.begin() + j + 1, l.end(), min_v);
      auto it_e = lower_bound(l.begin() + j + 1, l.end(), max_v);
      res += distance(it_s, it_e);
    }
  }


  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n, i, c1, c2, s, t, x, y;
	c1 = 0;
	c2 = 0;
	scanf( "%d", &n );
	int a[n];
	int g[100];
	g[0] = 1;
	
	for( i = 0; i < n; i++ ){
		scanf( "%d", &a[i] );
	}
	
	for( c2 = 0; g[c2]*3+1 < n; c2++ ){
		g[c2+1] = g[c2] * 3 + 1;
	}
	
		for( s = c2; s >= 0; s-- ){
			for( t = g[s]; t < n; t++ ){
				x = a[t];
				y = t - g[s];
				while( y >= 0 && a[y] > x ){
					a[y+g[s]] = a[y];
					y = y - g[s];
					c1++;
				}
				a[y+g[s]] = x;
			}
		}
	
	printf( "%d\n", c2+1 );
	for( i = c2; i > 0; i-- ){
		printf( "%d ", g[i] );
	}
	printf( "%d\n%d\n", g[0], c1 );
	
	for( i = 0; i < n; i++ ){
		printf( "%d\n", a[i] );
	}
	
	return 0;
}


Measured memory_bytes: 5688
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    long long N;
    cin >> N;
    int digit=0;
    for(int i=(int)(sqrt(N)+1);i>0;i--){

        if(N%i==0){
            
            int B=N/i;
            
            while(B!=0){
                B=B/10;
                digit++;
            }
            break;
        }
    }
    cout << digit;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
using namespace std;
int main(){
    int list[26]={};
    char c;
    while(scanf("%c",&c)!=EOF){
        c=toupper(c);
        int x=c;
        if (x>=65 && x<=90){
            ++list[x-65];
        }
    }
    for (int i=0; i<=25; i++){
        printf("%c : %d\n",i+97,list[i]);
    }
    return 0;
}


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

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

    int h, w;
    cin >> h >> w;
    string C[h];
    for(int i = 0; i < h; i++){
        cin >> C[i];
    }

    for(int i = 0; i < h; i++){
        for(int k = 0; k < 2; k++){
            for(int j = 0; j < w; j++){
                cout << C[i][j];
            }
            cout << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] str = stdR.readLine().split(" ");
        int A = Integer.parseInt(str[0]);
        int B = Integer.parseInt(str[1]);
        int C = Integer.parseInt(str[2]);
        if(A == B && B == C) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,ans=0;
  cin >> n >>k;
  vector<int> A(n,1);
  for(int i=0;i<k;i++){
    int d;
    cin >> d;
    for(int m=0;m<d;m++){
      int a;
      cin >> a;
      A[a-1]=0;
    }
  }
  ans = accumulate(A.begin(),A.end(),0);

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  char c;
  cin >> c;
  vector<int> v = {'a','i', 'u', 'e', 'o'};
  int res = count(v.begin(), v.end(), c);
  if (res == 1) {
    cout << "vowel" << "\n";
  } else {
    cout << "consonant" << "\n";
  }
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(b<c||d<a) cout<<0<<endl;
    else if(c<a){
        if(b<d) cout<<b-a<<endl;
        else cout<<d-a<<endl;
    }
    else {
        if(d<b) cout<<d-c<<endl;
        else cout<<b-c<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
using namespace std;

const long long int INF = 1000000007;

int main(void)
{
    int N;
    long long K;
    cin >> N >> K;
    vector<int> go(N);
    vector<long long> c(N);
    for (int i = 0; i < N; i++)
    {
        cin >> go[i];
        go[i]--;
    }
    for (int i = 0; i < N; i++)
    {
        cin >> c[i];
    }

    // devide loop
    vector<int> group(N, -1);
    int num = 0;
    for (int start = 0; start < N; start++)
    {
        if (group[start] >= 0)
        {
            continue;
        }

        group[start] = num;
        int i = start;
        while (go[i] != start)
        {
            i = go[i];
            group[i] = num;
        }

        num++;
    }

    vector<int> one_loop(num, 0);
    for (int i = 0; i < N; i++)
    {
        one_loop[ group[i] ]++;
    }
    

    // each start point
    long long ans = -INF;

    for (int start = 0; start < N; start++)
    {
        int a_loop = one_loop[ group[start] ];

        // 1週分の得点
        long long sum = 0;
        int pos = start;
        for (int i = 0; i < a_loop; i++)
        {
            sum += c[go[pos]];
            pos = go[pos];
        }
        // printf("sum : %d\n", sum);
        
        // max point
        long long max_point = 0;
        // 1週以上できるなら
        if (K > a_loop)
        {
            if(sum > 1) max_point = (K / a_loop - 1) * sum;

            // start地点からK回以内で行ける最高ポイント
            long long p = -INF;
            long long now = 0;
            int w = start;
            for (int i = 0; i < K % a_loop + a_loop; i++)
            {
                now += c[go[w]];
                p = (p < now)? now : p;
                w = go[w];
            }
            
            max_point += p;
        }
        else
        {
            // start地点からK回以内で行ける最高ポイント
            long long p = -INF;
            long long now = 0;
            int w = start;
            for (int i = 0; i < K; i++)
            {
                now += c[go[w]];
                p = (p < now)? now : p;
                w = go[w];
            }
            
            max_point += p;
        }

        ans = (ans < max_point)? max_point : ans;

        // printf("%d : %d\n", start, max_point);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+ 5;

typedef pair<int, int> ii;
map<int, int> a[2];
vector<ii> store[2];
int n;

bool cmp(ii ff, ii ss){
	return ff.second < ss.second;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; i++){
		int k;
		cin >> k;
		a[i & 1][k]++;
	}
	for (int u = 0; u < 2; u++){
		for (auto it: a[u]){
			store[u].push_back(ii(it.first, it.second));
		}
	}
	sort(store[0].begin(), store[0].end(), cmp);
	sort(store[1].begin(), store[1].end(), cmp);

	int n1 = store[0].size();
	int n2 = store[1].size();

	int ans = 0;
	if (store[0][n1-1].first == store[1][n2-1].first){
		if (store[0][n1-1].second == n/2){
			if (store[1][n2-1].second == n/2)
				ans = n/2;
			else 
				ans = n/2-store[1][n2-2].second; 
		} else if (store[1][n2-1].second == n/2){
			ans = n/2-store[0][n1-2].second;
		} else {
            ans = n - max(store[0][n1-1].second + store[1][n2-2].second, store[1][n2-1].second + store[0][n1-2].second);
		}
	} else {
		ans = n - store[0][n1-1].second - store[1][n2-1].second;
	}

	cout << ans << endl;
}

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

using namespace std;

int main() {
		vector<int> x(5);
		for(int i = 0; i < 5; ++i) {
				cin >> x[i];
		}
		for(int i = 0; i < 5; ++i) {
				if(x[i] == 0) {
						cout << i + 1 << '\n';
				}
		}
		return 0;
}

Measured memory_bytes: 3620
MOD = 10 ** 9 + 7

K = int(input())
S = input()
l = len(S)

fac = [1] * (K + l + 1)
for i in range(1, K + l + 1):
	fac[i] = (fac[i - 1] * i) % MOD

p25 = [1] * (K + 1)
p26 = [1] * (K + 1)
for i in range(1, K + 1):
	p25[i] = (p25[i - 1] * 25) % MOD
	p26[i] = (p26[i - 1] * 26) % MOD

ans = 0
for en in range(l - 1, l + K):
	t = (fac[en] * pow(fac[en - l + 1], MOD - 2, MOD) * pow(fac[l - 1], MOD - 2, MOD)) % MOD
	t = (t * p25[en - l + 1]) % MOD
	t = (t * p26[l + K - 1 - en]) % MOD
	ans = (ans + t) % MOD
print(ans)

Measured memory_bytes: 123020
while True:
    x = input()
    list = x.split()
    [a, op, b] = list
    a = int(a)
    b = int(b)

    if op == "?":
        break
    elif op == "+":
        ans = a + b
    elif op == "-":
        ans = a - b
    elif op == "*":
        ans = a * b
    elif op == "/":
        ans = a // b
    
    print(ans)
    continue


Measured memory_bytes: 5592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);



int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;
    string ans;
    vector<int> a;
    while (n>0) {
        --n;
        ans.push_back('a'+n%26);
        n/=26;
    }
    
    rep(i,a.size()) cout << a[i] << endl;
    reverse(ans.begin(),ans.end());
    cout << ans << endl;


    return 0;   
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend();
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
	makei(N);
	rep(N) {
		char s;
		cin >> s;
		if (s == 'Y') {
			say("Four");
			re;
		}
	}
	say("Three");
}

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

int main(){
    int n, k;
    cin >> n;
    int number[n];
    for(int i=0;i<n;i++){
        cin >> k;
        number[i] =k;
    }
    for(int i =n-1;i>=0;i--){
        if(i!=n-1){cout << " ";}
        cout << number[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3080
n = int(input())
end = int(n**(0.5))+1
ans = len(str(n))

def F(a, b):
    return max(len(str(a)), len(str(b)))
    
for i in range(1, end):
    if n % i == 0:
        ans = min(ans, F(n//i, i))
print(ans)

Measured memory_bytes: 9428
using System;
using System.Collections.Generic;
using static Exter;
using System.Linq;
#if DEBUG
#else
using console = System.Console;
#endif

public class App
{
    public static void Main(string[] args)
    {
        var k = readarr[1];
        var e = console.ReadLine().Select(c=>c=='1');
        e=new bool[]{!e.First()}.Concat(e);
        var tmp = 1;
        var f = e.Zip(e.Skip(1),(a,b)=>new{v=b,b=(a!=b)}).Select(v=>new{v.v,cond=(v.b?tmp=1:++tmp)}).ToList();
        f.Add(new {v=!f.Last().v,cond=0});
        var g = f.Zip(f.Skip(1),(a,b)=>new{v=a.v,b=(a.v!=b.v),cond=a.cond}).Where(v=>v.b).Select(v=>new{v.cond,v.v}).ToList();
        if(g.First().v==false)
        g.Insert(0,new {cond=0,v=true});
        if(g.Last().v==false)
        g.Add(new {cond=0,v=true});
        var h = g.Select(v=>v.cond).ToArray();
        //cout = string.Join(",",h);
        if(h.Length/2<=k)
            cout = h.Sum().ToString();
        else
        {
            int max = 0;
            for(int i = 0;i<=h.Length-k*2;i+=2)
            {
                int aggregate = 0;
                for(int j = i;j<=i+k*2;j++)
                {
                    aggregate += h[j];
                }
                if(aggregate>max)
                    max = aggregate;
            }
            cout = max.ToString();
        }
    }
}
public static class Exter
{
    public static int Max(params int[] p)=>p.Max();
    public static long Max(params long[] p)=>p.Max();
    public static int Min(params int[] p)=>p.Min();
    public static long Min(params long[] p)=>p.Min();
    public static string cout
    {
        set
        {
            console.Write(value);
            console.WriteLine();
            
        }
    }
    public static int[] readarr
    {
        get 
        {
            return console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
        }
    }
}


#if DEBUG
public static class console
{
    static int cursorLine = 0;
    static readonly string[] cin = new string[]
    {
                "14 1",
                "11111"
    };
    static public string ReadLine()
    { 
        return cin[cursorLine++];
    }
    static public void WriteLine()
    {
        Console.WriteLine();
    }
    static public void WriteLine<T>(T input)
    {
        Console.WriteLine(input);
    }
    static public void Write<T>(T input)
    {
        Console.Write(input);
    }
    static public void WriteLine(string s,params object[] arr)
    {
        Console.WriteLine(s,arr);
    }
}
#endif

Measured memory_bytes: 29272
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;

int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int xt,yt,at;
  int xm,ym,xM,yM;
  xm=0;
  ym=0;
  xM=w;
  yM=h;
  
  
  rep(i,n){
    cin>>xt>>yt>>at;
    if(at==1)xm=max(xt,xm);
    if(at==3)ym=max(yt,ym);
    if(at==2)xM=min(xt,xM);
    if(at==4)yM=min(yt,yM);
  }
  //cout<<xM<<endl;
  //cout<<xm<<endl;
  //cout<<yM<<endl;
  //cout<<ym<<endl;
  
  if(xM-xm<=0)cout<<0<<endl;
  else if(yM-ym<=0)cout<<0<<endl;
  else cout<<(xM-xm)*(yM-ym)<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int FindGcd(int x, int y) {
  if (y > x) {
    int swap = x;
    x = y;
    y = swap;
  }

  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }

  return x;
}

int main() {
  int x, y;
  cin >> x >> y;
  int ans = FindGcd(x, y);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3084
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var dict= new Dictionary<int, int>();
        Console.ReadLine();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var m = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            var z = int.Parse(line[2]);
            int yv;   int zv;
            if (dict.ContainsKey(y)) yv = dict[y];
            else { yv = getNum(a, d, y);  dict[y] = yv; }
            if (dict.ContainsKey(z)) zv = dict[z];
            else { zv = getNum(a, d, z); dict[z] = zv; }
            if (x == 0) { dict[y] = zv; dict[z] = yv; }
            else dict[y] = zv;
        }
        var k = int.Parse(Console.ReadLine().Trim());
        Console.WriteLine(dict.ContainsKey(k) ? dict[k] : getNum(a,d,k));
    }
    public static int getNum(int a, int d, int n)
    {
        return a + (n - 1) * d;
    }
}


Measured memory_bytes: 9724
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			String str = stdIn.next();
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < str.length(); ++i)
			{
				if(str.charAt(i) == 'M')
				{
					list.add(1000);
				}
				else if(str.charAt(i) == 'D')
				{
					list.add(500);
				}
				else if(str.charAt(i) == 'C')
				{
					list.add(100);
				}
				else if(str.charAt(i) == 'L')
				{
					list.add(50);
				}
				else if(str.charAt(i) == 'X')
				{
					list.add(10);
				}
				else if(str.charAt(i) == 'V')
				{
					list.add(5);
				}
				else if(str.charAt(i) == 'I')
				{
					list.add(1);
				}
			}
			int sum = 0;
			boolean flag = false;
			for(int i = 0; i < list.size() - 1; ++i)
			{
				flag = false;
				if(list.get(i) < list.get(i + 1))
				{
					sum += list.get(i + 1) - list.get(i);
					++i;
					flag = true;
				}
				else
				{
					sum += list.get(i);
				}
			}
			if(!flag)
			{
				sum += list.get(list.size() - 1);
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
#include<cstdio>

int a, b;

int f(int x, int y) {
    if (y % x == 0) return x;
    return f(y % x, x);
}

int main() {
    scanf("%d %d", &a, &b);
    int l = (a < b) ? f(a, b) : f(b, a);
    printf("%ld\n", static_cast<long>(a) * b / l);
    return 0;
}


Measured memory_bytes: 128
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A[1001],B[1001];
int N,M;
int main() {
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	for(int i=0;i<M;i++){
		cin>>B[i];
	}
	int T[1001]={};
	int S;
	for(int j=0;j<M;j++){
		S=0;
		for(int i=0;i<N;i++){
			if(A[i]<=B[j] && S==0){
				S=1;
				T[i]+=1;
			}
		}
	}
	int ans=0;
	int C=0;
	for(int i=0;i<N;i++){
		if(C<T[i]){
			C=T[i];
			ans=i;
		}
	}

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

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


int main(){
	int n, a, b, tmp, res = 0;
	cin >> n >> a >> b;

	for(int i = 1; i < n + 1; i++){
	    tmp = i;
	    int dsum = 0;
	    while(tmp > 0){
            dsum += tmp%10;
            tmp /= 10;
	    }
	    if(a <= dsum && dsum <= b) res += i;
	}
	cout << res << "\n";
}


Measured memory_bytes: 256