akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int[][] score = new int[10][10];
    int[][] input = new int[h][w];
    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<10; i++) {
            for (int j=0; j<10; j++) {
                score[i][j] = sc.nextInt();
            }
        }

        floyd();

        Map<Integer, Integer> map = new HashMap<>();

        long ans = 0;

        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                int tmp = sc.nextInt();
                if (tmp>=0) ans += score[tmp][1];
//                if (map.containsKey(tmp)) {
//                    int val = map.get(tmp);
//                    map.put(tmp, val+1);
//                } else {
//                    map.put(tmp, 1);
//                }
            }
        }

//        System.out.println(map);

//        for (Integer k: map.keySet()) {
//            if (k==-1 || k==0) continue;
//            int val = map.get(k);
//            ans += score[k][1] * val;
//        }


//        for (int i=0; i<10; i++) {
//            for (int j=0; j<9; j++) {
//                System.out.print(score[i][j]+" ");
//            }
//            System.out.println(score[i][9]);
//        }

        System.out.println(ans);

    }

    void floyd() {
        for (int k=0; k<10; k++) {
            start:
            for (int i=0; i<10; i++) {
                if (score[i][k]==0) continue start;
                end:
                for (int j=0; j<10; j++) {
                    if (score[k][j]==0) continue end;
                    if (i==8 && k==4 && j==9) {
//                        System.out.println(score[i][j]);
//                        System.out.println(score[i][k]);
//                        System.out.println(score[k][j]);
                    }

                    if (score[i][j] > score[i][k]+score[k][j]) {
                        score[i][j] = score[i][k] + score[k][j];
                    }
                }
            }
        }
    }

}


Measured memory_bytes: 47104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int main()
{
	int N;
	int coin[7]={500,100,50,10,5,1};

	while(1)
	{
		int count=0;
		int j=0;

		s_1(N);
		if(N==0)break;
		int max_c=1000-N;
		
		while(max_c>0)
		{
			rep_to(j,i,6)
			{
				if(coin[i]<=max_c)
				{
					max_c-=coin[i];
					count++;
					break;
				}
				else j++;
			}
		}
		cout<<count<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int N; cin >> N;
	vector<int> x(N);
	int MIN = inf, MAX = 0;
	rep(i, N) {
		cin >> x[i];
		MIN = min(MIN, x[i]);
		MAX = max(MAX, x[i]);
	}

	ll ans = inf;

	for (int i = MIN; i <= MAX; i++) {
		ll sum = 0;
		rep(j, N) sum += (x[j] - i) * (x[j] - i);
		ans = min(ans, sum);
	}

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


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


int main(){
   int a;
   cin>>a;
   vector<int> vec(a);
   rep(i,a){
       cin>>vec.at(i);
   }
   int sum=0;
   bool flag=true;
   while(flag){
       flag=false;
       for(int j=a-1;j>0;j--){
           if(vec.at(j)<vec.at(j-1)){
               int san=vec.at(j);
               vec.at(j)=vec.at(j-1);
               vec.at(j-1)=san;
               flag=true;
               sum++;
           }
       }
   }
   rep(i,a){
       if(i!=a-1){
        cout<<vec.at(i)<<" ";
       }
       else{
           cout<<vec.at(i)<<endl;
       }
   }
   cout<<sum<<endl;
}






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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class ADontBeLate {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int d,t,s;
        cin>>d>>t>>s;
        if (((d/s)<t)||(d%s==0&&d/s==t))
            cout<<"Yes";
        else cout<<"No";
	}
};


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


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
    
  
  return 0;
}


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

