akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
const int N=100010;
char s[N];
int c[10];
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i,n;
    scanf("%s",s+1);n=strlen(s+1);
    for (i=1;i<=n;i++) c[s[i]-'a']++;
    sort(c,c+3);
    if (c[2]-c[0]<=1) puts("YES");
     else puts("NO");

    return 0;
}


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

// dp[i][j] := j: 0:a, 1:b, 2:c
int dp[101010][3];

int main() {
	int n;
	cin >> n;
	vector< vector< int > > d(n, vector< int >(3, 0));
	for (int i=0; i<n; ++i) {
		cin >> d[i][0] >> d[i][1] >> d[i][2];
	}

	for (int ni=0; ni<n; ++ni) {
		for (int ji=0; ji<3; ++ji) {
			for (int jj=1; jj<3; ++jj) {
				dp[ni+1][ji] = max(dp[ni+1][ji], dp[ni][(ji+jj)%3] + d[ni][ji]);
			}
		}
	}

	int ans = 0;
	for (int i=0; i<3; ++i) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
	
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vi a(n);
	REP(i, n) cin >> a[i];
	ll ans = 0;
	int maxim = a[0];
	RI(i, n - 1) {
		if (a[i] < maxim) {
			ans += (maxim - a[i]);
		} else {
			maxim = a[i];
		}
	}
	cout << ans;
	return 0;
}
 


Measured memory_bytes: 4024
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 if r<H and l<H:
  if A[i]<A[l]:
   if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
   else:A[i],A[l]=A[l],A[i];h(l)
  elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
 elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65444
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<endl;
}






Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B := sc.nextInt(), sc.nextInt()
	ans := 0
	for i := A; i <= B; i++ {
		if f(i) {
			ans++
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}

func f(n int) bool {
	str := strconv.Itoa(n)
	l, r := 0, len(str)-1
	for l < r {
		if str[l] != str[r] {
			return false
		}
		l++
		r--
	}
	return true
}


Measured memory_bytes: 1152
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    int[] c = new int[n-1];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i++){
      b[i] = sc.nextInt();
    }
    for(int i = 0; i < n-1; i++){
      c[i] = sc.nextInt();
    }
    int sum = 0;
    for(int i = 0; i < n-1; i++){
      sum += b[a[i]-1];
      if(a[i]+1 == a[i+1]){
        sum += c[a[i]-1];
      }
    }
    sum += b[a[n-1]-1];
    System.out.print(sum);
  }
}


Measured memory_bytes: 21972
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int temp, n;
  cin >> temp;
  n = temp;
  int num = 0;
  while(n >= 10){
    num += n % 10;
    n /= 10;
  }
  num += n;
  if(temp % num == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int main(void) {
    int i, n, ary[MAX];
    scanf("%d", &n);
    for(i = 0; i < n; scanf("%d", &ary[i++]));
    for(; i; printf("%d%c", ary[--i], ~-i ? ' ' : '\n'));
    return 0;
}

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
  int N,L;
  string str;
  sl(N);sl(L);
  vector<string>vect;
  while(N--){
	  cin>>str;
	  vect.pb(str);
  }
  sort(vect.begin(),vect.end());
  for(auto it:vect)cout<<it;
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AOJ0510
{
    class Program
    {
        public void Proc()
        {
                int[,] score = new int[2,4];
                int[] total = new int[2];
                for (int i = 0; i < 2; i++)
                {
                    string input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input)) break;
                    string[] score_s = input.Split(' ');

                    for (int j = 0; j < score_s.Length; j++)
                    {
                        score[i, j] = int.Parse(score_s[j]);
                        total[i] += score[i, j];
                    }
                }
                Console.WriteLine(Math.Max(total[0], total[1]));
        }

        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }
}

Measured memory_bytes: 9108
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
using namespace std;


