akhauriyash/Code-Regression huggingface dataset:
//file_name:ABC63_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n,m;
    scanf("%d%d",&n,&m);


    ll ans = n+m;

    if(ans>9){
        puts("error");
        return 0;
    }

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



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;
	if((A>=1)&&(A<=13)&&(B>=1)&&(B<=13))
	{
		if(A==B)
		printf("Draw");
		if((A==1)&&(B!=A))
		printf("Alice");
		else if((B==1)&&(A!=B))
		printf("Bob");
		if((A>B)&&(B!=1))
			printf("Alice");
			else if((B>A)&&(A!=1))
				printf("Bob");}
			
		
		
		
	
}
	
	
	
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=5e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,a[N],cnt=0;
char s[N];
int main() {
    scanf("%s",s+1);n=strlen(s+1);
    reverse(s+1,s+n+1);
    for(int i=1;i<=n;i++) a[i]=s[i]-'0';
    for(int i=1,t=0;i<=n;i++) {
        t+=a[i]*9;a[i]=t%10;t/=10;cnt+=a[i];
        if(t&&i==n) n++;
    }
    for(int k=1;;k++) {
        for(int i=1,t=9;i<=n;i++) {
            t+=a[i];cnt-=a[i];a[i]=t%10;cnt+=a[i];t/=10;
            if(!t) break; if(i==n) n++;
        }
        if(cnt<=9*k) return printf("%d\n",k),0;
    }
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, r, u, v, w, d[202][202] = {}, a[8] = {}, z = mod;
    cin >> n >> m >> r;
    for (int i = 0; i < r; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) d[i][j] = mod;
    while (m--) cin >> u >> v >> w, d[u][v] = d[v][u] = w;
    for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    for (int i = 0; i < 40320; i++) {
        int c = 0;
        for (int j = 1; j < r; j++) c += d[a[j]][a[j - 1]];
        z = min(z, c);
        next_permutation(a, a + r);
    }
    cout << z;
}


Measured memory_bytes: 384
/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>

class job{
public:
  long long int delay, pay;
  
  job(long long int d, long long int p){
    delay = d;
    pay = p;
  }
  
  const bool operator < (const class job &another) const{
    if(delay == another.delay){
      return pay > another.pay;
    }
    else{
      return delay < another.delay;
    }
  }
};