int main()
{
  int c[10];
  string str;
  int n;
  int ba;

  while (cin >> n){
    if (n == 0) break;
    for (int i = 0; i < 10; i++){
      c[i] = 0;
    }
    cin >> str;
    int p = 0;
    ba = 0;
    for (int i = 0; i < 100; i++){
      if (str[i] == 'M'){
        c[p]++;
      }
      if (str[i] == 'S'){
        ba += c[p];
        ba++;
        c[p] = 0;
      }
      if (str[i] == 'L'){
        c[p] += ba;
        c[p]++;
        ba = 0;
      }
      p++;
      if (p >= n){
        p = 0;
      }
    }
    sort(c, c + n);
    
    for (int i = 0; i < n; i++){
      cout << c[i] << " ";
    }
    cout << ba << endl;
  }

  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
    ll h,w,k;
    cin>>h>>w>>k;

    string s[h];

        for(int j=0;j<h;j++)
        {
            cin>>s[j];
        }
        int count=0,ans=0;
    for(int mask=0;mask<(1<<(h+w));mask++)
    {
        count=0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(s[i][j]!='#')continue;
                if(mask&(1<<i)||mask&(1<<(h+j)))continue;
                count++;
            }
        }
        if(count==k)ans++;
    }
    cout<<ans<<endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int N; cin >> N;

    int v[100], c[100];
    int ans = 0;

    for (int i = 0;i < N;i++){
        cin >> v[i];
    }
    for (int i = 0;i < N;i++){
        cin >> c[i];
        if(v[i] > c[i]) ans += v[i]-c[i];
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
// Problem : B - ∵∴∵
// Contest : AtCoder - AtCoder Beginner Contest 058
// URL : https://atcoder.jp/contests/abc058/tasks/abc058_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
string o,e;cin>>o>>e;
string ans;
int ptr1=0,ptr2=0;
while(ptr1<size(o) or ptr2<size(e))
{
	if(size(ans)&1)
	ans+=e[ptr2++];
	else
	ans+=o[ptr1++];
}
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,C,S;
    scanf("%d %d %d",&A,&B,&C);
    S=A+B+C;
    if(S>=22)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }
    return 0;
}



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

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

    vector<bool> occured(26);
    for (int i = 0; i < (int)S.size(); i++)
    {
        int c = S.at(i) - 'a';
        if (occured.at(c))
        {
            cout << "no" << endl;
            return 0;
        }
        occured.at(c) = true;
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n,k,q,a;
    cin>>n>>k>>q;
    vector<int> ans(n);
    rep(i,n) ans[i]=k-q;
    rep(i,q){
        cin>>a;
        ans[a-1]++;
    }
    rep(i,n){
        cout<<(ans[i]>0? "Yes": "No")<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  string S,T;
  cin>>S;
  cin>>T;
  int count=0;
  int n=S.length();
  for(int i=0;i<n;i++){
    if(S[i]!=T[i])
    {
      int temp=S[i];
      S[i]=T[i];
      T[i]=temp;
      count++;
    }
  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 3752
//OM
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define  x first
#define  y second
#define  pb push_back
#define  mp make_pair
#define  PI (acos(-1.0))
#define  mem(a,b) memset(a,b,sizeof(a))
#define  Sort(x) sort(x.begin(),x.end())
#define  FOR(i, b, e) for(int i = b; i <= (int)(e); i++)
#define  FORR(i, b, e) for(int i = b; i >=(int)(e); i--)
#define  FORI(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define  pr(x) cout<<x<<"\n"
#define  prs(x) cout<<x<<" "
#define  pr2(x,y) cout<<x<<" "<<y<<"\n"
#define  pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define  ppr(a) cout<<a.x<<" "<<a.y<<"\n"

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  vector <int> vi;
typedef  vector <pii> vpii;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction

#define  EPS 1e-9
#define  MAX 100007
int a[MAX];
int main()
{
    int T,n;
    scanf("%d",&n);
    FOR(i,1,n)
    {
        scanf("%d",&a[i]);
    }
    ll mx=1000000000000000000;
    FOR(c,-100,100)
    {
        ll sum=0;
        FOR(i,1,n)
        {
            sum+=abs(c-a[i])*abs(c-a[i]);
        }
        mx=min(mx,sum);
    }
    pr(mx);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int MAX=3000;
const ll limit=1e13;
int n;
ll dp[MAX][MAX][2];
vector<int> a(MAX);
ll calc(int start,int end,int turn){
    if(start>end){
        return 0;
    }
    if(dp[start][end][turn]!=limit){
        return dp[start][end][turn];
    }
    ll ans;
    if(start==end){
        ans=a[start]-calc(start+1,end,1-turn);
    }
    else{
        ans=max(a[start]-calc(start+1,end,1-turn),a[end]-calc(start,end-1,1-turn));
    }
    return dp[start][end][turn]=ans;
}
void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<n;j++){
            dp[i][j][0]=limit,dp[i][j][1]=limit;
        }
    }
    ll result=calc(0,n-1,1);
    cout<<result<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
#define ull unsigned long long int
#define sull static unsigned long long int
using namespace std;
int main(){
	int N, T;
	int i;
	int cost=114514;
	bool f;
	int a[1000];
	int b[1000];
	int c[1000];
	int d[1000];
	cin >> N>>T;
	for(i=0;i<N;i++){
		cin >> a[i];
		cin >> b[i];
	}
	for(i = 0; i < N; i++) {
		if (b[i] > T);
		else cost = min(cost, a[i]);
	}
	if (cost == 114514)cout << "TLE" << endl;
	else cout << cost << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        long t=0;
        long sum=0;
        while (t<s.length()){
            int num=Integer.parseInt(String.valueOf(s.charAt((int) t)));
            sum=sum+num;
            t++;
        }
        if (sum%9==0){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 50492
n = input()
n_l = list(n)
a = [str(i % 2) for i in range(0, len(n))]
b = [str(i % 2) for i in range(1, len(n) + 1)]

count_a = 0
for i in range(len(n)):
    if n_l[i] != a[i]:
        count_a += 1

count_b = 0
for i in range(len(n)):
    if n_l[i] != b[i]:
        count_b += 1

print(min(count_a, count_b))

Measured memory_bytes: 16628
program problemA
  implicit none

integer :: K,A,B
integer :: n, m, yr,judge
character(len=4) :: S


read(*,*) S

if (S=='ABC') then
  write(*,*) 'ARC'
else
  write(*,*) 'ABC'
end if
! if (K==1) then
!   write(*,*) 'OK'
! else
!   if (A==B) then
!     if (mod(A,K)==0) then
!       write(*,*) 'OK'
!     else
!       write(*,*) 'NG'
!     end if
!   else
!     if (int(A/K)==int(B/K)) then
!       write(*,*) 'NG'
!     else
!       write(*,*) 'OK'
!     end if
!   end if
! end if



stop
end program


Measured memory_bytes: 2856
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double db;

#define ft first
#define sd second
#define flag bool fl=true

#define mod 1000000007
#define N 100001
#define MX 1000000001
#define MXX 1000000000000000001

#define pb push_back
#define For(i, a, b) for(int i=a;i<=b;i++)
#define T int t, qq=0; cin>>t; while(qq++<t)
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define scarr(array, size) for(int i=0;i<size;i++) cin>>array[i]

#define deg(rad) (rad*180.0)/pi
#define pi acos(-1)
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)


/*
//----------useful_functions----------

long long extended_euclid(ll a, ll b, ll &x, ll &y){//ax+by=c
    if(b==0)
    {
        x=1, y=0;
        return a;
    }

    ll x1, y1;
    ll d=extended_euclid(b, a%b, x1, y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
long long bigMod(ll a, ll b){//(a^b)%mod
    ll ans=1;
    while(b)
    {
        if(b%2==1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
long long modInverse(ll a, ll b){//a*x=1 mod b
    ll x, y;
    ll gcd=extended_euclid(a, b, x, y);

    if(gcd==1) return ((x%b)+b)%b;
    else return 1;
}
long long nCr(ll n, ll r){//n<=1e6
    //declare globally-> ll fact[1000001];
    fact[1]=1;
    for(ll i=2;i<1000001;i++)
        fact[i]=(i*fact[i-1])%mod;

    return (fact[n]*modInverse(fact[r], mod)*modInverse(fact[n-r], mod))%mod;
}
long long josephus(ll n, ll k){//k'th person is killed out of n in the circle
    if(n==1) return 1;
    else return (josephus(n-1, k)+k-1)%n+1;
}

vector<int> sieve(ll n){
    bool fl[n+1];
    vector<int> primes;
    for(int i=0;i<=n;i++) fl[i]=false;

    for(int i=3;i*i<=n;i+=2)
        for(int j=i+i;j<=n;j+=i)
            fl[j]=true;

    primes.pb(2);
    for(int i=3;i<=n;i+=2) if(!fl[i]) primes.pb(i);
    return primes;
}
*/

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

    ll a[n-1];
    for(int i=0;i<n-1;i++) cin>>a[i];

    ll sum=a[0];
    for(int i=1;i<n-1;i++) sum+=min(a[i-1], a[i]);
    sum+=a[n-2];

    cout<<sum<<endl;
//        cout<<"Case "<<qq<<": ";
}


Measured memory_bytes: 3560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        sc.close();
        if (X < A) {
            System.out.println(0);
        } else {
            System.out.println(10);
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
int dp[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	rep(i, 0, N) {
		chmax(dp[i + 1], dp[i]);
		if (i + 1 < N and S[i] != S[i + 1]) chmax(dp[i + 2], dp[i] + 1);
	}
	cout << dp[N] << endl;
}



Measured memory_bytes: 3732
N, A, B, C, D = list(map(int, input().split()))
M = N - 1
n = abs(A - B)
m = abs(C - D)

def prin(tf):
  if tf:
    print("YES")
  else:
    print("NO")
  exit()

if n > D * M:
  prin(False)

GC = n
GD = n
if M % 2 == 1:
  M -= 1
  GC = abs(n - C)
  GD = abs(n - D)
t = GC // (2 * C)
k = M // 2 - t
a = t * 2 * C
b = t * 2 * D + k * m

if b >= GD:
  prin(True)

if GD % (2 * D) == 0:
  prin(True)

t = GD // (2 * D) + 1
k = M // 2 - t
a = t * 2 * C - k * m
b = t * 2 * D


if a <= GC:
  prin(True)

prin(False)

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

#define pb push_back
     
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,a,b;
	cin>>n>>a>>b;
	ll sum=a*(n/(a+b));
	sum+=min((n%(a+b)),a);
	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10**9
for i in range(n-k+1):
  d = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))
  ans = min(ans, d)
  
print(ans)


Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


template<typename T>
void dump(T *arr, int h, int w){
	rep(i,h){
		rep(j,w) cout << arr[i][j] << "\t";
		cout << "\n";
	}
}

template<typename T>
void dump(T *arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

template<typename T>
void dump(vector<T> arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

const int INF = 1e9;
const int MOD = 1e9+7;

bool compare(P a, P b){
	if(a.second != b.second) return a.second > b.second;
	else	return a.first > b.first;
}

int digits(ll num){
	ll d=0;
	while(num >= 1){
		num/= 10;
		d++;
	}
	return d;
}

ll pow_kai(ll a, int n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> num_node; //そのノードの所属するグループのノード数

    UnionFind(int N) : par(N), num_node(N){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
			par[i] = i;
			num_node[i] = 1;
		}
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		num_node[ry] += num_node[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

	int nodes(int x) {
		return num_node[root(x)];
	}
};

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

	int a[3][3];
	rep(i, 3) rep(j,3) cin >> a[i][j];

	int n;
	cin >> n;

	int b;
	bool check[3][3] = {};
	rep(i, n) {
		cin >> b;
		rep(i, 3) rep(j,3) {
			if(a[i][j] == b) {
				check[i][j] = true;
				break;
			}
		}
	}
	bool bingo=false;
	rep(i,3){
		if(check[i][0] && check[i][1] && check[i][2]){
			bingo=true;
			break;
		}
		if(check[0][i] && check[1][i] && check[2][i]){
			bingo=true;
			break;
		}
	}
	if((check[0][0] && check[1][1] && check[2][2]) || (check[0][2] && check[1][1] && check[2][0])){
		bingo=true;
	}
	if(bingo) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.array;//split
import std.conv;//to
import std.string;//chomp
import std.bigint;

void main(){
    string[] input = split(readln());
    int n= to!int(input[0]);
    while(n--){
        BigInt a = BigInt(chomp(readln()));
        BigInt b = BigInt(chomp(readln()));
        BigInt c = a+b;
        if(c<BigInt("100000000000000000000000000000000000000000000000000000000000000000000000000000000"))
            writeln(c);
        else writeln("overflow");
    }
}

Measured memory_bytes: 1060
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, m;
int y[1501];
int x[1501];
int cnt_h[1500001];
int cnt_w[1500001];

signed main() {
	while (cin >> n >> m) {
		if (!n) break;
		int i, j;
		
		for (i = 0; i < n; i++) cin >> y[i + 1];
		for (i = 0; i < m; i++) cin >> x[i + 1];
		for (i = 0; i < n; i++) y[i + 1] += y[i];
		for (i = 0; i < m; i++) x[i + 1] += x[i];
		
		for (i = 0; i <= n * 1000; i++) cnt_h[i] = 0;
		for (i = 0; i <= m * 1000; i++) cnt_w[i] = 0;
		for (i = 0; i <= n; i++) for (j = i + 1; j <= n; j++) cnt_h[y[j] - y[i]]++;
		for (i = 0; i <= m; i++) for (j = i + 1; j <= m; j++) cnt_w[x[j] - x[i]]++;
		int ans = 0;
		for (i = 0; i <= min(n, m) * 1000; i++) { ans += cnt_h[i] * cnt_w[i]; }
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 26520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int h, a; cin >> h >> a;
    int i=0;
    bool conti = true;
    while(conti){
        h -= a;
        i += 1;
        if(h <= 0){
            conti = false;
        }
    }
    cout << i << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int num;
  struct Node *left;
  struct Node *right;
  struct Node *parent;
  struct Node *next;
};

struct Node *root,*NIL;

struct Node *makeNode(void);
void initialize(struct Node*);
void insert(int);
void inParse(struct Node*);
void preParse(struct Node*);


int main(){
  int n;
  int i=0,j,number;
  char order[10];

  scanf("%d",&n);


  for(i=0;i<n;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
      scanf("%d",&number);
      insert(number);
    }
    if(strcmp(order,"print")==0){
      inParse(root);
      printf("\n");
      preParse(root);
      printf("\n");
    }
  }

  return 0;
}


struct Node *makeNode(void){	
  return  (struct Node*)malloc(sizeof(struct Node));
}  

  
void insert(int key){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  
  z=makeNode();

  z->num=key;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->num < x->num){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->num < y->num){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }

}
  
void inParse(struct Node *p){
  if(p==NIL) return;
  
  inParse(p->left);
  printf(" %d",p->num);
  inParse(p->right);
}

void preParse(struct Node *p){
  if(p==NIL) return;

  printf(" %d",p->num);
  preParse(p->left);
  preParse(p->right);
}

Measured memory_bytes: 24040
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val A = sc.nextInt
  val B = sc.nextInt

  var a = A - 1
  var b = B - 1
  // どんなA, Bがきても、100 x 100 のマスを考える
  println("100 100")

  // 上半分の100 x 50は白 = .
  for(h <- 1 to 50) {
    if (h % 2 == 0 | b == 0) {
      println("." * 100)
    } else {
      for(w <- 1 to 100) {
        if (w % 2 == 1 && b > 0) {
          print("#")
          b -= 1
        } else {
          print(".")
        }
      }
      println()
    }
  }
  println("#" * 100)
  // 下半分の100 x 50は黒 = #
  for(h <- 1 to 49) {
    if (h % 2 == 0 | a == 0) {
      println("#" * 100)
    } else {
      for(w <- 1 to 100) {
        if (w % 2 == 1 && a > 0) {
          print(".")
          a -= 1
        } else {
          print("#")
        }
      }
      println()
    }
  }
 }

Measured memory_bytes: 27332
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        ts = s[i:i + len(t)]
        b = True
        for j in range(len(t)):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                s[i + j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  uli a, b, c, h, k, n, w, x, ans = 0, count = 0;
  cin >> a >> b >> n;
  // vector<unsigned lli> f(n + 1);
  // for (unsigned lli i = 0; i <= n; i++)
  // {
  //   unsigned lli e = i / b;
  //   unsigned lli d = (a * i) / b;
  //   if (e <= 0)
  //   {
  //     f[i] = d;
  //   }
  //   else
  //   {
  //     x = d - a * e;
  //     f[i] = x;
  //   }
  // }
  // cout << f << endl;
  // cout << MAX(f) << endl;
  if (n >= b)
  {
    x = b - 1;
  }
  else
  {
    x = n;
  }
  unsigned lli e = x / b;
  unsigned lli d = (a * x) / b;
  x = d - a * e;
  cout << x << endl;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

bool Solve(const std::string s) {
  std::string reverse;
  for (int i = s.size() - 1; i >= 0; i--) {
    reverse += s[i];
  }
  int pos = 0;
  while (pos < s.size()) {
    std::string add;
    bool missed = false;
    add         = "maerd";
    for (int i = 0; i < add.size(); i++) {
      if (pos + i >= reverse.size() || reverse[pos + i] != add[i]) {
        missed = true;
        break;
      }
    }
    if (!missed) {
      pos += add.size();
      continue;
    }
    missed = false;
    add    = "resare";
    for (int i = 0; i < add.size(); i++) {
      if (pos + i >= reverse.size() || reverse[pos + i] != add[i]) {
        missed = true;
        break;
      }
    }
    if (!missed) {
      pos += add.size();
      continue;
    }
    missed = false;
    add    = "remaerd";
    for (int i = 0; i < add.size(); i++) {
      if (pos + i >= reverse.size() || reverse[pos + i] != add[i]) {
        missed = true;
        break;
      }
    }
    if (!missed) {
      pos += add.size();
      continue;
    }
    missed = false;
    add    = "esare";
    for (int i = 0; i < add.size(); i++) {
      if (pos + i >= reverse.size() || reverse[pos + i] != add[i]) {
        missed = true;
        break;
      }
    }
    if (!missed) {
      pos += add.size();
      continue;
    }
    return false;
  }
  return true;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string s;
  cin >> s;
  cout << (Solve(s) ? "YES" : "NO") << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

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

  int D,G;
  cin>>D>>G;
  V p(D),c(D);
  rep(i,D)cin>>p[i]>>c[i];

  int ans=INF;
  for(int bit=0;bit<(1<<D);++bit){
    int psum=0,solved=0,unuse_max=-1;
    rep(i,D){
      if((bit>>i)&1){
        psum+=100*(i+1)*p[i]+c[i];
        solved+=p[i];
      }
      else unuse_max=i;
    }
    if(psum<G){
      int solve=100*(unuse_max+1);
      int need=(G-psum)/solve+((G-psum)/solve==0);
      if(need>=p[unuse_max])continue;
      solved+=need;
    }
    chmin(ans,solved);
  }
  out(ans);
  
  
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 100005
#define END -1

typedef struct {
  int parent;
  int next;
  int rig;
  
}Node;
  
Node tree[MAX];
int s_dep(int,int);
int main(void){

  int i,t,n,id,deg,cha,fr;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    tree[i].parent=END;
    tree[i].next=END;
    tree[i].rig=END;

  }

  //input the tree
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&deg);
    for(t=0;t<deg;t++){
      scanf("%d",&cha);
      if(t==0){
        tree[cha].parent=id;
        tree[id].next = cha;
        fr = cha;
      }
      else {
        tree[fr].rig = cha;
        tree[cha].parent = id;
        fr = cha;
      }
    }    
  }
  //output the tree
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",tree[i].parent);
    printf("depth = %d, ",s_dep(i,0));
    if(tree[i].parent==END) printf("root, [");
    else if(tree[i].next != END) printf("internal node, [");
    else {
      printf("leaf, []\n");
      continue;
    }
    if(tree[i].next !=END){
      printf("%d",tree[i].next);
      cha =  tree[i].next;
    }
    else cha = i;
    while(1){
      if(tree[cha].rig !=END){
        printf(", %d",tree[cha].rig);
        cha = tree[cha].rig;
      }
      else break;
      
    }
    printf("]\n");
    
    
  }
  
  return 0;
}