int main(){
	int n;
    cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	vector<int>count(n);
	for (int i = 0; i < n; i++) {
		if(a[i]==b[i]){
			count[i]++;
		}
		if (a[i] == c[i]) {
			count[i]++;
		}
		if (b[i] == c[i]) {
			count[i]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (count[i] ==2||count[i]==1) {
			ans += 1;
		}else if(count[i]==0){
			ans += 2;
		} 

	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  string s;
  cin>>s;
  ll n=s.size(),change=0;
  for (ll i=0;i<n-1;i++) {
    if (s[i]!=s[i+1]) {
      change++;
    }
  }
  cout<<change<<endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
int main() {
	int i,sx, sy, tx, ty;
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	for (i = 0; i < (ty - sy); i++) {
		printf("U");
	}
	for (i = 0; i < (tx - sx); i++) {
		printf("R");
	}
	for (i = 0; i < (ty - sy); i++) {
		printf("D");
	}
	for (i = 0; i < (tx - sx); i++) {
		printf("L");
	}
	printf("L");
	for (i = 0; i <= (ty - sy); i++) {
		printf("U");
	}
	for (i = 0; i <= (tx - sx); i++) {
		printf("R");
	}
	printf("D");
	printf("R");
	for (i = 0; i <= (ty - sy); i++) {
		printf("D");
	}
	for (i = 0; i <= (tx - sx); i++) {
		printf("L");
	}
	printf("U");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int selectionsort(vector<int> &a,int n){
    int cnt=0;
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if(a[i]==a[minj])cnt--;
        swap(a[i],a[minj]);
        cnt++;
    }
    return cnt;
}
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=selectionsort(a,n);
    for(int i=0;i<n;i++){
        cout << a[i];
        if(i<n-1)cout << " ";
    }
    cout << endl << ans << endl;
}



Measured memory_bytes: 3100
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long nums[] = new long[n];
		long dp[] = new long[n];		
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 0 ; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n && j <= i+k; j++) {
				dp[j] = Math.min(dp[j],  Math.abs(nums[i] - nums[j]) + dp[i]);				
			}
		}
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 50468
N=int(input())
fourK = 0
fourLen=[]
sevenK = 0
sevenLen=[]
while fourK <= N:
    fourLen.append(fourK)
    fourK += 4
while sevenK <= N:
    sevenLen.append(sevenK)
    sevenK += 7
x=fourLen[0] + sevenLen[0]
for f in fourLen:
    for s in sevenLen:
        if N == f + s:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
void 
solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N;
vector<int> A;

void solve() {
	cin >> N;
	A.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> A[n];
		A[n]--;
	}
	int count = 0;
	for (int n = 0; n < N; n++) {
		if (A[A[n]] == n)count++;
	}
	cout << count / 2 << endl;
	return;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
    #include <fstream>
    #include<string>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>


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


    #define endl "\n"
    #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    const int N=3e5+5;
    ll mod=998244353 ;
    ll mul (ll a, ll b)
    {
        a%=mod;
        b%=mod;
        return (a*b)%mod;
    }
    ll add (ll a, ll b)
    {
        a%=mod;
        b%=mod;
        return (a+b+mod)%mod;
    }
    ll fastpow(ll b, ll p)
    {
        if(p==0)
            return 1;
        ll ans=fastpow(b,p/2);
        ans=mul(ans,ans);
        if(p%2)ans=mul(ans,b);
        return ans;
    }
    ll inf=1e18;
    const int M=(1<<13);
    ll dp[1005][M];
    int n,m;
    ll cost[1005];
    vector<int>v[N];
    bool checkall(int mask)
    {
        for(int i=0;i<n;i++)
        {
            if(((mask>>i)&1)==0)
                return 0;

        }
        return 1;


    }
    ll nower(int mask,int i)
    {

        for(auto j:v[i])
        {
            mask|=(1<<j);
        }
    return mask;

    }
    ll solve(int i, int mask)
    {
        if(i==m)
        {
            if(checkall(mask))
                return 0;
            else
                return inf;
        }
        ll &ans=dp[i][mask];
        if(ans!=-1)
            return ans;
        ans=1e18;
        ans=min(ans,solve(i+1,mask));

        ans=min(ans,solve(i+1,nower(mask,i))+cost[i]);
        return ans;


    }


    int main()
    {
        FIO
       memset(dp,-1,sizeof dp);
       cin>>n>>m;
       for(int i=0;i<m;i++)
       {
           int b;
           cin>>cost[i]>>b;
           while(b--)
           {
               int x;
               cin>>x;
               v[i].push_back(x-1);
           }
       }
       ll ans=solve(0,0);
       if(ans==inf)
        cout<<-1;
       else
        cout<<ans;

        return 0;
    }


