akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<ll> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
ll cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
ll dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

typedef vector<P> G;

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<P> ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

int main(){
	ll N;
	cin >> N;
	vector<P> input;
	REP(i, N){
		ll x, y;
		cin >> x >> y;
		P tmp(x, y);
		input.push_back(tmp);
	}
	vector<P> ch = convex_hull(input);
	ll M = ch.size();
	map<P, double> res;
	REP(i, M){
		P p1 = ch[i] - ch[(i-1+M)%M];
		P p2 = ch[(i+1)%M] - ch[i];
		double norm1 = sqrt(norm(p1));
		double norm2 = sqrt(norm(p2));
		double coss = (double)dot(p1, p2)/(norm1*norm2);
		double sinn = (double)cross(p1, p2)/(norm1*norm2);
		double theta = atan2(sinn, coss);
		res[ch[i]] = theta;
	}
	REP(i, N){
      	bool flag = (res.find(input[i])!=res.end());
		if(flag){
			printf("%.20f\n", res[input[i]]/(2*M_PI));
		}else{
			printf("%.20f\n", 0.0);
		}
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 50
#define WHITE 0
#define GRAY 1
#define BLACK 2

int h, w;
int m[MAX][MAX], c[MAX][MAX];
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};

void bfs_init(){
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			m[i][j]=0;
			c[i][j]=WHITE;
		}
	}
	m[0][0]=1;
	return;
}

void bfs_visit(int x, int y){
	queue<pair<int,int>> q;
	c[x][y]=GRAY;
	q.push(make_pair(x,y));
	while(!q.empty()){
		pair<int,int> u=q.front();
		q.pop();
		int ux=u.first, uy=u.second;
		for(int i=0; i<4; i++){
			int xx=ux+dx[i], yy=uy+dy[i];
			if(xx<0 || xx>=h || yy<0 || yy>=w) continue;
			if(m[xx][yy]!=-1 && c[xx][yy]==WHITE){
				c[xx][yy]=GRAY;
				m[xx][yy]=m[ux][uy]+1;
				q.push(make_pair(xx,yy));
			}
		}
		c[ux][uy]=BLACK;
	}
	return;
}

int main(){
	bfs_init();

	cin >> h >> w;
	int b_cnt=0;
	for(int i=0; i<h; i++){
		string s;
		cin >> s;
		for(int j=0; j<w; j++){
			if(s[j]=='#'){
				m[i][j]=-1;
				b_cnt++;
			}
		}
	}

	bfs_visit(0,0);
	if(m[h-1][w-1]==0) cout << -1 << endl;
	else cout << h*w-b_cnt-m[h-1][w-1] << endl;
	return 0;
}

Measured memory_bytes: 256
read aa
read bb
read cc
cnta=0
cntb=0
cntc=0
 
a ()
{
	check=${aa:0:1}
	aa=${aa/?/}
	now=A
}
b ()
{
	check=${bb:0:1}
	bb=${bb/?/}
	now=B
}
c ()
{
	check=${cc:0:1}
	cc=${cc/?/}
	now=C
}
 
a
 
while :
do
	ans=$now
	case ${check} in
		a)
			a
		;;
		b)
			b
		;;
		c)
			c
		;;
		*)
			break
		;;
	esac
done
echo $ans


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

int x;