int s_dep(int id,int c){
  int i;
  int de = 0;

  if(tree[id].parent!=-1){
    de = s_dep(tree[id].parent,c);
    return de+1;
  }
  else return c;

}

Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    ll n;
    cin >> n;
    ll result = 0;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i != 0) {
            continue;
        }
        for (ll j = i; j <= n; j *= i) {
            if (n % j != 0) {
                break;
            }
            if ((n / j) % i == 1) {
                ++result;
                break;
            }
        }
        ll ii = n / i;
        if (ii == i) {
            continue;
        }
        for (ll j = ii; j <= n; j *= ii) {
            if (n % j != 0) {
                break;
            }
            if ((n / j) % ii == 1) {
                ++result;
                break;
            }
        }
    }
    ++result;

    for (ll i = 2; i * i <= n - 1; ++i) {
        if ((n - 1) % i != 0) {
            continue;
        }
        ++result;
        ll ii = (n - 1) / i;
        if (ii == i) {
            continue;
        }
        ++result;
    }
    if (n > 2) {
        ++result;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	if (a > b)
	{
		swap(a, b);
	}

	for (auto i = 0; i < b; ++i)
	{
		cout << a;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define maxn 2000010
int a[maxn];
bool col[maxn][7], vis[maxn][7];
typedef long long ll;
struct que {
	int x, y;
} qu[maxn];
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int up[maxn], dw[maxn], Fa[maxn], fcol[maxn][7];
int Find(int x) {return Fa[x] == x ? x : Fa[x] = Find(Fa[x]);}
int main()
{
	ll n;
	int m, q; scanf("%lld%d%d", &n, &m, &q);
	for (int i = 1; i <= q; ++i) scanf("%d", &a[i]);
	if (m % 7)
	{
		int nq = q;
		for (int i = 1; i <= q; ++i)
			for (int j = 1; j < 7; ++j)
				a[++nq] = a[i] + j * m;
		m *= 7; q = nq;
	}
	int mm = m / 7, cnt = 0;

	for (int i = 1; i <= q; ++i)
	{
		col[a[i] / 7][a[i] % 7] = 1;
//		printf("%d %d\n", a[i] / 7, a[i] % 7);
	}

	for (int i = 0; i < mm; ++i)
		for (int j = 0; j < 7; ++j)
			if (!vis[i][j] && !col[i][j])
			{
				fcol[i][j] = ++cnt;
				int head = 0, tail = 1; qu[1] = (que) {i, j}; vis[i][j] = 1;
				while (head < tail)
				{
					que now = qu[++head];
					for (int k = 0, nx, ny; k < 4; ++k)
					{
						nx = now.x + dx[k]; ny = now.y + dy[k];
						if (nx >= 0 && nx < mm && ny >= 0 && ny < 7 && !vis[nx][ny] && !col[nx][ny])
						{
							qu[++tail] = (que) {nx, ny};
							fcol[nx][ny] = cnt;
							vis[nx][ny] = 1;
						}
					}
				}
			}
//	printf("%d\n", cnt);
	int cnt2 = 0;
	for (int i = 0; i < 7; ++i) up[i] = fcol[0][i];
	for (int i = 0; i < 7; ++i) !col[mm - 1][i] ? dw[i] = fcol[mm - 1][i] + cnt : 0;
	for (int i = 1; i <= cnt * 2; ++i) Fa[i] = i;

//	for (int i = 0; i < 7; ++i) printf("%d %d\n", up[i], dw[i]);
	for (int i = 0; i < 7; ++i)
	{
//		printf("%d %d\n", up[i], dw[i]);
		if (up[i] && dw[i] && Find(up[i]) != Find(dw[i]))
		{
			Fa[Find(up[i])] = Find(dw[i]);
			++cnt2;
		}
	}
//	printf("%d\n", cnt2);
//	while (n % mm) ;
	ll ans = 1ll * cnt * (n / mm) - 1ll * (n / mm - 1) * cnt2;

	printf("%lld\n", ans);
	return 0;
}
/*
1000000000000 28 20
3 4 5 6 7 8 10 11 12 13 17 18 19 20 22 23 24 25 26 27
*/

Measured memory_bytes: 22656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string ss;
	int n;
	cin>>n>>ss;
	int len=ss.length();
	for(int i=0;i<len;++i) ss[i]=(ss[i]-'A'+n)%26+'A';
	cout<<ss<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N; cin >> N;
    double M; cin >> M;
    vector<int> A(N); REP (i, N) cin >> A[i];

    ll acc = accumulate(all(A), 0LL);

    sort(all(A), greater<int>());

    double mat = 1 / (4 * M);
    int cnt = 0;
    for(int i = 0; i < N; ++i) {
        if(A[i] < acc * mat) {
            break;
        } else {
            cnt++;
        }
    }

    if(cnt >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/*
  AtCoder Regular Contest 099
  C - Minimization
*/

#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int N, K;

int main() {
  scanf("%d%d", &N, &K);
  
  string buf;
  getline(cin, buf);

  printf("%d\n", (N - 1 + (K - 2)) / (K - 1));
	return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let c: i32 = sc.read();
    let d: i32 = sc.read();
    if a + b > c + d {
        println!("Left");
    } else if a + b == c + d {
        println!("Balanced");
    } else {
        println!("Right");
    }
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class AX {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}
};

int main() {
	AX solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
    ll n, x;
    cin >> n >> x;

    ll ans = n;
    ll a = x;
    ll b = n - x;
    while (1) {
        if (a % b == 0) {
            ans += a / b * 2 * b - b;
            break;
        } else {
            ans += a / b * 2 * b;
            ll _a = a;
            a = b;
            b = _a % b;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
def insertion_sort(aa)
  puts aa.join(" ")
  for i in 1..aa.size-1
    key = aa[i]
    j = i - 1
    while j >= 0 and aa[j] > key
      aa[j+1] = aa[j]
      j -= 1
    end
    aa[j+1] = key
    puts aa.join(" ")
  end
end

gets
insertion_sort(gets.split(" ").map(&:to_i))



Measured memory_bytes: 6892
n = int(input())
a = list(map(int, input().split()))
res = 0
x = 0
for i in range(1,n):
    if a[i-1] >= a[i]:
        x += 1
    else:
        res = max(res,x)
        x = 0
res = max(res,x)
print(res)

Measured memory_bytes: 14224
S = input()
T = input()
R = [0 for _ in range(26)]
Rrev = [0 for _ in range(26)]
AB = ["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"]

Able = True
for i in range(len(S)):
    if R[AB.index(S[i])] == 0:
        R[AB.index(S[i])] = T[i]
    elif R[AB.index(S[i])] != T[i]:
        Able = False
        break
    if Rrev[AB.index(T[i])] == 0:
        Rrev[AB.index(T[i])] = S[i]
    elif Rrev[AB.index(T[i])] != S[i]:
        Able = False
        break

print("Yes" if Able else "No")

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

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

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;

ll dp[1005] = { -INF };
vector<pair<ll,ll>> g[5000];
bool mugen = false;

void dfs(ll to, ll from, ll cost,vb check)
{
	if (check[to])
	{
		mugen = true;
	}
	else {
		dp[to] = max(dp[to],cost);
		//cout << to << " " << dp[to] << endl;
		check[to] = true;
		for (auto i : g[to])
		{
			dfs(i.first, to, cost + i.second, check);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here

	int a, b, c; cin >> a >> b >> c;

	//syou = a % b;
	FOR(i, 1, b + 1)if (a*i%b == c) { YES; return 0; }
	
	NO;
	return 0;
	
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>

int main()
{
	int r, d, x;
	std::cin >> r;
	std::cin >> d;
	std::cin >> x;

	int output_num = 10;
	for (int i = 0; i < output_num; i++) {
		x = r * x - d;
		std::cout << x << std::endl;
	}

    return 0;
}

Measured memory_bytes: 3604
H,W=map(int,input().split());B=[];l=[]
for y in range(H):
  A=list(map(int,input().split()));x=0
  for x in range(1,W):
    if A[x-1]%2:l.append((y+1,x,y+1,x+1));A[x]+=1
  B.append(A[x])
  if y and B[-2]%2:l.append((y,W,y+1,W));B[y]+=1
print(len(l))
for a in l:print(*a)

Measured memory_bytes: 24236