Measured memory_bytes: 74956
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    long long int n; cin>>n;
    vector<int> R(n);
    for(long long int i=0;i<n;i++){
        cin>>R[i];
    }
    int maxv=-2000000000;
    int minv=R[0];
    for(long long int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
    #define pb push_back
    #define MOD 1000000007
    #define pii pair<int,int>
    #define ll long long int
    using namespace std;


    void solve() {
        string s, t;
        cin >> s >> t;
        string ss = "";
        for (int i = 0; i < t.length() - 1; i++)
            ss += t[i];

        if (ss == s)
            cout << "Yes" << "\n";

        else
            cout << "No" << "\n";





    }




    int main()
    {

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t = 1;
        //cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }




Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ran(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main(void)
{
    int N, W;
    vector<int> w(110);
    vector<int> v(110);
    vector<ll> dp(100010, 0);
    int i, j, k;

    cin >> N >> W;

    ran(i, 1, N)
    {
        cin >> w[i] >> v[i];
    }

    ran(i, 1, N)
    {
        for (j = W; j >= w[i]; j--)
        {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define LL long long
#define ri register int
#define pii pair<int, int>
#define pll pair<LL, LL>
using namespace std;
inline int read()
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9')
		ch = getchar();
	do {
		ret = ret * 10 + ch - '0';
		ch = getchar();
	} while('0' <= ch && ch <= '9');
	return ret;
}
inline void write(int x) // x > 0 (x != 0) ***
{
	if(!x)
		return ;
	write(x / 10);
	putchar(x % 10 + '0');
}
inline LL gcd(LL x, LL y)
{
	return x == 0 ? y : gcd(y % x, x);
}
inline LL lcm(LL x, LL y)
{
	return x / gcd(x, y) * y;
}
LL n, m;
string s1, s2;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	cin >> s1 >> s2;
	LL g = lcm(n, m);
	LL d1 = g / n, d2 = g / m;
	for(int i = 0; i < n; i ++)
	{
		if(i * d1 % d2 == 0 && s1[i] != s2[i * d1 / d2])
			return cout << -1 << endl, 0;
	}
	cout << g << endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL; 
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
//LL dp[2000001];
LL mod=1e9+7;
bool vis[100000];
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
LL modexpo(LL a, LL b) {
  LL ans=1;
  a=a%mod;
  while(b>0){
    if((b&1)==1){
      ans=((ans%mod)*(a%mod))%mod;
    }
    b=b>>1;
    a=((a%mod)*(a%mod))%mod;
  }
  return ans; 
}
LL invmod(LL n){
  return modexpo(n,mod-2);
}

LL comb(LL n,LL r){
  if(r==0){
    return 1;
  }
  LL fact[n+1];
  fact[0] = 1; 
    for (LL i = 1; i <= n; i++){
       fact[i] = (fact[i - 1] * i) %mod;}
    return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) %mod; 
}
LL gcd(LL a, LL b) {
  if (a == 0){
       return b;
       }  
    return gcd(b % a, a);  
}
LL lcm(LL a, LL b) {
  return (a*b)/gcd(a,b);
}
void dfs(LL i,vector<LL>adj[],bool visited[]){
  visited[i]=1;
  for(auto j:adj[i]){
    if(visited[j]==0){
      dfs(j,adj,visited);
    }
  }
}
void solve(LL k){
LL n, m; 
cin>>n>>m; 
vector<LL>adj[n+1];
bool visited[n+1];
memset(visited,0,sizeof(visited));
while(m--){
  LL a, b;
  cin>>a>>b; 
  adj[a].push_back(b);
  adj[b].push_back(a);
}
LL c=0;
for(LL i=1;i<=n; i++){
  if(visited[i]==0){
    c++;
    dfs(i,adj,visited);
  }
}
cout<<c-1<<endl; 
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
 LL t=1;
//cin>>t;
 LL k=1;
while(k<=t){
   solve(k);
  k++;
  }
   return 0;
   }


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int a, b, c; cin >> a >> b >> c;
        set<int> s;
        s.insert(a);
        s.insert(b);
        s.insert(c);
        cout << (s.size() == 2 ? "Yes" : "No") << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

using namespace std;
typedef long long ll;

ll memo[110][100100];
ll N, W, w[100100], v[100100];
const ll INF = 1e18 + 10;
ll dp(ll n, ll we) {
	if (n < 0) return -INF;
	if (we < 0) return -INF;
	if (n == 0) return 0;
	ll &ans = memo[n][we];
	if (ans != -1) return ans;

	ans = max(0LL, max(dp(n - 1, we), dp(n - 1, we - w[n]) + v[n]));

	return ans;
}
int main() {
	memset(memo, -1, sizeof memo);
	cin >> N >> W;
	for (ll i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}

	cout << dp(N, W) << endl;
	return 0;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

#define M 100010


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	
   	int x;cin>>x;
   	cout<<!x;
   	
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 1e5;

void solve() {
  int n;
  scanf("%d", &n);
  std::vector<int> rocks(n);
  for (auto& _ : rocks) {
    scanf("%d", &_);
  }
  int dp[MAXN] = {};
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    int cost_2 = INT32_MAX;
    int cost_1 = abs(rocks[i - 1] - rocks[i]) + dp[i - 1];
    if (i != 1) {
      cost_2 = abs(rocks[i - 2] - rocks[i]) + dp[i - 2];
    }
    dp[i] = std::min(cost_1, cost_2);
    // 4
    // 10 30 40 20
    // 0  20 30 30
  }
  printf("%d\n", dp[n - 1]);
}

void warp() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
}
int main() {
  warp();
  solve();
  return 0;
}


Measured memory_bytes: 4164
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

bool check (string S, string T, int k)
{
   corner(T.size() + k > S.size(),"Out of Size");
   bool check = 1;
   for (int i = 0; i < T.size(); i++)
   {
    if((S[k+i] == T[i] || S[k+i] == '?')^(true)) check = 0;
   }

   return check;
}

string fill(string S,string T,int k)
{
  string filled = S;
  for (int i = 0; i < T.size(); i++)
  {
    filled[k+i] = T[i];
  }
  for (int i = 0; i < S.size(); i++)
  {
    if(filled[i] == '?')filled[i] = 'a';
  }
  
  return filled;
}
void solve(void)
{   
  int X,Y,Z;
  cin>>X>>Y>>Z;
  X -=Z;
  cout<<X/(Y+Z)<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0 && w==0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0||i==h-1||j==0||j==w-1)cout<<"#";
                else cout<<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <stdio.h>

int main(void)
{
	int a,b,c=100000,d,e,f=10000,i;
	for(i=0;i<3;i++)
	{
		scanf("%d",&a);
	if(f>a)
	{
		f=a;
	}
	}
	for(i=0;i<2;i++)
	{
		scanf("%d",&b);
		if(c>b)
	{
		c=b;
	}
	}
	e=c+f-50;
	printf("%d\n",e);
	return 0;
}



Measured memory_bytes: 2108
<?php
$a = intval(fgets(STDIN));
$b = intval(fgets(STDIN));
$c = intval(fgets(STDIN));
$x = intval(fgets(STDIN));
$ans = 0;
for ($i = 0; $i <= $a; $i++) {
    for ($j = 0; $j <= $b; $j++) {
        for ($k = 0; $k <= $c; $k++) {
            $ammount = $i * 500 + $j * 100 + $k * 50;
            if ($ammount == $x) {
                $ans++;
            }
        }
    }
}
print $ans;
?>

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;

    int cost[101];
    int wt[101];
    ll dp[101][100001];
int main()
{
    fast;
    int n, w;
    cin>>n>>w;
    REP1(i, n) cin>>wt[i]>>cost[i];
    REP(i, n+1){
      REP(j, 100001){
        if(j==0) dp[i][j] = 0;
        else if(i==0) dp[i][j] = INT_MAX;
        else{
          if(j>=cost[i]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-cost[i]] + wt[i]);
          else dp[i][j] = dp[i-1][j];
        }
      }
    }
    ll ans = 0;
    REP(i, 100001) if(dp[n][i]<=w) ans = i;
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 82504
s = raw_input()
tx, ty = map(int, raw_input().split())
xs, ys = [], []
for i, l in enumerate(map(len, s.split("T"))):
    if i % 2 == 0:
        xs.append(l)
    else:
        ys.append(l)
tx -= xs[0]
xs.pop(0)
xs = sorted(xs)[::-1]
ys = sorted(ys)[::-1]
for x in xs:
    tx += (2*(tx < 0) - 1) * x
for y in ys:
    ty += (2*(ty < 0) - 1) * y
print "Yes" if ((tx == 0) and (ty == 0)) else "No"

Measured memory_bytes: 2820
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  string s;
  cin >> s;
  for (int bit = 0; bit < 8; ++bit) {
    int a = s[0] - '0';
    for (int i = 0; i < 3; ++i) {
      if (bit & 1 << i) a += s[i + 1] - '0';
      else a -= s[i + 1] - '0';
    }
    if (a == 7) {
      for (int i = 0; i < 3; ++i) cout << s[i] << ((bit & 1 << i) ? '+' : '-');
      cout << s[3] << "=7" << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;


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

	int count = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			int k = S - i - j;
			if (0 <= k && k <= K)
				count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
     using namespace std;
         
        int main(){
            long long int N,K;
           cin >> K >> N;
            vector<long long int> V(N,0);
            vector<long long int>D(N,0);
            for( int i=0;i<N;i++){
                cin>>V[i];
            }
         
            for (int i=0;i<N-1;i++){
                D[i] = V[i+1]-V[i];
            }
            D[N-1] = K - (V[N-1]-V[0]);
           cout<<K - *max_element(D.begin(),D.end())<<std::endl;
            return 0;
        }

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
     
long long n,x,result,h,w;
 
int main(){
	cin>>n>>x;
	result=n;
	h=n-x;
	w=x;
	while(true){
		if(h>w){
			if(h%w==0){
				result+=(h/w*2-1)*w;
				break;
			}
			result+=(h/w*2)*w;
			h%=w;
		}
		else if(h<w){
			if(w%h==0){
				result+=(w/h*2-1)*h;
				break;
			}
			result+=(w/h*2)*h;
			w%=h;
		}
		else{
			result+=h;
			break;
		}
	}
	cout<<result<<endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC159D2
//
#include <iostream>
#include<vector>
using namespace std;
int main()
{
    long long N; // ボールの数
    cin >> N;
    vector<long long>A(N+1); // ボールに書かれている整数
    vector<long long>d(200001); // d(0)~d(200000)まで
    for (int i = 1; i <= N; i++)
    {
        cin >> A.at(i);
        d.at(A.at(i))++; // 各数値のボールが何個あるか
    }
    long long all = 0;
    for (int j = 1; j <= 200000; j++)
    {
        if (d.at(j)>1) // ボールが２個以上
        {
            long long cmb = d.at(j)*(d.at(j)-1)/2; // 同じ数値から２個取る組合せの数
            all += cmb;
        }
    }
    //  k番目のボールを除いたとき、減る組合せの数
    for (int k = 1; k <= N; k++)
    {
        long long before=0;
        long long after=0;
        if (d.at(A.at(k))>1)
        {
            before=d.at(A.at(k))*(d.at(A.at(k))-1)/2;
            after=(d.at(A.at(k))-1)*(d.at(A.at(k))-2)/2;
        }
        cout << all - before + after << endl;
    }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i,N){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    ll sum=0;
    rep(i,A){
        sum+=v[i];
    }
    double ave=(double)sum/A;
    cout << fixed << setprecision(6);
    cout << ave << endl;
    ll count=0,s=-1;
    rep(i,N){
        if (v[i]==v[A-1]){
            count++;
            if (s==-1){
                s=i;
            }
        }
    }
    ll ans=0,c=1;
    if (v[A-1]!=ave){
        ans=1;
        for (int i=1;i<=A-s;i++){
            ans*=count-i+1;
            ans/=i;
        }
    }
    else {
        for (int i=1;i<=min(count,B);i++){
            c*=count-i+1;
            c/=i;
            if (i>=A){
                ans+=c;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N , M;
int mini = 0, maxi = 1 << 30;
int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int L, R;
        cin >> L >> R;
        mini = max(mini, L);
        maxi = min(maxi, R);
    }
    cout << max(maxi - mini + 1, 0) << endl;
    return 0;
}

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

#define endl "\n"
#define INF 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int32_t main() { fastio;
    time_t start = now();

    int n, r;
    cin >> n >> r;
    if (n < 10) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner (System.in);
		int num = scan.nextInt();

		int[] [] []   officialHouse = new int[4] [3] [10];

		int building = 0;
		int floor = 0;
		int roomNumber = 0;
		int residents = 0;

		for (int i = 0; i < num; i++) {
			building = scan.nextInt();
			floor = scan.nextInt();
			roomNumber = scan.nextInt();
			residents = scan.nextInt();

			officialHouse[building - 1] [floor - 1] [roomNumber - 1] += residents;

		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + officialHouse [i] [j] [k]);
				}
				System.out.println();
				if (j == 3) {
					break;
				}

			}
			if (i == 3) {
				break;
			}
			System.out.println("####################");
		}
		scan.close();
	}
}

Measured memory_bytes: 29724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
        // 3つの文字の固まりをそれぞれ整数値と想定して読み込む
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.printf("%d %d %d\n", a, b, c);
            } else if (c < a) {
                System.out.printf("%d %d %d\n", c, a, b);
            } else {
                System.out.printf("%d %d %d\n", a, c, b);
            }
        } else {
            if (a < c) {
                System.out.printf("%d %d %d\n", b, a, c);
            } else if (c < b) {
                System.out.printf("%d %d %d\n", c, b, a);
            } else {
                System.out.printf("%d %d %d\n", b, c, a);
            }
        }
    }
}


