akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   int N;
   cin >> N;
   //0:a
   //1:c
   //2:g
   //3:t
   long long dp[N+1][1<<6];
   memset(dp,0,sizeof(dp));
   for(int i=0;i<4;i++){
      for( int j=0; j<4; j++){
         for(int k=0;k<4; k++){
            if(i==0&&j==2&&k==1){
               dp[3][i*4*4+j*4+k]=0;
            }
            else if(i==2&&j==0&&k==1){
               dp[3][i*4*4+j*4+k]=0;
            }
            else if(i==0&&j==1&&k==2){
               dp[3][i*4*4+j*4+k]=0;
            }
            else{
               dp[3][i*4*4+j*4+k]=1;
            }
         }
      }
   }
   int mod = 1000000007;
   for(int i=3; i<N; i++){
      for(int mask=0; mask<(1<<6); mask++){
         int x = mask/16;
         int y = (mask/4)%4;
         int z = mask%4;
         int offset = (mask*4)%(1<<6);
            // check a
            dp[i+1][offset+0]+=dp[i][mask];
            dp[i+1][offset+0]%=mod;

            // check g
            if( !(y==0&&z==1) ){
               dp[i+1][offset+2]+=dp[i][mask];
               dp[i+1][offset+2]%=mod;
            }

            // check c
            if( !((y==0&&z==2)||(y==2&&z==0)||(x==0&&z==2)||(x==0&&y==2)) ){
               dp[i+1][offset+1]+=dp[i][mask];
               dp[i+1][offset+1]%=mod;
            }
            // check t
            dp[i+1][offset+3]+=dp[i][mask];
            dp[i+1][offset+3]%=mod;
      }
   }
   long long ans=0;
   for(int i=0;i<(1<<6);i++){
      ans += dp[N][i];
      ans %= mod;
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int s[100005];
vector<int> e[100005];
void bfs(int num) {
	queue<int> q;
	q.push(num);
	s[num] = 1;
	while (!q.empty()) {
		int a = q.front();
		q.pop();
		for (int i = 0; i < e[a].size(); i++) {
			if (s[e[a][i]] == -1 && e[a][i] != s[a]) {
				s[e[a][i]] = a;
				q.push(e[a][i]);
			}
		}
	}
}
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i <= n;i++) {
		s[i] = -1;
	}
	for (int i = 0; i < m;i++) {
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	bfs(1);
	bool flag = true;
	for (int i = 2; i <= n;i++) {
		if (s[i]==-1) {
			flag = false;
			break;
		}
	}
	if (!flag) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 2; i <= n;i++) {
		cout << s[i] << endl;
	}
	return 0;
}


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

int cal[50];

int main(void) {
    for(int i=0;i<=50;i++) {
        for(int j=0;;j++) {
            if (i<(j*j+j)/2) {
                cal[i]=j-1;
                break;
            }
        }
    }
    long long x;
    scanf("%lld",&x);
    int ret=0;
    for(long long i=2;i*i<=x;i++) {
        int cnt=0;
        while (x%i==0) {
            cnt++;
            x/=i;
        }
        ret+=cal[cnt];
    }
    if (x!=1) {
        ret++;
    }
    printf("%d",ret);
}

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