int main() {
  cin >> x;
  int fivehand = x/500;
  int sub = x % 500;
  int five = sub / 5;
  cout << fivehand * 1000 + five * 5 << endl;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
const int maxn = 1e5 + 1000;
int dp[maxn];
int f(int at)
{
	if(at >= n)
		return 1e9;
	if(at == n - 1)
		return 0;
	if(dp[at] != -1)
		return dp[at];
	
	int low = f(at + 1) + abs(arr[at] - arr[at+1]);
	int high = f(at + 2) + abs(arr[at] - arr[at+2]);
	return dp[at] = min(low,high);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i =0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	cout<<f(0)<<endl;
	return 0;
}

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

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

    int ans = 0;
    for(int i = a; i <= b; i++) {
        string s = to_string(i);
        string r = s;
        reverse(r.begin(), r.end());
        if(s == r) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。data[0]:root<-leaf:data[-1]
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, i, v):
        '''
        leafの初期化
        i: 0-origin idx
        v: value
        '''
        self.data[i+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        #leaf->rootに向かって、apply func していく
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        data[k]=aに更新する。
        更新をrootまで更新
        '''
        k += self.n-1 #k=segTree上での k-th leafのidx
        self.data[k] = a

        while k > 0: #while not reach to root
            k = (k-1)//2 #goto its parent
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2]) #update

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1: #R%2==1 
                R -= 1
                ret = self.func(ret, self.data[R-1]) #親が丸々区間に含まれない->はみ出したところを更新
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1 #to parent
            R >>= 1
        return ret


    def lower_bound_index(self,x,v):
        """
        [x,N)の範囲で、v<=data[j]を満たす最小のjを探す
        """
        #区間の左端
        x+=self.n-1

        #data[x]が、v以上なるまで登る
        while self.data[x]<v:
            #print("xbeg->",x)
            if x%2==0: #xが右のnodeなら
                #print("x&0")
                if len(bin(x+1))==len(bin(x+2)):#一つ右に移動できるなら
                    #print("T")
                    x+=1
                else:#右に行けない->とりま大きい値をreturnしとく。(多分、全ての値が条件を満たさない時に、無限whileするのを防ぐ
                    return float("inf")

            else:#登る
                x>>=1
            #print("x->",x)

        while x<self.n-1:
            if self.data[2*x+1]>=v:
                x=2*x+1
            else:
                x=2*x+2
        return x-self.n+1



N,Q = map(int,input().split())
Seg = SegmentTree(N,lambda x,y:max(x,y),init=-1)
A = list(map(int,input().split()))
for i,a in enumerate(A):
    Seg.set(i,a)



Seg.build()

for _ in range(Q):
    t,a,b = map(int,input().split())
    if t==1:
        Seg.update(a-1,b)
    elif t==2:
        print(Seg.query(a-1,b))
    elif t==3:
        print(min(Seg.lower_bound_index(a-1,b),N)+1)




Measured memory_bytes: 101496
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    string s;
    cin>>n>>s;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R')++r;
        else if(s[i]=='G')++g;
        else ++b;
    }
    ll ans=r*g*b;
    rep(i,n){
        for(int j=i+1;j<n;++j){
            if(s[i]==s[j])continue;
            int d=j-i;
            if(n<=j+d)break;
            if(s[i]!=s[j+d]&&s[j]!=s[j+d])--ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

struct u_edge {
    int to, w;
};

struct d_edge {
    int from, to, w;
};

using graph = vector<vector<u_edge>>;

vector<bool> get_reachable_tree(const graph& g, int s) {
    const int n = g.size();
    vector<bool> reach(n, false);

    function<void(int)> rec = [&](int i) {
        reach[i] = true;
        for(auto u_e : g[i]) {
            if(!reach[u_e.to]) rec(u_e.to);
        }
    };

    rec(s);

    return reach;
}

ll bellman_ford(const graph& g, const vector<d_edge> edges, const vector<bool>& reach_s, const vector<bool>& reach_t) {
    const int n = g.size();
    vector<ll> dis(n, 1e10);
    dis[0] = 0;

    for(int i=0; i<n-1; i++) {
        for(auto d_e : edges) {
            if(dis[d_e.to] > dis[d_e.from] + d_e.w) {
                dis[d_e.to] = dis[d_e.from] + d_e.w;
            }
        }
    }

    for(auto d_e : edges) {
        if(dis[d_e.to] > dis[d_e.from] + d_e.w && reach_s[d_e.from] && reach_t[d_e.to]) {
            return -1;
        }
    }

    return max(0LL, -dis[n-1]);
}

int main() {
    int n, m, p; cin >> n >> m >> p;
    graph g(n), ng(n);
    vector<d_edge> edges(m); 

    REP(i, m) {
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        g[a].push_back({b, -(c-p)});
        ng[b].push_back({a, 0}); // 重さはなんでもいい
        edges[i] = {a, b, -(c-p)};
    }
    
    auto reach_s = get_reachable_tree(g, 0), reach_t = get_reachable_tree(ng, n-1);

    cout << bellman_ford(g, edges, reach_s, reach_t) << endl;

    return 0;
}



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

using namespace std;

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum = 0;
    if(a>=k)
        sum+=k;
    else
    {
        sum += a;
        k -= a;
        if(k<=b)
            sum+=0;
        else
        {
            k-=b;
            sum-=k;
        }
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3636
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            total = i * 500 + 100 * j + 50 * k
            if total == x:
                ans += 1
print(ans)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<ll> a;
vector<vector<ll> > memo;

ll rec(int left, int right){
	if(left > right) return 0;
	if(memo[left][right] != -1) return memo[left][right];
	int turn = (n - (right - left)) % 2;
	if(turn == 1){
		return memo[left][right] = max(rec(left + 1, right) + a[left], rec(left, right - 1) + a[right]);
	}
	else{
		return memo[left][right] = min(rec(left + 1, right) - a[left], rec(left, right - 1) - a[right]);
	}
}

signed main(){
	scanf("%d", &n);
	a.resize(n);
	memo.resize(n, vector<ll> (n, -1));
	for(int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	cout << rec(0, n - 1) << endl;
}

Measured memory_bytes: 73964
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int a,b;
int main(){
    r(a);r(b);
    cout<<max(a-b,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -1;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}

Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(x1 != x2){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}

Polygon ConvexCut(Polygon g,Point a,Point b){

	Polygon ret;
	int N = g.size();

	for(int i = 0; i < g.size(); i++){
		Point A = g[i], B = g[(i+1)%N];
		if(ccw(a,b,A) != -1)ret.push_back(A);
		if(ccw(a,b,A)*ccw(a,b,B) == -1)ret.push_back(calc_Cross_Point(a,b,A,B));
	}

	return ret;
}

double calc_S(Polygon g){

	int N = g.size();
	double ret = 0;

	for(int i = 0; i < g.size(); i++){
		ret += cross(g[i],g[(i+1)%N]);
	}
	return ret/2.0;
}

int main(){

	int N;
	scanf("%d",&N);

	Polygon g;
	double x,y;

	for(int loop = 0; loop < N; loop++){
		scanf("%lf %lf",&x,&y);
		g.push_back(Point(x,y));
	}

	int Q;
	scanf("%d",&Q);

	Point a,b;
	Polygon ret;

	for(int loop = 0; loop < Q; loop++){
		scanf("%lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y);
		ret = ConvexCut(g,a,b);
		printf("%.10lf\n",calc_S(ret));
	}

	return 0;
}



Measured memory_bytes: 3216
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int D[55][55], c[505][505];
int cost0[55], cost1[55], cost2[55];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, C;
	cin >> n >> C;
	rep(i,C)rep(j,C) cin >> D[i][j];
	rep(i,n)rep(j,n){
		cin >> c[i][j];
		--c[i][j];
	}
	rep(k,C){
		rep(i,n)rep(j,n){
			if((i+j)%3 == 0) cost0[k] += D[c[i][j]][k];
			if((i+j)%3 == 1) cost1[k] += D[c[i][j]][k];
			if((i+j)%3 == 2) cost2[k] += D[c[i][j]][k];
		}
	}
	int ans = 1e9;
	rep(i,C){
		rep(j,C){
			if(i == j) continue;
			rep(k,C){
				if(j == k) continue;
				if(k == i) continue;
				int cost = cost0[i] + cost1[j] + cost2[k];
				chmin(ans, cost);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4632
#include <iostream>
#include <queue>
#define NIL -1
#define MAXN 25
using namespace std;

typedef struct {
	int parent;
	int leftChild;
	int rightChild;
	int sibling;
	int depth;
	int high;
	int numChild;
} Tree, Node;

void readTree(Tree T[], int n)
{
	int id;
	int leftChild, rightChild;
	
	for (int i = 0; i < n; i++) {
		cin >> id;
		
		cin >> leftChild >> rightChild;
		
		if (leftChild != NIL) {
			T[id].leftChild = leftChild;
			T[T[id].leftChild].parent = id;
			T[id].numChild += 1;
		}
		if (rightChild != NIL) {
			T[id].rightChild = rightChild;
			T[T[id].rightChild].parent = id;
			T[id].numChild += 1;
		}
	}
	
	for (int i = 0; i < n; i++) {
		if (T[i].parent != NIL && T[T[i].parent].rightChild != i && T[T[i].parent].rightChild != NIL) {
			T[i].sibling = T[T[i].parent].rightChild;
		} else if (T[i].parent != NIL && T[T[i].parent].leftChild != i&& T[T[i].parent].leftChild != NIL) {
			T[i].sibling = T[T[i].parent].leftChild;
		}
	}
}

void getDepth(Tree T[], int n)
{
	for (int i = 0; i < n; i++) {
		int d = 0;
		int id = i;
		while (T[id].parent != NIL) {
			id = T[id].parent;
			d++;
		}
		T[i].depth = d;
	}
}

int setHeight(Node T[], int id)
{
	int h1 = 0;
	int h2 = 0;
	if (T[id].leftChild != NIL) {
		h1 = setHeight(T, T[id].leftChild) + 1;
	}
	if (T[id].rightChild != NIL) {
		h2 = setHeight(T, T[id].rightChild) + 1;
	}
	
	return T[id].high = (h1 > h2 ? h1 : h2);
}

void printTree(Tree T[], int n)
{
	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": ";
		cout << "parent = " << T[i].parent << ", ";
		cout << "sibling = " << T[i].sibling << ", ";
		cout << "degree = " << T[i].numChild << ", ";
		cout << "depth = " << T[i].depth << ", ";
		cout << "height = " << T[i].high << ", ";
		if (T[i].parent == NIL) {
			cout << "root";
		} else if (T[i].numChild == 0) {
			cout << "leaf";
		} else {
			cout << "internal node";
		}
		cout << '\n';
	}
} 

int main(void)
{
	Tree T[MAXN];
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		T[i].parent = NIL;
		T[i].leftChild = NIL;
		T[i].rightChild = NIL;
		T[i].sibling = NIL;
		T[i].numChild = 0;
	}
	
	readTree(T, n);
	int rootId;
	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL) {
			rootId = i;
			break;
		}
	}
	getDepth(T, n);
	setHeight(T, rootId);
	printTree(T, n);
	
	return 0;
}


Measured memory_bytes: 3124
N, K = map(int, raw_input().split())
R, S, P = map(int, raw_input().split())
T = raw_input()

ans = 0
X = ["."]*N
for i in range(N):
  if T[i]=="r" and (i<K or X[i-K]!="p"):
    ans += P
    X[i] = "p"
  if T[i]=="p" and (i<K or X[i-K]!="s"):
    ans += S
    X[i] = "s"
  if T[i]=="s" and (i<K or X[i-K]!="r"):
    ans += R
    X[i] = "r"
print ans


Measured memory_bytes: 8324
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#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<int,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-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	if(n==3){
		cout<<"2 5 63"<<endl;
	}else{
		vi in;
		rep(i,min(5000,n-2)/2*2)in.pb(3+6*i);
		n-=min(5000,n-2)/2*2;
		if(n%3==1)in.pb(6);
		if(n%3==2){
			in.pb(2);
			in.pb(4);
		}
		rep(i,n/3){
			in.pb(30000-6*i);
			in.pb(30000-6*i-2);
			in.pb(30000-6*i-4);
		}
		rep(i,in.size())cout<<in[i]<<" \n"[i==in.size()-1];
	}
}









Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int d = max(a, max(b, c));
	int ans = a + b + c - d;
	rep(i, k) {
		d *= 2;
	}
	ans += d;
	cout << ans << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
kr = 1
ks= 1
kp = 1
Is = 0
Ir=0
Ip=0
A =[]

for i in range(n):
  if i-k < 0:
      A.append(1)
      if t[i] == "r":
        kr = 1
        ans += p
      elif t[i] == "s":
        ks=1
        ans += r
      else:
        kp=1
        ans += s
  else:
    if t[i] != t[i-k]:
      if t[i] == "r":
        kr=1
        ans += p
        Ir = i
        A[i%k]=1
      elif t[i] == "s":
        ans += r
        ks=1
        Is = i
        A[i%k]=1
      else:
        kp=1
        ans += s
        A[i%k]=1
    else:
      if t[i] == "r":
        if A[i%k] == 0:
          ans+=p
          A[i%k] = 1
        else:
            A[i%k]  = 0
      elif t[i] == "s":
        if A[i%k] ==0:
          ans += r
          A[i%k] = 1
        else:
            A[i%k] = 0
      else:
        if A[i%k]==0:
          ans+=s
          kp=1
          Ip = i
          A[i%k] = 1
        else: 
            A[i%k] = 0
      
print(ans)

Measured memory_bytes: 4084
fn main() {
    let s = io::read_string();
    let mut sc = io::Scanner::new(&s);

    let mut a: Vec<usize> = sc.read_vec(3);

    a.sort();

    let res = a[2] - a[0];

    println!("{}", res);
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int v[3];
    cin >> v[0] >> v[1] >> v[2];
    sort( v, v+3 );
    if( v[0] == 5 && v[1] == 5 && v[2] == 7 ) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;
 


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

  
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  unordered_map<int, int> m;
  int ans = 0;
  for (int i = 0; i < n; i++){
    if (m.find(i - a[i]) != m.end()){
      ans += m[i - a[i]];
    }
    if (m.find(i + a[i]) != m.end()){
      m[i + a[i]] += 1;
    }
    else
      m[i + a[i]] = 1;
    
  }
  cout << ans << endl;
}


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

int main() {
  int W, H, N, ans = 0;
  cin >> W >> H >> N;
  vector<int>x(N);
  vector<int>y(N);
  vector<int>a(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }
  vector<vector<bool>>iwa(H,vector<bool>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      iwa.at(i).at(j) = true;
    }
  }
  for (int i = 0; i < N; i++) {
    if (a.at(i) == 1) {
      for (int j = 0; j < H; j++) {
        for (int k = 0; k < x.at(i); k++) {
          iwa.at(j).at(k) = false;
        }
      }
    }
    else if (a.at(i) == 2) {
      for (int j = 0; j < H; j++) {
        for (int k = x.at(i); k < W; k++) {
          iwa.at(j).at(k) = false;
        }
      }
    }
    else if (a.at(i) == 3) {
      for (int j = 0; j < y.at(i); j++) {
        for (int k = 0; k < W; k++) {
          iwa.at(j).at(k) = false;
        }
      }
    }
    else {
      for (int j = y.at(i); j < H; j++) {
        for (int k = 0; k < W; k++) {
          iwa.at(j).at(k) = false;
        }
      }      
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (iwa.at(i).at(j)) {
        ans++;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
B=[0]*n
j=0
for i in range(n):
    while b[i]>=c[j] and j<n-1:j+=1
    if b[i]<c[j]:B[i]=n-j
ans=0
s=sum(B)
j=0
for i in range(n):
    while a[i]>=b[j] and j<n-1:s-=B[j];j+=1
    if a[i]<b[j]:ans+=s
print(ans)

Measured memory_bytes: 22720
#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 rrng(a) a.rbegin(), a.rend()
#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 eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#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 tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  ll h;
  cin >> n >> h;
  vl a(n), b(n);
  ll ma = 0;
  rep(i, n) {
    cin >> a[i] >> b[i];
    maxs(ma,a[i]);

  }
  sort(b.begin(),b.end(),greater<ll>());
  ll count = 0;
  rep(i,n){
    if(ma < b[i]){
      count++;
      h-=b[i];
      if(h<=0) break;
    }
  }
  if(h<=0){
    cout<<count<<endl;
    return 0;
  }
  count += (h+ma-1)/ma;
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
int x, y, z;
int main() {
	cin >> x >> y;
	cout << max(x + y, max(x - y, x*y));
	cin >> x;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll x(n), y(n);
    REP(i, n) cin >> x[i] >> y[i];
    using D = double;
    D ans = 0;
    REP(i, n) {
        ll gx = x[i], gy = y[i];
        REP(k, 4) {
            {
                ll nx = -gy, ny=gx;
                gx = nx;
                gy = ny;
            }
            ll sx=0, sy=0;
            ll px=0, py=0;
            ll qx=0, qy=0;

            auto dot = [&](ll x1, ll y1, ll x2, ll y2){return x1*x2+y1*y2;};
            auto cross = [&](ll x1, ll y1, ll x2, ll y2){return x1*y2-y1*x2;};
            REP(j, n) {
                ll res = dot(x[j], y[j], gx, gy);
                if (res < 0) continue;
                else if (res > 0) {
                    sx += x[j];
                    sy += y[j];
                    continue;
                }
                if (cross(x[j], y[j], gx, gy) > 0) {
                    px += x[j];
                    py += y[j];
                } else {
                    qx += x[j];
                    qy += y[j];
                }
            }

            REP(t, 4) {
                D bx=sx, by=sy;
                if (t&1) bx += px, by += py;
                if (t&2) bx += qx, by += qy;
                chmax(ans, bx*bx+by*by);
            }
        }
    }
    cout << fixed << setprecision(12) << sqrt(ans) << '\n';
    return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};

int N, A, B, C, D;
string S;

bool reachable(){
    int l = 0, r = N - 1;
    int E = MAX2(C, D);
    for(int i = A; i <= E - 1; i++){
        if(S[i] == '#' && S[i + 1] == '#') return false;
    }
    if(C < D) return true;
    for(int i = B - 1; i <= D - 1; i++){
        if(S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') return true;
    }
    return false;
}

signed main(){
    cin >> N >> A >> B >> C >> D;
    cin >> S;
    A--; B--; C--; D--;
    if(reachable()) PRINT("Yes");
    else PRINT("No");
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

int checkS[30];
int checkT[30];

int SisOK(char c) {
  char cha = 'a';
  // i=1:a i=28:z
  int i=1;
  for(i=1; i<=28; i++) {
    if(cha == c) break;
    cha++;
  }
  checkS[i]++;
  return checkS[i];
}

int TisOK(char c) {
  char cha = 'a';
  // i=1:a i=28:z
  int i=1;
  for(i=1; i<=28; i++) {
    if(cha == c) break;
    cha++;
  }
  checkT[i]++;
  return checkT[i];
}

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

  string S,T; cin>>S>>T;

  vector<int> SS;
  vector<int> TT;

  REP(i,S.size()) {
    SS.push_back(SisOK(S[i]));
    TT.push_back(TisOK(T[i]));
  }

  string ans = "Yes";
  REP(i,S.size()) {
    if(SS[i] != TT[i]) {
      ans = "No";
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


int main(){
  string s, t;
  cin >> s >> t;
  map<char, int> mps, mpt;
  multiset<int> ss, ts;
  bool flag = true;
  for(int i = 0; i < s.size(); i++){
    char c1 = s.at(i), c2 = t.at(i);
    mps[c1]++;
    mpt[c2]++;
  }
  for(pair<char, int> p : mps){
    ss.insert(p.second);
  }
  for(pair<char, int> p : mpt){
    ts.insert(p.second);
  }
  flag = ss == ts;
  
    
  if(flag) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}
  

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...

ll L,R,d;	
void test_case(){
	cin >> L >> R >> d;
	cout << R/d - L/d + (L%d == 0?1:0);



	
}




int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
using namespace std;

int main () {
	string s;
	cin >> s;
	int l = 0;
	int r = s.length() - 1;
	int ans = 0;
	while(l <= r) {
		if(s[l] != s[r]) ans += 1;
		l += 1;
		r -= 1;
	}
	cout << ans;
	return 0;
}

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

int main(void){
  int n;
  cin >> n;
  string name;
  long m,a,r,c,h;
  m=0;
  a=0;
  r=0;
  c=0;
  h=0;  
  for (int i = 0; i < n; i++)
  {
    cin >> name;
    if (name[0] == 'M') m++;
    if (name[0] == 'A') a++;
    if (name[0] == 'R') r++;
    if (name[0] == 'C') c++;
    if (name[0] == 'H') h++;
  }
  cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h +r*c*h << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import product
def trueCheck(i,x):
    for j in range(1,N+1):
        if B[i][j]==1:
            if x[j-1]==0:
                return 1
        elif B[i][j]==0:
            if x[j-1]==1:
                return 1
    return 0
N = int(input())
A = [0]
B = {i:[-1 for _ in range(N+1)] for i in range(1,N+1)}
for i in range(1,N+1):
    A.append(int(input()))
    for _ in range(A[-1]):
        x,y = map(int,input().split())
        B[i][x] = y
cmax = 0
for z in product([0,1],repeat=N):
    flag = 0
    for i in range(1,N+1):
        if z[i-1]==1:
            flag = trueCheck(i,z)            
        if flag==1:break
    if flag==0:
        cmax = max(cmax,sum(z))
print(cmax)               

Measured memory_bytes: 46428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;

int main(void){
    ll N;
    cin >> N;
    set<ll> A;
    ll tmp;
    for(ll i = 0; i < N; i++){
        cin >> tmp;
        A.insert(tmp);
    }
    if( A.size() == N){
        printf("YES");
    }
    else{
        printf("NO");
    }
    
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
 
bool dp[100100];
 
 
int main () {
    long long X;
    cin >> X;

    long long yokin = 100;
    
    long long ans = 0;
    while(true){
        yokin = yokin + yokin *0.01;
        ans +=1;
        if(yokin >= X){
            cout << ans << endl;
            return 0;
        }
    }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K;
  cin >> N >> K;
  REP(k,K){
	int x, y;
	cin >> x >> y;
	cout << min(min(x-1, N-x), min(y-1, N-y)) % 3 + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
import sys
import fractions

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    S = input().strip()
    T = input().strip()

    ans = (N * M) // fractions.gcd(N, M)

    dic = {}
    for i, s in enumerate(S):
        dic[(ans // N) * i + 1] = s

    for i, t in enumerate(T):
        if ((ans // M) * i + 1) in dic.keys():
            if dic[(ans // M) * i + 1] != t:
                print(-1)
                return

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17492
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    unordered_map<string ,int>m;
    ll sum=0;
    while(n--){
        string s;
        ll x;
        cin>>s>>x;
        sum+=x;
        m[s]=sum;
    }
    string str;
    cin>>str;
    for(auto k:m){
        if(k.first==str){
            cout<<sum-k.second<<endl;
            break;
        }
    }
    return 0;
}
    
    
    

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

int main(){
  int n; cin>>n;
  vector<pair<int,int>> a[20];
  rep(i,n){
    int A; cin>>A;
    rep(j,A){
      int x,y; cin>>x>>y;
      x--;
      a[i].push_back(make_pair(x,y));
    }
  }
  int ans=0;
  for(int i=0; i<(1<<n); i++){
    bool ok=true;
    int honest_cnt=0;
    rep(j,n){
      if((i>>j)&1){
        honest_cnt++;
        for(auto x : a[j]){
          if(x.second==1 && !((i>>x.first)&1)) ok=false;
          if(x.second==0 &&  ((i>>x.first)&1)) ok=false;
        }
      }
    }
    if(ok) ans=max(honest_cnt,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3584
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
bool comp(vector<long long int> A,vector<long long int> B)
{
	return A[0]<B[0];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	long long int N,M;
	cin>>N>>M;
	vector<vector<long long int>> A;
	for (long long int i = 0; i < N; ++i)
	{
		long long int a,b;
		cin>>a>>b;
		vector<long long int> X={a,b};
		A.push_back(X);
	}
	sort(A.begin(), A.end(),comp);
	long long int ans=0;
	long long int c=0;
	for (long long int i = 0; i < N; ++i)
	{
		if(c<M)
		{
			if(A[i][1]<=(M-c))
			{
				ans+=A[i][1]*A[i][0];
				c+=A[i][1];
			}
			else
			{
				ans+=A[i][0]*(M-c);
				c+=(M-c);
			}
		}
		else
		{
			break;
		}
	}
	cout<<ans<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 6836
#include <stdio.h>
int main () {
 int i,j;
 char n[100000] = {0};
 int x[1001] = {0};

 i = 0;
 j = 0;

 while(1) {
  scanf("%c",&n[i]);

  if(n[i] == '0' && n[i-1] == '\n'|| n[0] == '0') {
   break;
  }

  if(n[i] >= '1' && '9' >= n[i] && n[i] != '\n') {
   x[j] += n[i]-48;
  }

  if(n[i] == '\n') {
   j = j + 1;
  }
  i= i+1;
 }

 for(i=0; i < j;i++) {
  printf("%d",x[i]);
  printf("\n");
 }

 return 0; 
} 


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S ;
  cin >> S;
  
  if (S[0] == S[1] && S[1] == S[2] && S[2] == S[3] ){
    cout << "No" << endl;
  }
  
  else if (S[0] == S[1] && S[2] == S[3] ){
    cout << "Yes" << endl;
  }
  
  else if (S[0] == S[2] && S[1] == S[3] ){
    cout << "Yes" << endl;
  }
  
  else if (S[0] == S[3] && S[1] == S[2] ){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

const int mod=1e9+7;
inline int add(int x,int y)
{
  x+=y;
  if (x>=mod)
    return x-mod;
  return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if (x<0)
    return x+mod;
  return x;
}
inline int mul(int x,int y)
{
  return (x*1ll*y)%mod;
}
inline int power(int x,int y)
{
  int ans=1;
  while(y)
    {
      if (y&1) ans=mul(ans,x);
      x=mul(x,x);
      y>>=1;
    }
  return ans;
}
inline int inv(int x)
{
  return power(x,mod-2);
}
inline int gcd(int x, int y)
{
  return(y!=0)?gcd(y, x%y):x;
}

/*------------CODE-----------*/

int main()
{
  IOS;
  int n;
  cin >> n;
  ll ans=0;
  for (int i=1; i<=n; i++)
    {
      for (int j=1; j<=n; j++)
	{
	  for (int k=1; k<=n; k++)
	    {
	      ans+=gcd(i, gcd(j, k));
	    }
	}
    }
  cout << ans << endl;
  return 0;
}

/*
**mpamt
*/


Measured memory_bytes: 3584
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]

result = []
for a, b in ab:
    tmp = []
    for c, d in cd:
        tmp.append(abs(a-c) + abs(b-d))
    result.append(tmp.index(min(tmp)) +1)
for ans in result:
    print(ans)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i ++) cin >> a[i] >> b[i];

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int sum = 0;
  for (int i = 0; i < m - 1; i ++) {
    if (a[i] < n) {
      sum += n - a[i];
    }
  }

  cout << sum << endl;
}


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

bool isPrime(int n){
	for(int i=6 ; i < n ; i+=7 ){
		if( n%i == 0 ) return false;
	}
	for(int i=8 ; i < n ; i+=7 ){
		if( n%i == 0 ) return false;
	}
	return true;
}

int main(){
	int n;
	while( cin >> n , n != 1 ){
		cout << n << ":";
		for(int i=7 ; i <= n+1 ; i+=7 ){
			if( n%(i-1) == 0 ){
				if( isPrime(i-1) ){
					cout << " " << (i-1);
				}
			}
			if( n%(i+1) == 0 ){
				if( isPrime(i+1) ){
					cout << " " << (i+1);
				}
			}
		}
		cout << endl; 
	}
}

Measured memory_bytes: 864
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

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



signed main () {
    int a,b,c,d,e;cin >>a>>b>>c>>d>>e;
    cout <<15-a-b-c-d-e<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,g,b,n; cin >> r >> g >> b >> n;
  int cnt = 0;
  for(int i = 0; i <= n; i+=r){
    for(int j = 0; j <= n; j+=g){
      int x = i + j;
      if(n-x<0)continue;
      cnt += (n-x)%b==0;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3540