Measured memory_bytes: 26392
dst = []

def CWDist( s, e, n ) : return (e - s + n)%n
def CCWDist( s, e, n ) : return (s - e + n)%n
def CWNext( i, m ) : return dst[0] if i == m-1 else dst[i+1]
def CCWNext( i, m ) : return dst[m-1] if i == 0 else dst[i-1]
def CWTurn( p, t, e, n ) : return CWDist( p, t, n ) + CCWDist( t, e, n )
def CCWTurn( p, t, e, n ) : return CCWDist( p, t, n ) + CWDist( t, e, n )

n,m,p = map(int, input().split())
for i in range(m) :
    dst.append( int(input()) )
dst.sort()

s = 0
while s < m :
    if dst[s] > p : break
    s += 1

cwNext = dst[0] if s == m else dst[s]
ccwNext = dst[m-1] if s == 0 else dst[s-1]
dist = min( CCWDist(p, cwNext, n), CWDist(p, ccwNext, n) )
for i in range(m) :
    dist = min( dist, CWTurn(p, dst[i], CWNext(i,m), n), CCWTurn(p, dst[i], CCWNext(i,m), n) )
print(100*dist)
    



Measured memory_bytes: 6036
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	string S[200000];
	for (int i = 0; i < n; i++)
		cin >> S[i];
	
	sort(S, S + n);
	
	queue<string> q;
	int max = 2;
	for (int i = 0; i < n - 1; i++) {
		int cnt = 1;
		while (i < n - 1 and S[i] == S[i + 1]) {
			cnt++;
			if (cnt == max)
				q.push(S[i]);
			if (cnt == max + 1) {
				while(q.size())
					q.pop();
				q.push(S[i]);
			}
			i++;
		}
		if (cnt > max)
			max = cnt;
	}
	
	if (q.size() == 0)
		for (int i = 0; i < n; i++)
			cout << S[i] << endl;
	
	while (q.size() > 0) {
		cout << q.front() << endl;
		q.pop();
	}
}