int main(){
  
  long long int N, M;
  scanf("%lld%lld", &N, &M);
  
  long long int A, B;
  std::vector<class job> job_list;
  
  for(int i = 0; i < N; i++){
    scanf("%lld%lld", &A, &B);
    job_list.push_back(job(A, B));
  }
  
  std::sort(job_list.begin(), job_list.end(), std::less<class job>());
  
  for(int i = 0; i < N; i++){
    std::cerr << job_list[i].delay << " " << job_list[i].pay << std::endl;
  }
  
  long long int tmp=0;
  long long int ans = 0;
  long long int pay_tmp;
  std::priority_queue<long long int> que;
  
  for(int i = 0; i < M; i++){
    // push all possible jobs
    while(job_list[tmp].delay <= i+1 && tmp < N){
      que.push(job_list[tmp].pay);
      tmp++;
    }
    if(!que.empty()){
      pay_tmp = que.top();
      que.pop();
      ans += pay_tmp;
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;
  
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std ;
int n ;
struct point
{
	double x , y ;
} p[55] ;
int row[4] = {-1 , 1 , 0 , 0} ;
int col[4] = {0 , 0 , -1 , 1} ;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
double len(point a , point b)
{
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) ;
}
double cal(point a)
{
	double Max = 0.0 ;
	for(int i = 1 ; i <= n ; i ++)
	  Max = max(Max , len(a , p[i])) ;
	return Max ;
}
double random1()
{
	return double(rnd() % 1000000) / 1000000.0 ;
}
double solve(double delta)
{
	int i ;
	point ans , next ;
	point now ;
	for(int i = 1 ; i <= n ; i ++)
	  ans.x += p[i].x / double(n) , ans.y += p[i].y / double(n) ;
	double t = 100  ;
	//double delta = 0.976 ;
	double dE ;
	double ans1 ;
	double inf = 1000000000 ;
	while(t > 1e-14)
	{
		ans1 = inf ;
		for(i = 0 ; i < 4 ; i ++)
		{
		   next.x = ans.x + row[i] * t ;
		   next.y = ans.y + col[i] * t ;
		   if(cal(next) < ans1)
		   {
		   	 ans1 = cal(next) ;
		   	 now = next ;
		   }		   	 
		}
		dE = cal(now) - cal(ans) ;
		if(dE < 0.0 || exp(dE / t) > random1())
		{
			ans = now ;
		}
		t *= delta ;
	}
	return cal(ans) ;
	//printf("%.12f" , cal(ans)) ;
}
int main()
{
	scanf("%d" , &n) ;
	for(int i = 1 ; i <= n ; i ++)
	  scanf("%lf%lf" , &p[i].x , &p[i].y) ;
	//solve() ;
	double ans = 10000000.0 , temp ;
	for(double delta = 0.90 ; delta <= 0.999 ; delta += 0.001)
	{
		double t = solve(delta) ;
		if(t < ans)
	    {
	  	  ans = t ;
	  	  temp = delta ;
	    }
	    //if(delta >= 0.90 && delta <= 0.99)  
		  //printf("%.12f %.12f\n" , delta , t) ;
	}
	  
	printf("%.12f\n" , ans) ;
	//printf("%.12f %.12f\n" , ans , temp) ;
	return 0 ; 
}


Measured memory_bytes: 768
#import time

def main():
    X = int(input())
    #print(isprime(int((9**5-5**5)/4)))
    lis = [[ [] for _ in range(240)] for _ in range(240)]
    ansA, ansB = 0, 0
    #print(type(ansA), ansB)
    for i in range (240):
        for j in range(240):
            lis[i][j].append(i-120)
            lis[i][j].append(j-120)
    
    for i in range(240):
        for j in range(240):
            A, B = lis[i][j]
            if A**5 - B**5 == X:
                ansA, ansB = A, B
                break
        else: #普通に終わったら実行される、breakならされない
            continue
        break #外側


    print(ansA, ansB)


if __name__ == '__main__':
    #start = time.time()
    main()
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

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

int main(void) {
    string s;
    cin >> s;
    int n = (int)s.size();
    int f;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'A') {
            f = i;
            break;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (s.at(i) == 'Z') {
            cout << i - f + 1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3780
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let mut v: Vec<usize> = get!([usize]);
    let mut odd_num = 0;
    for i in 0..v.len() {
        if v[i] & 1 == 1 {
            odd_num += 1;
        }
    }
    let mut ans = 0;
    if odd_num == 1 {
        ans += 1;
        for i in 0..v.len() {
            if v[i] & 1 == 0 {
                v[i] += 1;
            }
        }
    } else if odd_num == 2 {
        ans += 1;
        for i in 0..v.len() {
            if v[i] & 1 == 1 {
                v[i] += 1;
            }
        }
    }
    v.sort();
    let biggest = v[2];
    let middle = v[1];
    let smallest = v[0];
    ans += biggest - middle;
    ans += (biggest - ((biggest - middle) + smallest)) / 2;
    println!("{}", ans);
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, X; cin >> N >> X;
	int mi = 1e8;
	for (int i = 0; i < N; i++) {
		int v; cin >> v;
		mi = min(mi, v);
		X -= v;
	}
	int ans = N + X / mi;
	cout << ans << '\n';

	return 0;
}


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

sum = 0
for i in range(1, n, 1):
    if heights[i] < heights[i-1]:
        sum += (heights[i-1] - heights[i])
        heights[i] += (heights[i-1] - heights[i])

print(sum)

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

using namespace std;

int main()
{
  string s;
  cin>>s;
  set<char> s1;
  s1.insert(s[0]);
  s1.insert(s[1]);
  s1.insert(s[2]);
  s1.insert(s[3]);
  if(s1.size()==2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
def resolve():

    S=str(input())[::-1]
    flag='YES'
    i=0

    while i<len(S):
        if S[i:i+5]=='maerd' or S[i:i+5]=='esare':
            i+=5
            continue
        if S[i:i+6]=='resare':
            i+=6
            continue
        if S[i:i+7]=='remaerd':
            i+=7
        else:
            flag='NO'
            break

    print(flag)









resolve()

Measured memory_bytes: 40560
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int a,b;
    cin>>a>>b;
    int d=b-a;
    int s=0;
    FORIN(i,1,d){
        s+=i;
    }
    cout<<s-a<<endl;
    return 0;
}

Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function mkdivisor(n::Int)
  divisors=Int[]
  for i=1:div(n^0.5,1)
    if n%i==0
      push!(divisors,i)
      if i!= fld(n,i); push!(divisors,fld(n,i));end
    end
  end
  sort!(divisors)
  return divisors
end
function main()
  x=pI(readline())
  l=mkdivisor(x)
  ll=[(i,i-j) for i=1:200 for j=l]
  for k in ll
    i,j=k
    if i^5-j^5==x
      print(i," ",j)
      break
    end
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 195252
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int n;cin>>n;
	double x1,x2,x3,y1,y2,y3,x12,x13,y12,y13,xx12,yy12,xx13,yy13,x,y,r;
	for(int i=0;i<n;i++)
	{
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
		
		x12=x1-x2;
		x13=x1-x3;
		y12=y1-y2;
		y13=y1-y3;
		xx12=x1*x1-x2*x2;
		xx13=x1*x1-x3*x3;
		yy12=y1*y1-y2*y2;
		yy13=y1*y1-y3*y3;
		
		x=-0.5*(y12*(xx13+yy13)-y13*(xx12+yy12))/(x12*y13-x13*y12);
		y=-0.5*(x12*(xx13+yy13)-x13*(xx12+yy12))/(y12*x13-y13*x12);
		r=sqrt(x*x+y*y+x1*x1+y1*y1-2*x*x1-2*y*y1);
		
		printf("%.3lf %.3lf %.3lf\n",x,y,r);
		
	}
	return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;

//Class
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double x = sc.nextDouble();
			System.out.println(x<=48?"light fly":
				x<=51?"fly":
				x<=54?"bantam":
				x<=57?"feather":
				x<=60?"light":
				x<=64?"light welter":
				x<=69?"welter":
				x<=75?"light middle":
				x<=81?"middle":
				x<=91?"light heavy":"heavy");
		}
	}
}

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

using namespace std;
int q;
struct point
{
    double x;
    double y;
};
point vt(point a,point b)
{
    point vt;
    vt.x=b.x-a.x;
    vt.y=b.y-a.y;
    return vt;
}
double scalar(point a,point b)
{
    double scalar=0;
    scalar=sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
    return scalar;
}
double mul1(point a,point b)
{
    double mul=a.x*b.x+a.y*b.y;
    return mul;
}
point mul2(point a,double b)
{
    point c;
    c.x=a.x*b;
    c.y=a.y*b;
    if (c.x==-0) c.x=0;
    if (c.y==-0) c.y=0;
    return c;
}
int main()
{
    point p1,p2;
    cin>>p1.x>>p1.y;
    cin>>p2.x>>p2.y;
    cin>>q;
    while (q--)
    {
        point p;
        cin>>p.x>>p.y;
        point v=vt(p1,p);
        point u=vt(p1,p2);
        //cout<<v.x<< " "<<v.y<<endl;
        //cout<<u.x<< " "<<u.y<<endl;
        double su=scalar(p1,p2);
        //cout<<su<<endl;
        point ans;
        ans=mul2(u,mul1(u,v)/(su*su));
        point x1;
        x1.x=ans.x+p1.x;
        x1.y=ans.y+p1.y;
        point px1=vt(p,x1);
        px1=mul2(px1,2);
        cout<<setprecision(10)<<fixed<<px1.x+p.x<<" "<<px1.y+p.y<<endl;
    }
    return 0;
}



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

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

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> ab(n);
  rep(i,n)ab[i]=0;
  int result = 0, max_g=0;

  rep(i,n){
    int a,b;cin>>a>>b;
    if(a<max_g)continue;
    max_g=a;
    result = a+b;
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    string s;
    cin >> s;
    int r = 0;
    FOR(i,s) {
        if (*i == '1') r++;
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
 string A,B;
 cin>>A;
 cin>>B;
 if(A.length()>B.length()){
     cout<<"GREATER"<<endl;
 }
 else if (A.length()<B.length()){
     cout<<"LESS"<<endl;
 }
 else {
     if(A>B){
         cout<<"GREATER"<<endl;
     }
     else if(A<B){
         cout<<"LESS"<<endl;
     }
     else {
         cout<<"EQUAL"<<endl;
     }
 }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>



using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int A, B, C;
  cin >> A >> B >> C;
  int N = (A<B)?B:A;
  N = (N<C)?C:N;
  int sum = 3*N-A-B-C;
  if (sum %2 == 0) {
    printf("%d\n", sum/2);
  } else {
    printf("%d\n", (sum+3)/2);
  }

  return 0;
}


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

int main() {
  int N;
  int sum = 0;
  int l, r;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, c;
  cin>>a>>b>>c;
  if(b-a==c-b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    mod = 10**9+7
    loop = [0 for i in range(n)]
    t = [0 for i in range(n)]
    for i in range(n-1):
        for j in range(i,n):
            if a[i]>a[j]:
                loop[i] += 1
    for i in range(n):
        for j in range(n):
            if a[i]>a[j]:
                t[i] += 1
    s = (sum(loop) * k) % mod
    s += (sum(t) * (k * (k-1) //2)) % mod
    print(s%mod)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        byte a[][] = new byte[h][w];
        for(int i = 0; i < h; i++){
        	String s = sc.next();
        	byte sb[] = s.getBytes();
        	for (int j = 0; j < w; j++){
        		a[i][j] = sb[j];
        	}
        }

        int depth[][] = new int[h][w];
        Deque<Integer> q = new ArrayDeque<Integer>();
        for(int i = 0; i < h; i++){
        	for(int j = 0; j < w; j++){
                if (a[i][j] == (byte)('#') ){
                	depth[i][j] = 0;
                	q.addLast(i * 1000 + j);
                }
        	}
        }
        while(! q.isEmpty()){
        	Integer r = q.removeFirst();
        	int i = r / 1000;
        	int j = r % 1000;
        	if (i > 0 && a[i-1][j] == (byte)('.') && depth[i-1][j] == 0){
        		depth[i-1][j] = depth[i][j] + 1;
        		q.addLast(i * 1000 - 1000 + j);
        	}
        	if (i < h-1 && a[i+1][j] == (byte)('.') && depth[i+1][j] == 0){
        		depth[i+1][j] = depth[i][j] + 1;
        		q.addLast(i * 1000 + 1000 + j);
        	}
        	if (j > 0 && a[i][j-1] == (byte)('.') && depth[i][j-1] == 0){
        		depth[i][j-1] = depth[i][j] + 1;
        		q.addLast(i * 1000 + j - 1);
        	}
        	if (j < w-1 && a[i][j+1] == (byte)('.') && depth[i][j+1] == 0){
        		depth[i][j+1] = depth[i][j] + 1;
        		q.addLast(i * 1000 + j + 1);
        	}
        }
        int ret = 0;
        for(int i = 0; i < h; i++){
        	for(int j = 0; j < w; j++){
        		if (ret < depth[i][j]) ret = depth[i][j];
        	}
    	}
        System.out.println(ret);
	}
}


Measured memory_bytes: 62220
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const S = input[0]
  const T = input[1]
  let ans = 0
  for (let i = 0; i < S.length; i++) {
    if (S[i] == T[i]) {
      ans++
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 1;
  rep(i,n) ans = min(2*ans,ans+k);
  cout << ans << endl;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
n = int(input())
if n == 1:
  ans = 0
else:
  ans = 0
  a = factorization(n)
  for j in a:
    t = j[1]
    if t <= 2:
      ans += 1
    elif t <= 5:
      ans += 2
    elif t <= 9:
      ans += 3
    elif t <= 14:
      ans += 4
    elif t <= 20:
      ans += 5
    elif t <= 27:
      ans += 6
    elif t <= 35:
      ans += 7
    else:
      ans += 8
print(ans)

Measured memory_bytes: 9508
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
//const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
vector<ll> a;
ll memo[3300][3300][3];
ll MOD = 998244353;
ll rec(ll i, ll j, ll state){
    if(i == -1){
        if(j == 0 && (state == 0 || state == 1)){
            return 1;
        } else {
            return 0;
        }
    }

    if(memo[i][j][state] != -1) return memo[i][j][state];

    ll res = 0;
    if(state == 2){
        if(j - a[i] >= 0) res += rec(i - 1, j - a[i], 1);
        res %= MOD;
        res += rec(i - 1, j, 1);
        res %= MOD;
    }
    if(state == 1){
        if(j - a[i] >= 0) res += rec(i - 1, j - a[i], state);
        res %= MOD;
        res += rec(i - 1, j, 0);
        res %= MOD;
    }

    res += rec(i - 1, j, state);
    res %= MOD;

    return memo[i][j][state] = res;
} 
int main(void){
    ll n, s;
    cin >> n >> s;
    a.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, 3300){
        rep(j, 3300){
            rep(k, 3){
                memo[i][j][k] = -1;
            }
        }
    }

    cout << rec(n - 1, s, 2) << endl;
}


Measured memory_bytes: 255616
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<long long> a;

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int tmp = 0;
        while (a[i] % 2 == 0) {
            tmp++;
            a[i] /= 2;
        }
        ans += tmp;
    }
    cout << ans << endl;
}


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

int main() {
  string S; int Q; cin >> S >> Q;
  int N = S.size();
  list<char> s_list;
  for (int i = 0; i < N; i++) s_list.push_back(S[i]);
  bool rev = false;
  int t, f; char c;
  for (int i = 0; i < Q; i++) {
    cin >> t;
    if (t == 1) rev = !rev;
    else {
      cin >> f >> c;
      if ((f == 1 && !rev) || (f == 2 && rev)) s_list.push_front(c);
      else s_list.push_back(c);
    }
  }
  string res;
  for (auto it = s_list.begin(); it != s_list.end(); it++)
    res.push_back(*it);
  if (rev) reverse(res.begin(), res.end());
  cout << res << endl;
}

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

vector<ll> divisor(ll x) {
    vector<ll> ret;
    for (ll i=1; i*i<=x; ++i) {
        if (x%i == 0) {
            ret.push_back(i);
            if (i != x/i) ret.push_back(x/i);
        }
    }
    return ret;
}

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

    vector<ll> A(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    ll ans = 1;
    vector<ll> tmp = divisor(sum);
    vector<ll> r(N);
    for (ll d : tmp) {
        bool ok = true;
        ll rsum = 0;
        rep(i, N) {
            r[i] = A[i] % d;
            rsum += r[i];
        }
        sort(r.rbegin(), r.rend());

        if (rsum / d > K) continue;

        ll k = 0;
        rep(i, rsum/d) {
            k += d - r[i];
        }

        if (k <= K) {
            ans = max(ans, d);
        }
    }

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


Measured memory_bytes: 256
N,K = map(int, input().split())
H = [int(h) for h in input().split()]

dp = [[10**13]*N for _ in range(N)]
dp[0][0] = H[0]
    
for i in range(1, N):
    for j in range(i+1):
        if j == 0:
            dp[i][j] = H[i]
            continue
        for k in range(i):
            dp[i][j] = min(dp[i][j], dp[k][j-1]+max(0, H[i]-H[k]))
            
if N == K:
    ans = 0
else:
    ans = 10**13
    for i in range(N):
        ans = min(ans, dp[i][N-K-1])
        
print(ans)

Measured memory_bytes: 43244
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
int main(){
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    while(m--){
        ll i;
        cin>>i;
        sum+=i;
    }
    if(sum>n)cout<<"-1"<<endl;
    else{
        cout<<n-sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
        ll x,a,b,end=0,i,j,k;
        cin>>x;
        for(i=200;i>=-200;i--){
                for(j=200;j>=-200;j--){
                        if(((i*i*i*i*i)-(j*j*j*j*j))==x){
                                end=1;
                                a=i,b=j;
                                break;
                        }
                }
                if(end==1){
                        break;
                }
        }

        cout<<a<<" "<<b<<endl;
        return 0;
}


Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List <Integer> H = new ArrayList <Integer> ();
		List <Integer> W = new ArrayList <Integer> ();
		
		int lastH = 0;
		int lastW = 0;
		do {
			lastH = stdIn.nextInt();
			lastW = stdIn.nextInt();
			
			H.add(lastH);
			W.add(lastW);
		} while (lastH != 0 || lastW != 0);
		
		for(int i = 0; i < H.size()-1; i++) {
			for(int j = 0; j < H.get(i); j++) {
				for(int k = 0; k < W.get(i); k++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}

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

int main() {
  int n;
  string s;
  vector<int> a(n);
  long long ans=1;
  cin>>n;
  cin>>s;
  rep(i,n){
    if(s.at(i)=='R')a.at(i)=0;
    if(s.at(i)=='G')a.at(i)=1;
    if(s.at(i)=='B')a.at(i)=2;    
  }
  vector<long long> cnt(3);
  rep(i,n) cnt.at(a.at(i))++;
  rep(i,3) ans*=cnt.at(i);
  rep(j,n)rep(i,j){
    int k=j+(j-i);
    if(k<n){
      if(a.at(i)==a.at(j))continue;
      if(a.at(i)==a.at(k))continue;
      if(a.at(k)==a.at(j))continue;
      ans--;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3756
class Combination:
    def __init__(self, n_max, mod=10 ** 9 + 7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max + 1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod - 2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nCr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod


def resolve():
    def f(r, c):
        return cmb.nCr(r + c, r)

    MOD = 10 ** 9 + 7
    r1, c1, r2, c2 = map(int, input().split())
    r2 += 1
    c2 += 1
    cmb = Combination(r2 + c2 + 5)

    ans = f(r2, c2)
    ans -= f(r1, c2)
    ans -= f(r2, c1)
    ans += f(r1, c1)
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 167240
#include<bits/stdc++.h>
using namespace std;
int main(){
    int flag = 1,N,count = 0;
    cin >> N;
    vector<int> list(N);
    for(int i = 0; i < N; i++)
{
    cin >> list[i];
}
    while(flag){
        flag = 0;
        for(int i = N - 1; i > 0; i--){
            if(list[i] < list[i - 1]){
                int b = list[i];
                int c = list[i - 1];
               list[i - 1] = b;
               list[i] = c;
                    flag = 1;  
            count++;     }
        
        }
    }
    for(int i = 0; i < N; i++){
        if(i < N - 1)
        cout << list[i] << " ";
        if(i  == N - 1)
        cout << list[i];
    }
    cout << endl;
    cout << count << endl;
}


Measured memory_bytes: 3092
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	int[] a;
	public void solve() {
		N = nextInt();
		M = nextInt();

		a = new int[N];

		for(int i = 0;i < M;i++){
			a[i] = nextInt();
		}
		boolean[] b = new boolean[N * 2 - 1];
		Arrays.fill(b,true);
		for(int i = 0;i < M;i++){
			b[a[i]+N-1] = false;
		}

		for(int i = N*2-2;i > 0;i-=2){
			if(b[i] && b[i-1])b[(i-2)/2] = true;
			else if(b[i] || b[i-1])b[(i-2)/2] = true;
			else b[(i-2)/2] = false;
		}

		int ans = 0;
		for(int i = 0;i < N-1;i++){
			if(b[i*2+1] && b[i*2+2])ans++;
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24392
#include <iostream>
using namespace std;
bool isPrime (int);

int main()
{
    int X, i;

    cin>>X;
    for (i=X; !isPrime(i); i++);
    cout<<i;
    return 0;
}

bool isPrime (int a)
{
    int counter=0;
    for (int i=2; i<=a/2; i++)
        if(a%i==0)
            counter++;

    if (counter==0)
        return true;
    else
        return false;
}


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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        string S;
        cin >>S;
        if ("RRR"==S)
                cout <<3 <<endl;
        else if ("RRS"==S)
                cout <<2 <<endl;
        else if ("SRR"==S)
                cout <<2 <<endl;
        else if ("SSS"==S)
                cout <<0 <<endl;
        else
                cout <<1 <<endl;
        return 0;
}


Measured memory_bytes: 3620
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
	//try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
    	PrintWriter out = new PrintWriter(outputStream);

        int i, n, m, k;

		n = Integer.parseInt(br.readLine());
      	int[] a = new int[n+1];
      	int[] b = new int[n+1];
      	int[] c = new int[n];
      StringTokenizer st = new StringTokenizer(br.readLine());
      for(i=1;i<=n;i++)
      	a[i]=Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      for(i=1;i<=n;i++)
      	b[i]=Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      for(i=1;i<n;i++)
      	c[i]=Integer.parseInt(st.nextToken());
	
      long sum=0;
      for(i=1;i<=n;i++)
      {
        sum+=b[a[i]];
        
        if(i-1>=0 && a[i-1]+1==a[i])
          	sum+=c[a[i-1]];
      }
      out.print(sum);
	out.flush();
	out.close();
	//}catch(Exception e){}
	}
}

Measured memory_bytes: 21972
N,x=map(int, input().split(' '))
a = list(map(int, input().split(' ')))
wa = [a[0]]+[a[i]+a[i+1] for i in range(N-1)]+[a[-1]]
ans = 0

for i in range(N):
    if wa[i] <= x:
        continue
    if wa[i] > x:
        dif = wa[i]-x
        ans += dif
        a[i] -= dif
        wa[i] -= dif
        wa[i+1] -= dif
        continue

if wa[-1] > x:
    ans += wa[-1]-x
    a[-1] = wa[-1]-x
    wa[-1] -= wa[-1]-x

print(ans)

Measured memory_bytes: 71132
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int x,y; cin >> x >> y;
    cout << GCD(x,y) << endl;
}
  




Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10)cout << "error" << endl;
	else cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

void solve() {
  ll n, m; cin >> n >> m;
  string s, t; cin >> s >> t;
  ll g = gcd(n, m);
  ll ans = n / g * m;
  n /= g; m /= g;
  for (ll i = 0; i < g; i++) {
    if (s[i*n] != t[i*m]) {
      outl(-1);
      return;
    }
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007



string S;
ll dp[100010][4];



int main() {
    cin >> S;
    ll len = S.size();
    rep(i,100010){
        rep(j,4) dp[i][j] = 0;
    }
    dp[0][0] = 1;
    repi(i,1,len+1){
        if (S[i-1] == 'A' || S[i-1] == '?'){
            dp[i][0] = (dp[i][0]+dp[i-1][0])%inf;
            dp[i][1] = (dp[i][1]+dp[i-1][1])%inf;
            dp[i][2] = (dp[i][2]+dp[i-1][2])%inf;
            dp[i][3] = (dp[i][3]+dp[i-1][3])%inf;
            dp[i][1] = (dp[i][1]+dp[i-1][0])%inf;
        }
        if (S[i-1] == 'B' || S[i-1] == '?'){
            dp[i][0] = (dp[i][0]+dp[i-1][0])%inf;
            dp[i][1] = (dp[i][1]+dp[i-1][1])%inf;
            dp[i][2] = (dp[i][2]+dp[i-1][2])%inf;
            dp[i][3] = (dp[i][3]+dp[i-1][3])%inf;
            dp[i][2] = (dp[i][2]+dp[i-1][1])%inf;
        }
        if (S[i-1] == 'C' || S[i-1] == '?'){
            dp[i][0] = (dp[i][0]+dp[i-1][0])%inf;
            dp[i][1] = (dp[i][1]+dp[i-1][1])%inf;
            dp[i][2] = (dp[i][2]+dp[i-1][2])%inf;
            dp[i][3] = (dp[i][3]+dp[i-1][3])%inf;
            dp[i][3] = (dp[i][3]+dp[i-1][2])%inf;
        }
    }
    cout << dp[len][3]%inf << endl;
 
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, k, noneed = -1, need;
    vector<int> a;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        if(t < k)a.push_back(t);
    }
    n = a.size();
    sort(a.begin(), a.end());
    need = n;
    while(noneed + 1 < need){
        int mid = (noneed + need) / 2;
        vector<int> b;
        vector< vector<bool> > dp;
        for(int i=0;i<n;i++){
            if(i != mid){
                b.push_back(a[i]);
            }
        }
        dp.assign(2, vector<bool>());
        dp[0].assign(k+1, false);
        dp[1].assign(k+1, false);
        dp[1][0] = true;
        for(int i=0;i<n-1;i++){
            for(int j=0;j<=k;j++){
                dp[i%2][j] = dp[(i+1)%2][j];
                if(j-b[i]>=0)dp[i%2][j] = dp[i%2][j] || dp[(i+1)%2][j-b[i]];
            }
        }
        bool flg = false;
        for(int i=k-a[mid];i<k;i++){
            if(dp[n%2][i]){
                flg = true;
                break;
            }
        }
        if(flg)need = mid;
        else noneed = mid;
    }
    cout << need;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  string s;
  char t[10]={};
  cin >> s;
  int c=0;
  rep(i,0,s.size()){
    if(s[i]=='0'){
      t[c]='0';
      c++;
      continue;
    }
    else if(s[i]=='1'){
      t[c]='1';
      c++;
      continue;
    }
    else if(s[i]=='B'){
      if(c>0) c-=1;
    }
  }
  rep(i,0,c) cout << t[i];
  cout << endl;
    
  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=sorted(filter(lambda x:x<K,list(map(int,input().split()))))
N=len(A)
if N==0:
  print(0)
  exit()
def judge(x):
  DP=1
  Z=(1<<K)-1
  for i in range(N):
    if i!=x:
      DP=((DP|(DP<<A[i]))&Z)
  r=0
  for i in range(K-A[x],K):
    r|=(DP&(1<<i))
  return r

if judge(0):
  print(0)
  exit()
L,R,M=1,N,0
while L!=R:
  M=(L+R)//2
  if judge(M)==0:
    L=max(L+1,M)
  else:
    R=M
print(L)

Measured memory_bytes: 73960
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef string ST;
 
 
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

LL modinv(LL a, LL m) {
  LL b = m, u = 1, v = 0;
  while (b) {
    LL t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0){
     u += m;
  }
  return u;
}

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}

vector<LL> dp;
vector<LL> X;
vector<LL> Y;
vector<vector<LL>> To;
vector<vector<LL>> Fr;
  
LL rec(LL i){
  if(dp[i]!=-1){
    return dp[i];
  }

  dp[i] = 0L;
  if(Fr[i].size()==0){
    return dp[i];
  }

  for(LL j=0;j<Fr[i].size(); ++j){
    LL k = Fr[i][j];
     cmax(dp[i],rec(k)+1);
  }
  return dp[i];
}

void func() {
  LL N;
  LL M;
  cin >> N;
  dp.resize(N,-1);
  To.resize(N);
  Fr.resize(N);
  cin >> M;
  X.resize(M);
  Y.resize(M);
  REP(i,M){
    LL x;
    LL y;
    cin >> x;
    cin >> y;
    x--;
    y--;
    X[i] = x;
    Y[i] = y;

    To[x].push_back( y );
    Fr[y].push_back( x );
    
  }

  REP(i,M){
    //fprintf(stderr, "%lld, %lld, %lld\n",i,X[i],Y[i]);
  }
  REP(i,N){
    rec(i);
    //PRINTSP(dp);
  }
  cout << *max_element(ALL(dp));


  return;
}



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

Measured memory_bytes: 19584
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 列ベクトルとかの受け取り
lists = ["".join(sorted(list(input()))) for _ in range(n)]

strcount = Counter(lists)

ans = 0
for i,n in strcount.items():
    if n == 1:
        continue
    else:
        ans += n*(n-1)//2

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 19820