int main() {
    string s;
    cin>>s;
    int num[26]={0};
    int n=s.size();
    for(int i=0;i<n;++i){
        ++num[s[i]-'a'];
    }
    int c=0;
    for(int i=0;i<26;++i){
        if(num[i]==0){
            printf("%c",'a'+i);
            return 0;
        }
        }
    cout<<"None"<<endl;
   
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(void) {
    int a,b;
    char op;
    cin >> a >> op >> b;
    if (op=='+') {
        cout << a+b << endl;
    } else {
        cout << a-b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int n, m, a[50], b[50], c[50], d[50];
int ans;
int mu;

signed main() {
	cin >> n >> m;
	rep(i, n)cin >> a[i] >> b[i];
	rep(i, m)cin >> c[i] >> d[i];
	rep(i, n) {
		mu = inf;
		rep(j, m) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < mu) {
				mu = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,g,b;cin >> r >> g >> b;
    if((g*10+b)%4==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3632
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())

A1_ans = [0, 0, 0]
A2_ans = [0, 0, 0]
A3_ans = [0, 0, 0]

for i in range(N):
    b = int(input())
    for j in range(3):
        if A1[j] == b:
            A1_ans[j] = 1
    for j in range(3):
        if A2[j] == b:
            A2_ans[j] = 1
    for j in range(3):
        if A3[j] == b:
            A3_ans[j] = 1
            
flag = False
for i in range(3):
    if A1_ans[i] == 1 and A2_ans[i] == 1 and A3_ans[i] == 1:
        flag = True
if A1_ans[0] == 1 and A1_ans[1] == 1 and A1_ans[2] == 1:
    flag = True
if A2_ans[0] == 1 and A2_ans[1] == 1 and A2_ans[2] == 1:
    flag = True
if A3_ans[0] == 1 and A3_ans[1] == 1 and A3_ans[2] == 1:
    flag = True
if A1_ans[0] == 1 and A2_ans[1] == 1 and A3_ans[2] == 1:
    flag = True
if A1_ans[2] == 1 and A2_ans[1] == 1 and A3_ans[0] == 1:
    flag = True
    
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (ll i = 0; i < (n); ++i)

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

mint comb(ll n, ll a)
{
    mint c(1);
    mint d(1);
    rep(i, a) {
        c *= n;
        --n;
        d *= (i+1);
    }
    c /= d;
    return c;
}

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

    ll n, a, b;
    cin >> n >> a >> b;


    mint ans = mint(2).pow(n);
    comb(4, 1); 
    comb(4, 2); 

    ans -= 1;
    ans -= comb(n, a);
    ans -= comb(n, b);

    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(i,arr)       for(int& i:arr)cin>>i;
#define output(i,arr)      for(int& i:arr)cout<<i<<" ";
#define for_each(arr)      for(auto& it:arr)
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
   // #ifndef ONLINE_JUDGE
  //  freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //  #endif
    cin>>n;
    vector<int>v(n);
    input(i,v);
    bool hobe=false;
    for(int i=0;i<n;i++){
    	if(v[i]%2==0){
    		if(v[i]%3==0||v[i]%5==0)
    			continue;
    		else hobe=true;
    	}
    }
    if(hobe)cout<<"DENIED"<<endl;
    else cout<<"APPROVED"<<endl;

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int[] a = new int[5];
		int min=10;
		int sum = 0;
		for(int i=0; i<5; i++){
			a[i] = Integer.parseInt(sc.next());
			int tmp_min = a[i]%10;
			if(tmp_min != 0 && tmp_min<min)min = tmp_min;
			sum += a[i];
			if(tmp_min>0)sum += 10-tmp_min;
		}
		int ans = sum - 10 + min;
		
			System.out.println(ans);

		sc.close();
	}
	
}


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

int main()
{
  string s;
  cin >> s;
  sort(begin(s), end(s));
  string abc = "abcdefghijklmnopqrstuvwxyz";
  string answer;
  char judge;
  for(int i = 0; i < s.size(); i++)
  {
    if(i == 0)
    {
      judge = s.at(i);
      answer += judge;
      continue;
    }
    if(judge != s.at(i))
    {
      judge = s.at(i);
      answer += judge;
    }
    else
    {
      continue;
    }
    
  }
  
  for(int i = 0; i <= answer.size(); i++)
  {
    if(i == answer.size() && answer.size() < abc.size())
    {
      cout << abc.at(i) << endl;
      return 0;
    }
    else if(i == answer.size())
    {
      break;
    }
    
    if(answer.at(i) != abc.at(i))
    {
      cout << abc.at(i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin>>n>>s;

    vector<ll> w(n);
    vector<ll> b(n);

    FOR(i,0,s.size()){
      if(s[i] == '.') b[i] = 1;
      else w[i] = 1;
    }

    ll tmp=0;
    ll ans=0;
    FOR(i,0,s.size()) tmp+=b[i];

    ans = tmp;
    FOR(i,0,s.size()){
      tmp = tmp - b[i] + w[i];
      ans = min(ans, tmp);
    }


    cout<<ans<<endl;
}


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

int main(){
  string s, t; cin >> s >> t;
  int n = s.size(), m = t.size(), a = 1e9;
  rep(i, n-m+1){
    int u = 0;
    rep(j, m) if(s[i+j] != t[j]) ++u;
    a = min(a, u);
  }
  cout << a << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>
#include <string>
#include <cstdlib>
using namespace std;

int a,b,c,d,n;
string course;

int main(){

    cin >> n >> a >> b >> c >> d;
    cin >> course;

    a--;
    b--;
    c--;
    d--;

    bool prev_x = false;
    bool end = false;
    for(int i=a;i<c;i++){
        if(course[i] == '#'){
            if(prev_x){
                cout << "No" << endl;
                return 0;
            }
            prev_x = true;
        } else {
            prev_x = false;
        }   
    }

    if(!end){
        for(int i=b;i<d;i++){
            if(course[i] == '#'){
                if(prev_x){
                    cout << "No" << endl;
                    return 0;
                }
                prev_x = true;
            } else {
                prev_x = false;
            }        
        }
    }

    if(c<d && !end){
        cout << "Yes" << endl;
    } else if (!end) {
        int o_count = 0;
        int o_max = 0;
        for(int i=b-1;i<d+2;i++){
            if(course[i]=='.'){
                o_count++;
                o_max = max(o_count, o_max);
            } else {
                o_count = 0;
            }
        }

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


Measured memory_bytes: 640
import Control.Monad
import Data.List (sortBy)

manhattan [x1, y1] [x2, y2] =
  x + y
    where
      x = abs $ x1 - x2
      y = abs $ y1 - y2

solve [] ys = []
solve (x:xs) ys = (msolve (solve' x ys)) : solve xs ys

solve' x ys = zip [1..] $ fmap (\y -> manhattan x y) ys

msolve ts = fst $ head $ sortBy (\x y -> compare (snd x) (snd y)) ts

main = do
  [n, m] <- words <$> getLine
  ns <- replicateM (read n) $ words <$> getLine
  ms <- replicateM (read m) $ words <$> getLine
  let ns' = fmap (\xs -> fmap (read :: String -> Int) xs) ns
      ms' = fmap (\xs -> fmap (read :: String -> Int) xs) ms in
    forM_ (solve ns' ms') (\a -> putStrLn ((show :: Int -> String) a))


Measured memory_bytes: 1020
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(15);
  int a,b,c,k;
  cin >> a >> b >> c >>k;
  if(k%2==1) cout << b-a << endl;
  else cout << a-b << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

n=input()
for line in sys.stdin:
    x=map(float,line.split())[0::2];
    y=map(float,line.split())[1::2];
    #guilty...
    A=x[0]-x[1]
    B=y[0]-y[1]
    C=x[1]-x[2]
    D=y[1]-y[2]
    E=-(x[0]**2+y[0]**2)+(x[1]**2+y[1]**2)
    F=-(x[1]**2+y[1]**2)+(x[2]**2+y[2]**2)
    l=(D*E-B*F)/(A*D-B*C)
    m=(-C*E+A*F)/(A*D-B*C)
    n=-(x[0]**2+y[0]**2+l*x[0]+m*y[0])

    print "{:.3f} {:.3f} {:.3f}".format(-l/2,-m/2,(l**2+m**2-4*n)**0.5/2)

Measured memory_bytes: 5012
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int r = s.nextInt();
        String str;
        if(r < 1200)
            str = "ABC";
        else if(r < 2800)
            str = "ARC";
        else 
            str = "AGC";
        System.out.println(str);
            
    }
    
}

Measured memory_bytes: 22356
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));

		char[] str = input.readLine().toCharArray();

		int order = Integer.parseInt(input.readLine());

		//命令をorder回実行する
		for(int kai = 0; kai < order; kai++)
		{
			String[] orderStr = input.readLine().split(" ");

			int start = Integer.parseInt(orderStr[1]);

			int end = Integer.parseInt(orderStr[2]);

			//命令がprintのとき
			if(orderStr[0].equals("print"))
			{
				//startからendまでの文字列を表示する
				for(int num = start; num <= end; num++)
					System.out.print(str[num]);

				System.out.println();
			}

			//命令がreverseのとき
			else if(orderStr[0].equals("reverse"))
			{

				char[] reverse = new char[end - start +1];

				//reverseに指定された範囲の文字列を逆順に代入する
				for(int num = 0; num < end - start + 1; num++)
					reverse[num] = str[end - num];

				//指定範囲を逆順にした文字列を代入する
				for(int num = 0; num < end - start + 1; num++)
					str[start + num] = reverse[num];
			}

			//命令がreplaceのとき
			else if(orderStr[0].equals("replace"))
			{
				char[] replace = orderStr[3].toCharArray();

				//指定範囲に入力された文字列を代入する
				for(int num = 0; num <end - start + 1; num++)
					str[start + num] = replace[num];
			}
		}
	}
}



Measured memory_bytes: 28504
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

class UnionFind {
public:
    
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ

    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
    
};

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    UnionFind Uni(n);
    Uni.init(n);

    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        Uni.unite(x, y);
    }

    vvl G(n);
    ll renketuseibun = 0;  // 森の連結成分の個数
    rep(v, n) {
        if(Uni.root(v) == v) {
            renketuseibun++;
        }
        ll p = Uni.root(v);
        G[p].pb(a[v]);
    }

    if(renketuseibun == 1) {
        out(0);
        re0;
    }

    if(2*(renketuseibun-1) > n) {
        out("Impossible");
        re0;
    }

    vl vec;
    ll ans = 0;
    rep(v, n) {
        if(Uni.root(v) == v) {
            sort(all(G[v]));
            ans += G[v][0];
            rep(j, G[v].size()) {
                if(j == 0) {
                    continue;
                }
                vec.pb(G[v][j]);
            }
        }
    }

    sort(all(vec));
    rep(i, renketuseibun-2) {
        ans += vec[i];
    }

    out(ans);
    re0;
}

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

using namespace std;

#define ll long long
#define mod (ll)1000000007

const ll INF = 1e11;

void solve(){

    int n, m; cin >> n >> m;
    vector<int> graph [n+1];
    vector<int> indeg (n+1);
    for(int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        graph[u].push_back(v);
        indeg[v]++;
    }
    int dp[n+1] = {0};
    vector<int> toProcess;
    for(int i = 1; i <= n; ++i)
        if(indeg[i] == 0) toProcess.push_back(i);
    
    for(int i = 0; i < toProcess.size(); ++i){
        for(int it : graph[toProcess[i]]){
            dp[it] = max(dp[it], dp[toProcess[i]] + 1);
            indeg[it]--;
            if(indeg[it] == 0)
                toProcess.push_back(it);
        }
    }
    cout << *max_element(dp, dp+n+1) << endl;

    return;
}


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

    solve();    

	return 0;
}



Measured memory_bytes: 10056
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> v(N);
	for(int i=0; i<N; ++i) cin >> v[i];
	sort(v.begin(), v.end());
	priority_queue<int> pq;
	for(int k=0; k<2; ++k){
	    for(int i=1; i*i<=v[k]; ++i){
	        if(v[k]%i==0){
	            pq.push(i);
	            if(i*i<v[k]) pq.push(v[k]/i);
	        }
	    }
	}
	while(true){
	    int cnt=0;
	    for(int i=0; i<N; ++i) if(v[i]%pq.top()==0) ++cnt;
	    if(cnt<N-1) pq.pop();
	    else break;
	}
	cout << pq.top() << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

struct Skill{
    static const int INF = 100000000;
    static const int N = 100;
    array<int, N> begin;
    array<int, N> end;
    Skill(){
        begin.fill(-INF);
        end.fill(INF);
    }
    bool operator < (const Skill& s) const {
        for(int i = 0; i < N; i++){
            if(end[i] < s.begin[i]) return true;
        }
        return false;
    }
};

int main(){
    int M, N;
    while(cin >> M >> N){
        vector<Skill> skills(M);
        REP(i, M){
            int K;
            cin >> K;
            while(K--){
                int s, t;
                string cond;
                cin >> s >> cond >> t;
                if(cond == ">="){
                    int& x = skills[i].begin[s - 1];
                    x = max(x, t);
                }else{
                    int& y = skills[i].end[s - 1];
                    y = min(y, t);
                }
            }
        }
        bool d[100][100] = {};
        REP(i, M) REP(j, M) if(skills[i] < skills[j]) d[i][j] = true;
        REP(k, M) REP(i, M) REP(j, M) d[i][j] |= d[i][k] && d[k][j];
        bool ans = true;
        REP(i, M) if(d[i][i]) ans = false;
        cout << (ans ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string S, T;
    cin >> S >> T;
    vector<string> v;
    REP (i, S.size() - T.size() + 1) {
        bool ok = true;
        REP (j, T.size()) {
            if (S[i + j] == '?') continue;
            ok &= (S[i + j] == T[j]);
        }
        if (ok) {
            string s = S;
            REP (j, i) if (S[j] == '?') s[j] = 'a';
            FOR (j, i, i + T.size()) s[j] = T[j - i];
            FOR (j, i + T.size(), S.size()) if (S[j] == '?') s[j] = 'a';
            v.push_back(s);
        }
    }
    if (v.empty()) {
        cout << "UNRESTORABLE" << endl;
        return;
    }
    sort(v.begin(), v.end());
    cout << v[0] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(void) {
  int list[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}, x, y;
  cin >> x >> y;
  if (list[x] == list[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

struct UnionFind {
  vector<int> par, rank, sz;
  UnionFind(int n) {
    par.assign(n, 0);
    rank.assign(n, 0);
    sz.assign(n, 1);
    for (int i = 0; i < n; i++) { par[i] = i; }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  vector<int> deg(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
    deg[a]++;
    deg[b]++;
  }
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (uf.same(a, b)) {
      deg[a]++;
      deg[b]++;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << uf.sz[uf.find(i)] - 1 - deg[i];
    if (i + 1 < N)
      cout << ' ';
    else
      cout << endl;
  }
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int gcd(int a, int b) {
  int t;
  while ( b != 0 ) { 
    t = a%b; a = b; b = t; 
  }
  return a; 
}

int gcd3(int a, int b, int c) {
  int s, t;
  s = gcd(a, b);
  t = gcd(c, s);
  return t;
}

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

  int64_t ans=0;
  for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)for(int k=1; k<=n; k++){
    ans+=gcd3(i,j,k);
  }

  cout << ans << endl;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  string s, t; cin >> s >> t;
  int n = s.size();
  rep(i, n) {
    if(t == s.substr(n-i, i) + s.substr(0, n-i)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

typedef pair<char,int> P;
int ans;

void func(P p[], int cnt, vector<int> f){
  if(cnt == 3) ans = 1;
  for(int i=0;i<9;i++){
    if(!f[i]){
      f[i] = true;
      for(int j=i+1;j<9;j++){
        if(!f[j] && p[i].first == p[j].first){
          if(p[i].second == p[j].second){
            vector<int> f2 = f;
            f2[j] = true;
            for(int k=j+1;k<9;k++){
              if(!f[k] && p[i].first == p[k].first && p[i].second == p[k].second){
                f2[k] = true;
                func(p,cnt+1,f2);
              }
            }
          }
          if(p[i].second + 1 == p[j].second){
            vector<int> f2 = f;
            f2[j] = true;
            for(int k=j+1;k<9;k++){
              if(!f[k] && p[i].first == p[k].first && p[i].second + 2 == p[k].second){
                f2[k] = true;
                func(p,cnt+1,f2);
              }
            }
          }
        }
      }
    }
  }             
}

int main(){
  int n;
  cin >> n;
  while(n--){
    P p[9];
    ans = 0;
    for(int i=0;i<9;i++) cin >> p[i].second;
    for(int i=0;i<9;i++) cin >> p[i].first;
    sort(p,p+9);
    vector<int> v(9,0);
    func(p,0,v);

    cout << ans << endl;
  }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a) > (b) ? (a) : (b))
const int N = 8e6+1;

char s[1000001],t[1000001];
char Ls[N];
char Lt[N],lt[N];

int z[N];

int mx,R;
inline void Z(int siz){
   z[1] = siz;
   R = mx = 0;
   for(int i = 2;i <= siz; ++i){
      z[i] = (i < R)?min(R-i,z[i-mx+1]):0;
      while(i+z[i] <= siz && Lt[i+z[i]] == Lt[z[i]+1])++z[i];
      if(i+z[i] > R)R = i+z[i],mx = i;
   }
}

int ans2 = 0;
int main(){
   scanf("%s",s+1); scanf("%s",t+1);
   memcpy(Ls,s,sizeof s);
   int tsize = strlen(t+1);
   int Lsz = strlen(s+1),sz = Lsz;
   while(Lsz -sz < 2*tsize){
      for(int i = Lsz+1;i <= Lsz+sz; ++i)
         Ls[i] = s[i-Lsz];
      Lsz += sz;
      Ls[Lsz+1] = '\0';
   }
   memcpy(Lt,t,sizeof t);
   int Ltz = strlen(t+1);
   while(Ltz-tsize < Lsz){
      for(int i = Ltz+1;i <= Ltz+tsize; ++i){
         Lt[i] = t[i-Ltz];
      }
      Ltz += tsize;
      Lt[Ltz+1] = '\0';
   }
   int pos = strlen(Lt+1)+2;
   Lt[pos-1] = '#';
   for(int i = pos;i < pos+Lsz; ++i){
      Lt[i] = Ls[i-pos+1];
   }
   Lt[pos+Lsz] = '\0';
   int ans = 0;
   int Lsize = strlen(Lt+1);
   Z(Lsize);
   for(register int i = pos;i <= Lsize; ++i){
      if(z[i])ans = max(ans,z[i]/tsize);
   }
   if(ans == 0)puts("0");
   else {
      for(int i = Lsize;i < Lsize+Lsz; ++i){
         Lt[i+1] = Ls[i-Lsize+1];
      }
      Lsize += Lsz;
      Z(Lsize);
      for(register int i = pos;i <= Lsize; ++i){
         ans2 = max(ans2,z[i]/tsize);
      }
      //cerr << ans2 << ' ' << ans << endl;
      if(ans2 > ans)puts("-1");
      //else if(ans2 > ans)cerr << "error" << endl;
      else printf("%d\n",ans);
   }
   return 0;
}


Measured memory_bytes: 39680
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int n; cin>>n;
  double ans = 0;
  rep(i,n) {
    double a; string s;
    cin>>a>>s;
    if (s == "JPY") ans += a;
    else ans += (380000.0 * a);
  }
  printf("%.6f\n", ans); 
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     
#include <cassert>
#include <iomanip>        
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>
#define vl vector<LL>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,m,l;
	cin>>n>>m>>l;
	vl a(m),b(m),c(m);
	vll g(n,vl(n,1LL*mod*mod));
	vll g2(n,vl(n,1LL*mod*mod));
	FOR(i,0,m){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--;b[i]--;
		g[a[i]][b[i]]=g[b[i]][a[i]]=c[i];
	}
	cerr<<"In1"<<endl;
	FOR(i,0,n){
		g[i][i]=g2[i][i]=0;
	}
	FOR(k,0,n){
		FOR(i,0,n){
			FOR(j,0,n){
				g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
			}
		}
	}
	FOR(i,0,n){
		FOR(j,0,n){
			if(l>=g[i][j])g2[i][j]=1;
		}
	}
	FOR(k,0,n){
		FOR(i,0,n){
			FOR(j,0,n){
				g2[i][j]=min(g2[i][j],g2[i][k]+g2[k][j]);
			}
		}
	}
	cerr<<"WF"<<endl;

	int q;
	cin>>q;
	vi s(q),t(q);
	FOR(i,0,q){
		cin>>s[i]>>t[i];
		s[i]--;t[i]--;
		LL ans=g2[s[i]][t[i]]-1;
		if(ans>mod)ans=-1;
		cout<<ans<<endl;
	}

}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();

		if (a > b) {
			System.out.println(0);
			return;
		}
		if (a < b && n == 1) {
			System.out.println(0);
			return;
		}
		long max = a + (n - 1) * b;
		long min = a * (n - 1) + b;
		System.out.println(max - min + 1);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n;
    std::cin >> n;

    int act[n][3];
    for(int i = 0 ; i < n ; ++i){
        std::cin >> act[i][0] >> act[i][1] >> act[i][2];
    }

    int dp[n][3];
    dp[0][0] = act[0][0];
    dp[0][1] = act[0][1];
    dp[0][2] = act[0][2];

    for(int i = 1 ; i < n ; ++i){
        dp[i][0] = std::max(dp[i - 1][1] , dp[i - 1][2]) + act[i][0];
        dp[i][1] = std::max(dp[i - 1][0] , dp[i - 1][2]) + act[i][1];
        dp[i][2] = std::max(dp[i - 1][0] , dp[i - 1][1]) + act[i][2];
    }

    int sol = std::max(dp[n - 1][0] , dp[n - 1][1]);
    sol = std::max(sol , dp[n - 1][2]);

    std::cout << sol << '\n';

}

Measured memory_bytes: 2560
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]
#print(dp)
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))

Measured memory_bytes: 34616
#include<bits/stdc++.h>
using namespace std;
using Long = long long;

int main(){
    Long ans = 0;

    int n;
    cin >> n;
    vector<int> v(n + 1);

    for( int i = 1 ; i <= n ; ++i ){
        for( int j = i ; j <= n ; j += i ){
            v[j]++;
        }
    }

    for( int i = 1 ; i <= n ; ++i ){
        ans += 1LL * i * v[i];
    }

    cout << ans ;

    return 0;
}

Measured memory_bytes: 42320
from heapq import heapify, heappop, heappush
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]
A = [[x, y, 0] for x, y in ab]
B = [[x, y, 1] for x, y in cd]
abcd = A+B
abcd.sort()

a = []
heapify(a)
result = 0
for i in range(2*n):
    x, y, h = abcd[i]
    if h==0:
        heappush(a, -y)
    else:
        if len(a) > 0:
            a_y = heappop(a)
            h = []
            while y+a_y < 0:
                h.append(a_y)
                if len(a) > 0:
                    a_y = heappop(a)
                else:
                    break
            if y+a_y>0:
                result += 1
            for j in h:
                heappush(a, j)
        
print(result)

Measured memory_bytes: 3064
'use strict';

const DELIMITER = " ";
const A_INDEX = 0;
const B_INDEX = 1;
const K_INDEX = 3;
const LIMIT = Math.pow(10, 18);

const process = input => {
    const indexArr = input.split(DELIMITER);
    const ans = parseInt(indexArr[A_INDEX]) - parseInt(indexArr[B_INDEX]);
    const KString = indexArr[K_INDEX];
    // JS rounds up large numbers; simply get last digit for modulo
    const K = parseInt(KString.charAt(KString.length-1));

    if (Math.abs(ans) > LIMIT) {
        console.log('Unfair')
    } else {
        console.log(K % 2 === 0 || ans === 0 ? ans : -ans);
    }
}

process(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
abc = list(map(int, input().split()))
abc.sort()
abc_min,abc_middle,abc_max = abc
step1 = abc_max - abc_middle
abc_min += step1
step2 = (abc_max - abc_min)//2
step3 = (abc_max - abc_min)%2 * 2
print(step1+step2+step3)

Measured memory_bytes: 3060
from heapq import heappush,heappop
N=int(input())
X,Y=[],[]
for i in range(N):
  x,y=map(int,input().split())
  X.append((x,i))
  Y.append((y,i))
X.sort()
Y.sort()
inf=float("inf")
G=[[]*N for i in range(N)]
for i in range(N-1):
  G[X[i][1]].append((X[i+1][0]-X[i][0],X[i+1][1]))
  G[X[i+1][1]].append((X[i+1][0]-X[i][0],X[i][1]))
  G[Y[i][1]].append((Y[i+1][0]-Y[i][0],Y[i+1][1]))
  G[Y[i+1][1]].append((Y[i+1][0]-Y[i][0],Y[i][1]))
  
Q=[(0,0)]
ans=0
visited=[False]*N
while Q:
  c,n=heappop(Q)
  if visited[n]:
    continue
  visited[n]=True
  ans+=c
  for c2,n2 in G[n]:
    if visited[n2]:
      continue
    else:
      heappush(Q,(c2,n2))

print(ans)

                
              
              
  


Measured memory_bytes: 117848
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,ll>;
const ll inf=1000000000007;
const int mod=1000000007;


vector<int> Parent;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
//	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};



int main() {
  int n,m; cin >> n >> m;
  vector<int> a(n,-1);

  UnionFind Uni(n);

  rep(i,0,m){
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;
    Uni.connect(x,y);
}
  int cnt=0;
  rep(i,0,n){
    if(Parent[i]<0){
      cnt+=1;
    }
//    cout << Parent[i] << endl;
  }
  cout << cnt << endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(m);
    vector<int> y(m);
    vector<vector<int>> all(n);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--;
        p.at(i) = a;
        y.at(i) = b;
        all.at(a).push_back(b);
    }
    for(int i=0; i<n; i++){
        sort(all.at(i).begin(), all.at(i).end());
    }
    for(int i=0; i<m; i++){
        int a,b;
        a = p.at(i);
        b = y.at(i);
        int s = all.at(a).size();
        int l=-1; int r= s;
        while(l+1 < r){
            int mid = (l+r)/2;
            if(all.at(a).at(mid) >= b){
                r = mid;
            }
            else l = mid;
        }
        printf("%06d%06d\n", a+1, r+1);
    }
}

Measured memory_bytes: 9344