Measured memory_bytes: 14208
require "set"

n, m = gets.split.map &:to_i
Room = Struct.new(:connected, :indicator)
rooms = n.times.map { Room[[], nil] }
rooms[0].indicator = 0

m.times do
  a, b = gets.split.map &:to_i
  rooms[a-1].connected << b-1
  rooms[b-1].connected << a-1
end

count = 1
q = [0]
until q.empty? or count == n
  i = q.shift
  rooms[i].connected.each do |j|
    if rooms[j].indicator.nil?
      rooms[j].indicator = i
      count += 1
      q << j
    end
  end
end

if count == n
  puts "Yes"
  (1...n).each do |i| p rooms[i].indicator+1 end
else
  puts "No"
end

Measured memory_bytes: 45916
def nCr(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

x, y = map(int, input().split())

if max(x, y) > 2 * min(x, y) or (x+y) % 3 != 0:
    print(0)
else:
    n = (x + y) // 3
    r = 2 * n - x
    print(nCr(n, r))

Measured memory_bytes: 3064
#include <stdio.h>
void output(int *,int);
int main(){
  int i,j,n,cnt=0;
  int min,hozon,han=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(a[j]<a[min]){
	min=j;
	han=1;
      }
    }
    if(han==1){
      hozon=a[i];
      a[i]=a[min];
      a[min]=hozon;
      cnt++;
      han=0;
    }
  }
  output(a,n);
  printf("%d\n",cnt);
  return 0;
}
void output(int *a,int n){
  int i,j;
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++)  cin >> R[i];
    int maxv = -9999999999;
    int minv = R[0];
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3868
// Crt. 2019-12-24  17:05:33
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;

int n, a[100005];

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);

    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);

    int pos = 0, tmp1, tmp2 = 0;
    while (pos < n && a[pos + 1] >= pos + 1) ++pos;

    tmp1 = (a[pos] - pos) & 1;

    for (int i = pos + 1; i <= n; ++i) tmp2 += a[i] == pos;

    tmp2 &= 1;

    puts(tmp1 or tmp2 ? "First" : "Second");

    return 0;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll chmax(ll &a, ll b){ return a = (a>b) ? a : b;}
ll chmin(ll &a, ll b){ return a = (a<b) ? a : b;}


////////////////////////////////////////////////////////////////
#define PI 3.14159265359
int main(void) {
	int N, K;
	cin >> N >> K;
	vector<int> h(N+105, 0);
	for(int i=0; i<N; i++) cin >> h[i];

	vector<ll> dp(N+105, INF);
	dp[0] = 0;// dp[i]: 足場iに行くのにかかる最小コスト

	for(int i=0; i<=N; i++){
		//chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
		//chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
		//dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));//chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
		//dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));//chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));

		for(int k=1; k<=K; k++){
			dp[i+k] = min(dp[i+k], dp[i] + abs(h[i] - h[i+k]));
		}
	}
	

	cout << dp[N-1] << endl;


}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
    ll x;
    scanf("%lld",&x);
    ll ans = x/500*1000;
    x-=x/500*500;
    ans+=x/5*5;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
         
         
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
        int n,m,t;
        vector<pair<int,int>> mat[5001];
        vector<pair<int,int>> ulta[5001];
        int32_t main()
        {
            IOS
        
            
        int n,h;
        cin>>n>>h;
        vector<pair<int,int>>v;
        for(int i=0;i<n;++i)
        {
            int a,b;
            cin>>a>>b;
            v.push_back({a,b});
        }
        sort(v.begin(),v.end());
        if(v[n-1].second>=h)
        {
            cout<<1;return 0;

        }
        vector<pair<int,int>>v1;
        for(int i=0;i<v.size()-1;++i)
        {
            v1.push_back({v[i].second,v[i].first});
        }
        sort(v1.begin(),v1.end());
        int cost=0;
        for(int i=v1.size()-1;i>=0;--i)
        {
            if(h<=v[n-1].second)
            {
                cost++;
                cout<<cost;
                return 0;
            }
            if(v1[i].first>v[n-1].first)
            {
                h-=v1[i].first;
                cost++;
                if(h<=0)
                    break;
            }
        }
        if(h<=0)
        {
            cout<<cost;
            return 0;
        }
        if(v[n-1].first>=v[n-1].second)
        {
            cout<<cost+(h+v[n-1].first-1)/v[n-1].first;
            return 0;
        }
        else
        {
            cost++;
            h-=v[n-1].second;
            cout<<cost+(h+v[n-1].first-1)/v[n-1].first;

        }




    }



Measured memory_bytes: 5104
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
l = N - 1
w = M - 1
ans = l * w
print(ans)

Measured memory_bytes: 5144