akhauriyash/Code-Regression huggingface dataset:
def gcd(x,y)
  x,y = y,x if x < y
  if y == 0
    return x
  else
    return gcd(y,x%y)
  end
end

n,m = gets.split.map(&:to_i)
s = gets.chomp!
t = gets.chomp!
# if n > m
#  n,m,s,t = m,n,t,s
#end
len = n * m / gcd(n,m)

check = []
flag = true

n.times do |i|
  k = len/n * i
  check << [i,k/(len/m)] if k % (len/m) == 0
end
check.each do |a|
  flag = false if s[a[0]] != t[a[1]]
end

if flag
  p len
else
  p -1
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
  
using namespace std;
  
const int INF = (1<<29);
  
class Point{
public:
  double x,y;
  
  Point(double x = 0, double y = 0):x(x),y(y){}
  
  bool operator < (const Point &a)const{
    if(x != a.x) return x < a.x;
    return y < a.y;
  }
};
  
bool compare(Point a, Point b){
  return a.y < b.y;
}
  
double solve(Point *a, int n){
  if(n <= 1) return INF;
  int m = n / 2;
  double xx = a[m].x;
  double d = min(solve(a,m),solve(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare);
  
  vector<Point> v;
  for(int i = 0 ; i < n ; i++){
    if(fabs(a[i].x - xx) >= d) continue;
    int len = (int)v.size();
    for(int j = 0 ; j < len ; j++){
      double dx = a[i].x - v[len-j-1].x;
      double dy = a[i].y - v[len-j-1].y;
  
      if(dy*dy >= d) break;
      d = min(d,dx * dx + dy * dy);
    }
    v.push_back(a[i]);
  }
  return d;
}
  
int main(){
  int n;
  
  cin >> n;
  Point p[n];
  for(int i = 0 ; i < n ; i++){
    scanf("%lf%lf",&p[i].x,&p[i].y);
  }
  sort(p,p+n);
  cout << solve(p,n) << endl;
  return 0;
}

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

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

    bool aflag = false;
    bool bflag = false;
    bool cflag = false;
    for ( int i=0; i<3; ++i) {
        if (S[i]=='a') aflag = true;
        if (S[i]=='b') bflag = true;
        if (S[i]=='c') cflag = true;
    }

    if (aflag==true && bflag==true && cflag==true){
        cout << "Yes";
    } else {
        cout << "No";
    }
}

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

int main(){
  string str;
  long int index = 0,len;
  cin>>str;
  len = str.length();
  while(index<len){
    if(str[index]=='?'){
      str[index] = 'D';
    }
    index+=1;
  }
  cout << str;
}







Measured memory_bytes: 3376
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string T[3] = {"Sunny", "Cloudy", "Rainy"};
int main(){

	string S;
	cin >> S;
	for(int i=0;i<3;i++){
		if(S== T[i]) cout << T[(i+1)%3] <<endl;
	}
  return 0;
}




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

using namespace std;

int main()
{
    string s;
    int i = 700;

    cin >> s;
    if(s[0] == 'o') i += 100;
    if(s[1] == 'o') i += 100;
    if(s[2] == 'o') i += 100;
    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
    ll n,m,a,b;
    cin>>n;
    string s;
    vector<string> v,v1;
    v.push_back(" ");
    REP(i,1,n)
    {
        cin>>s;
        v.push_back(s);        
    }
    v1=v;
    sort(v1.begin(),v1.end());
    REP(i,1,n)
    {
        REP(j,i+1,n)
        {
            if(v1[i]==v1[j])
            {
                cout<<"No";
                return 0;
            }
        }
    }
    REP(i,2,n)
    {
        if(v[i-1].back()!=v[i].front())  
        {
            cout<<"No";
            return 0;
        }      
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
char a[3];
using namespace std;
int main()
	{
		cin>>a;
		if(a[0]!=a[1]&&a[0]!=a[2]&&a[1]!=a[2]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1e+6;
pair<int ,int> a[101];
int dp[101][N+1];
main()
{
    int n,w,goal=0;
    scanf("%lld%lld",&n,&w);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i].S,&a[i].F);
    }
    for(int i=0;i<=n;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=100000000000;
        }
    }
    for(int i=1;i<=n;i++){
        goal+=a[i].F;
        for(int j=1;j<=goal;j++){
            if(a[i].F>=j){
                dp[i][j]=min(a[i].S,dp[i-1][j]);
            }
            else{
                dp[i][j]=min(a[i].S+dp[i-1][j-a[i].F],dp[i-1][j]);
            }
        }
    }
    int it=0;
    while(dp[n][it]<=w&&it<=N){
        //cout<<dp[n][it]<<" ";
        it++;
    }
    cout<<it-1;
}

Measured memory_bytes: 792740
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

VS mp;
int n, m, x, y;
char mp_input[ 200 ];
bool gone[ 200 ][ 200 ];

int main() {
	while ( ~scanf( "%d %d", &n, &m ) && n && m ) {
		mp.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%s", mp_input );
			mp[ i ] = ( string ) mp_input;
		}
		memset( gone, 0, sizeof( gone ) );
		x = y = 0;
		while ( mp[ y ][ x ] != '.' ){
			if ( gone[ y ][ x ] ) {
				break;
			}
			gone[ y ][ x ] = true;
			if ( mp[ y ][ x ] == '>' ) {
				x++;
			}
			else if ( mp[ y ][ x ] == '<' ) {
				x--;
			}
			else if ( mp[ y ][ x ] == '^' ) {
				y--;
			}
			else if ( mp[ y ][ x ] == 'v' ) {
				y++;
			}
		}
		if ( gone[ y ][ x ] ) {
			printf( "LOOP\n" );
		}
		else {
			printf( "%d %d\n", x, y );
		}
	}
	return 0;
}

Measured memory_bytes: 1296
#include <stdio.h>

main(){
  int a, i, j, min = 1000000, max = -1000000;
  long long int sum = 0;

  scanf("%d\n", &i);

  for(j = 0; j < i; j++){
    scanf("%d ", &a);
    if(min > a)min = a;
    if(max < a)max = a;
    sum += a;
  }

  printf("%d %d %lld\n", min, max, sum);

  return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
const int mod = 1e9 + 7;
int main()
{
	int n;
	LL ans = 1;
	cin >> n;
	for(LL i = 1 ; i <= n ; i++)
		{
			ans *= i;
			ans = ans % mod;
		}
	cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 256
// ===========================================
// 20.03.11 Atcdoer DP まとめコンテスト. A - Frog 1 (dp)
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=1; i<=n; i++)
#define rez(i,n) for(int i = 0; i<n; i++)
#define ET "\n"
#define CLR(arr) memset(&arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;
const int mini = 10e5+5;



int main(){
    int n; cin >> n;
    
    int x[mini];
    rep(i,n) cin >> x[i];
    
    ll dp[mini];
    dp[1] = 0;
    dp[2] = abs(x[2] - x[1]);
    
    for(int i=3; i<=n; i++){
        dp[i] = min(dp[i-1] + abs(x[i] - x[i-1]),
                    dp[i-2] + abs(x[i] - x[i-2]));
    }
    cout << dp[n];
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n;

    cin >> n;

    vi v(n);

    int brojNegativnih = 0;

    for(auto &z : v)
    {
        cin >> z;
        if(z < 0)brojNegativnih++;
    }

    ll suma = 0;
    int najmanji = INT_MAX;

    for(int i = 0; i < n - 1; i++)
    {
        if(v[i] < 0)
        {
            v[i] *= -1;
            v[i + 1] *= -1;
        }

        suma += v[i];

        if(abs(v[i]) < najmanji)najmanji = abs(v[i]);
    }

    if(v[n - 1] > 0)
    {
        suma += (ll)v[n - 1];
    }

    else
    {
        if(abs(v[n - 1]) < najmanji)
        {
            suma += (ll)v[n - 1];
        }

        else
        {
            suma -= 2LL * najmanji;
            suma += (ll)abs(v[n - 1]);
        }
    }

    cout << suma << '\n';

    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc097/submissions/14902578 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			int[] q = new int[n];
			IntStream.range(0, n).forEach(i -> q[scanner.nextInt() - 1] = i);
			UnionFindTree uft = new UnionFindTree(n);
			IntStream.range(0, m).forEach(i -> uft.union(scanner.nextInt() - 1, scanner.nextInt() - 1));
			System.out.println(IntStream.range(0, n).filter(i -> uft.same(q[i], i)).count());
		}
	}

	/**
	 * Union Find Treeの実装<br/>
	 * https://atcoder.jp/contests/abc040/submissions/4708654 を参考に作成
	 */
	private static class UnionFindTree {
		int[] parent;
		int[] count;

		UnionFindTree(int size) {
			parent = new int[size];
			IntStream.range(0, size).forEach(i -> parent[i] = i);
			count = new int[size];
			Arrays.fill(count, 1);
		}

		int find(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				int v = find(parent[x]);
				parent[x] = v;
				return v;
			}
		}

		/**
		 * @param x
		 * @param y
		 * @return xとyがつながっているかどうか
		 */
		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		/**
		 * xとyを結合する
		 * 
		 * @param x
		 * @param y
		 */
		void union(int x, int y) {
			int rootX = find(x);
			int rootY = find(y);
			if (rootX == rootY) {
				return;
			}
			parent[rootX] = rootY;
			parent[x] = rootY;
			count[rootY] += count[rootX];
		}

		/**
		 * @param x
		 * @return xと結ぶ都市の数
		 */
		@SuppressWarnings("unused")
		public int count(int x) {
			return count[find(x)];
		}
	}
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REPi(n) for(int i=0;i<n;i++)
#define REPj(n) for(int j=0;j<n;j++)

using namespace std;

int main(){
    string s,fro,las;
    fro="";
    las="";
    int q;
    int count=0;
    cin >> s >> q;
    string x[q][3];
    REPi(q){
        cin >> x[i][0];
        if(x[i][0]=="1"){
            count++;
        }
        if(x[i][0]=="2"){
            cin >> x[i][1] >> x[i][2];
        }
    }

    if(count%2==1){
        int end=(int)(s.length());
        REPj(end/2){
            char temp=s[0+j];
            s[0+j]=s[end-1-j];
            s[end-1-j]=temp;
        }
    }
    int count2=0;
    REPi(q){
        if(x[i][0]=="1"){
            count2++;
        }
        else{
            if(x[i][1]=="1"){
                if((count-count2)%2==1){
                    las+=x[i][2];
                }
                else{
                    fro+=x[i][2];
                }
            }
            else if(x[i][1]=="2"){
                if((count-count2)%2==1){
                    fro+=x[i][2];
                }
                else{
                    las+=x[i][2];
                }
            }
        }
    }
    reverse(fro.begin(),fro.end());
    
    cout << fro << s << las << endl;
    return 0;
}


Measured memory_bytes: 33856
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int k,n;
int a[200001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n)
	cin>>a[i];
	forn(i,k,n){
		if(a[i]>a[i-k]){
			cout<<"Yes\n";
		}else
		cout<<"No\n";
	}
	re 0;
}

Measured memory_bytes: 4436
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int from, to;
	T cost;
	Edge() {}
	Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template<class T>
vector<T> Bellman_Ford(vector<Edge<T>> &edges, int V, int st) {
	
	const T INF = numeric_limits<lint>::max();
	vector<T> dist(V, INF);
	dist[st] = 0;
	for (int i = 0; i <= 2 * V; i++) {
		for (const auto &ele : edges) {
			if (dist[ele.from] == INF) continue;
			if (dist[ele.to] > dist[ele.from] + ele.cost) {
				dist[ele.to] = dist[ele.from] + ele.cost;
				if (ele.to == V - 1 && i >= V) return vector<T>(1);
			}
		}
	}

	return dist;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, P;
	cin >> N >> M >> P;

	int a, b, c;
	vector<Edge<lint>> edges(M);
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--, b--;
		edges[i] = { a, b, P - c };
	}

	auto dist = Bellman_Ford(edges, N, 0);
	DMP(dist);

	lint ans = -dist.back();
	if (dist.size() == 1) cout << "-1\n";
	else if (ans < 0) cout << "0\n";
	else cout << ans << "\n";

	return 0;
}

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

vi p;
vector<bool> bp(55555+1,true);

void sieve(ll n){
    if(n<2)return;
    for(ll i=2; i<=n; i++){
        if(!bp[i])continue;
        p.push_back(i);
        for(ll j=i*i; j<=n; j+=i){
            if(bp[j]) bp[j] = false;
        }
    }
    return;
}

int main(){
    sieve(55555);
    int n; cin >> n;
    
    vi p1;
    rep(i,p.size()){
        if(p[i]%5==1)p1.push_back(p[i]);
    }
    
    rep(i,n){
        cout << p1[i];
        if(i!=n-1) cout << " ";
        else cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int left, right, result;
	char op;
	std::cin >> left >> op >> right;


	if ( op =='+') {
		result = left + right;	
	} else if (op == '-') {
		result = left - right;	
	}
	printf("%d\n", result);
	return 0;
}


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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x; ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}


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

    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, n) {
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(a.begin(), a.end());
    int median = a[n/2];
    forn(i, n) a[i] -= median;
    ll ans = 0;
    forn(i, n) ans += abs(a[i]);
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 	int N,cr,cl,ct=0;
  	cin>>N;
	cin>>cl;
  	for(int i=0;i<N-1;i++){
      	cin>>cr;
    	if(cl==cr){cl=-1*cr;ct++;}
      	else cl=cr;
  	}   
  cout<<ct<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(void){
    // Your code here!
    int i,n,ans;
    char x[1001];
    
    while(1){
        scanf("%s",&x);
        n=strlen(x);
        ans=0;
        if(n==1 && x[0]=='0') break;
        for(i=0;i<n;i++){
            ans +=x[i]-'0';
        }
        printf("%d\n",ans);
    }
    return 0;
    
}



Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


int tbl[101][100];

void solve(int x, int len) {
  if (len % 2 == 1) {
    REP(i, 0, len) {
      REP(j, 0, len - 1) {
	tbl[x + i][j] = x + (i + j + 1) % len;
      }
    }
    return;
  }
  if (len == 4) {
    int magic[4][3] = {
      {1,2,3},
      {3,0,2},
      {1,3,0},
      {2,0,1}};
    REP(i, 0, 4) {
      REP(j, 0, 3) {
	tbl[x + i][j] = x + magic[i][j];
      }
    }
    return;
  }
  assert (len % 2 == 0);
  solve(x, len / 2);
  solve(x + len / 2, len / 2);
  REP(j, 0, len / 2) {
    REP(i, 0, len / 2) {
      tbl[x + i][len / 2 - 1 +j] = x + len / 2 + (i + j) % (len / 2);
      tbl[x + len / 2 + i][len / 2 - 1 + j] = x + (i - j + len / 2 + 1) % (len / 2);
    }
  }
}


int main(void){
  int n;
  cin >> n;
  if (n == 2) {
    cout << -1 << endl;
    return 0;
  }
  solve(0, n);
  REP(i, 0, n) {
    REP(j, 0, n - 1)  {
      cout << tbl[i][j] + 1 << (j == n - 2 ? "\n" : " ");
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	long long inf = 1e18;
	long long mod = 1e9 + 7;

	int n,m;
	cin >> n >> m;

	vector<long long> dp(n + 1, -1);
	dp[0] = 1;

	rep(i, m) {
		int x;
		cin >> x;
		dp[x] = 0;
	}

	for (int i = 1; i < n + 1; i++) {
		if (dp[i] == 0) {
			continue;
		}
		if (i == 1) {
			dp[i] = dp[i - 1];
			continue;
		}
		dp[i] = dp[i - 1] + dp[i - 2];
		if (dp[i] > mod)
			dp[i] %= mod;
	}
	//dp確認用
	/*
	rep(i, n + 1) {
		cout << dp[i] << endl;
	}
	*/


	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4032
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;
int main() {
	char a, b;
	cin >> a >> b;
	if (a > b)cout << ">" << endl;
	else if (a < b)cout << "<"<<endl;
	else cout << "=" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	const int a=nxi(),b=nxi(),c=nxi(),x=std::max(a,std::max(b,c));
	int d=x*3-a-b-c;
	if(d&1) printf("%d\n",(d+3)>>1);
	else printf("%d\n",d>>1);
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  string a, b, c;
  cin >> a >> b;
  c = a + b;

  ll n = atoi(c.c_str());

  REP(i, 400)
  if (n == i * i) {
    cout << "Yes"
         << "\n";
    return 0;
  }
  cout << "No"
       << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

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 int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

void warshall_floyd(const int& n, vector<vector<int>>& d) {
  rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]);
}

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

  ll n, c, k;
  cin >> n >> c >> k;

  vector<ll> t(n);
  rep(i, n) cin >> t[i];
  sort(ALL(t));

  ll num = 0;   // バスに乗ってる数
  ll time = t[0];  // バスに乗っている人で最初に乗った人の時刻
  ll ans = 0;

  for (auto v : t) {
    if (num == 0) {
      time = v;
    }
    if (v <= time + k) {  // 乗せる
      num++;
    } else {   // 乗れない
      ans++;
      num = 1;
      time = v;
    }
    if (num >= c) {
      ans++;
      num -= c;
    }
  }

  if (num > 0) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string s;
    cin >> s;
    ll n=s.size();
    vector<ll>num(n,0);
    for(ll i=0;i<n-1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            for(ll j=i;j>=0&&s[j]=='R';j--){
                num[i+((i-j)%2)]++;
            }
            for(ll j=i+1;j<n&&s[j]=='L';j++){
                num[i+((j-i)%2)]++;
            }
        }
    }
    for(ll i=0;i<n;i++){
        cout << num[i] << " ";
    }
}

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

int main(){
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  for(int i=A;i<C-2;i++){
    if(S.substr(i,2)=="##"){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=B;i<D-2;i++){
    if(S.substr(i,2)=="##"){
      cout << "No" << endl;
      return 0;
    }
  }
  if(C<D){
    cout << "Yes" << endl;
  }else{
    for(int i=B-2;i<D-1;i++){
      if(S.substr(i,3)=="..."){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3740
N=int(input());q=1;t=[0]*N
for i in range(2,N+1):
    s=1
    while i>1:
        s+=1
        while i%s==0:
            i=i//s
            t[s-2]+=1
for j in range(N):
    q=q*(t[j]+1)%(10**9+7)
print(q)

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

int main(){
    int n, t, a; cin >> n >> t >> a;
    vector<int> h(n);
    int reg_diff = INT_MAX;
    int reg_index;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
        if(abs(t*1000-h[i]*6-a*1000)<reg_diff) {
            reg_diff = abs(t*1000-h[i]*6-a*1000);
            reg_index = i;
        }
    }
    cout << reg_index + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		
		long ans = 0;
		for (long i = 1; i * i <= n; i++) {
			if (n % i == 0) ans = i;
		}
		
		System.out.println(ans + n / ans - 2);
	}
}

Measured memory_bytes: 23636
#coding: utf-8
import math
import heapq
import bisect
from scipy.misc import comb

MOD = 10**9+7

N,K = map(int, input().split())

for i in range(1,K+1):
    ans = (comb(K-1,i-1,exact=True)%MOD)*(comb(N-K+1,i,exact=True)%MOD)%MOD
    print(ans)

Measured memory_bytes: 14472
#include <bits/stdc++.h>
#define le 3003
using namespace std;
string a, b, s, ss;
bool vis[le][le];
int dis[le][le];
int fnc(int i, int j){
  if(i == a.size() || j == b.size()) return 0;
  if(vis[i][j]) return dis[i][j];
  int ans = 0;
  if(a[i] == b[j]) ans = 1 + fnc(i + 1, j + 1);
  else ans = max(fnc(i + 1, j), fnc(i, j + 1));
  dis[i][j] = ans;
  vis[i][j] = true;
  return dis[i][j];
}
void pri(int i, int j){
  if(i == a.size() || j == b.size()){
    if(ss == "") ss = s;
    else if(ss > s) ss = s;
    return;
  }
  if(a[i] == b[j]){
    s += a[i];
    pri(i + 1, j + 1);
    s.erase(s.size() - 1);
  }
  else{
    if(dis[i + 1][j] > dis[i][j + 1]) pri(i + 1, j);
    else pri(i, j + 1);
  }
}
int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int t, co = 0;
  //for(scanf("%d", &t); t--; ){
    for(int i = 0; i < le; i++) for(int j = 0; j < le; vis[i][j] = false, dis[i][j] = 0, j++);
    cin >> a >> b;
    int x = fnc(0, 0);
    //printf("Case %d: ", ++co);
    if(x > 0){
      ss = s = "";
      pri(0, 0);
      cout << ss << endl;
    }
    else cout << " \n";
  //}
  return 0;
}


Measured memory_bytes: 44544
class UnionFind
    def initialize(n)
        @size = Array.new(n, 1)
        @par = (0..n-1).to_a
    end

    def root(x)
        x == @par[x] ? x : root(@par[x])
    end

    def unite(x, y)
        rx = root(x)
        ry = root(y)

        if rx != ry
            rx, ry = ry, rx if @size[rx] < @size[ry]
            @par[ry] = rx
            @size[rx] += @size[ry]
        end
    end

    def same?(x, y)
        root(x) == root(y)
    end

    def size(x)
        @size[root(x)]
    end
end

n,m,k = gets.split.map(&:to_i)

tree = UnionFind.new(n+1)
f = Array.new(n+1, 0)
m.times do 
    a, b = gets.split.map(&:to_i)
    tree.unite(a, b)
    f[a] += 1
    f[b] += 1
end

g = Array.new(n+1, 0)
k.times do 
    c, d = gets.split.map(&:to_i)
    if tree.same?(c, d)
        g[c] += 1
        g[d] += 1
    end
end

ans = Array.new(n)
1.upto(n) do |i|
    ans[i-1] = tree.size(i) - f[i] - g[i] - 1
end

puts ans.join(" ")

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

#define ll long long
#define endl "\n"
#define FILEIN freopen("input.txt", "r", stdin)


int main(){
    // FILEIN;

    ll n; cin>>n;
    ll ar[n] = {};
    for(ll i = 0; i<n; i++){
        cin>>ar[i];
    }

    ll dp[n] = {};
    dp[0] = 0, dp[1] = abs(ar[0] - ar[1]);
    for(ll i = 2; i<n; i++){
        if((dp[i-2] + abs(ar[i-2] - ar[i])) < (dp[i-1] + abs(ar[i-1] - ar[i]))){
            dp[i] = (dp[i-2] + abs(ar[i-2] - ar[i]));
        }else{
            dp[i] = (dp[i-1] + abs(ar[i-1] - ar[i]));
        }
    }
    
    cout<<dp[n-1]<<endl;

}

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

#define endl '\n';
#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll int a,b,sum=0;
	cin >> a >> b;
	if(a==1) sum+=300000;
	else if(a==2) sum+=200000;
	else if(a==3) sum+=100000;
	if(b==1) sum+=300000;
	else if(b==2) sum+=200000;
	else if(b==3) sum+=100000;
	if(a==1 && b==1) sum+=400000;
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<vector<ll>> dp(N + 10, vector<ll>(K + 10, 0));
  dp.at(0).at(0) = 1, dp.at(0).at(1) = -1;
  for (ll i = 0; i <= N; i++)
  {
    for (ll j = 0; j <= K; j++)
    {
      if (i != N)
      {
        dp.at(i + 1).at(j) += dp.at(i).at(j);
        dp.at(i + 1).at(j) %= MOD;

        if (j + A.at(i) + 1 <= K)
        {
          dp.at(i + 1).at(j + A.at(i) + 1) += MOD - dp.at(i).at(j);
          dp.at(i + 1).at(j + A.at(i) + 1) %= MOD;
        }
      }

      if (j != K)
      {
        dp.at(i).at(j + 1) += dp.at(i).at(j);
        dp.at(i).at(j + 1) %= MOD;
      }
    }
  }

  /*
  for (ll i = 0; i < N + 1; i++)
  {
    for (ll j = 0; j < K + 1; j++)
    {
      cerr << dp.at(i).at(j) << " ";
    }
    cerr << endl;
  }
  */

  ll ans = dp.at(N).at(K);
  cout << ans << endl;
}

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

struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x = (struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i,size=0,np=0,nd=0;
  char com[20];
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
	if(com[6]=='F')deleteFirst();
	else if(com[6]=='L')deleteLast();
      }
      else{
	deleteKey(key);
	nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



Measured memory_bytes: 33060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int MOD = 1e9 + 7;struct ModularInt{int n;ModularInt(int n_=0):n(n_){}};
ModularInt operator-(ModularInt a){return -a.n+MOD*(a.n!=0);}
ModularInt operator+(ModularInt a,ModularInt b){int x=a.n+b.n;return x-(x>=MOD)*MOD;}
ModularInt operator-(ModularInt a,ModularInt b){int x=a.n-b.n;return x+(x<0)*MOD;}
ModularInt operator*(ModularInt a,ModularInt b){return (long long)a.n*b.n%MOD;}
ModularInt &operator+=(ModularInt &a,ModularInt b){return a=a+b;}
ModularInt &operator-=(ModularInt &a,ModularInt b){return a=a-b;}
ModularInt &operator*=(ModularInt &a,ModularInt b){return a=a*b;}
istream &operator>>(istream &i,ModularInt &a){return i>>a.n;}
ostream &operator<<(ostream &o,ModularInt a){return o<<a.n;}
 
string s;
ModularInt three[1000005];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin >> s;
 
    three[0] = 1;
    for(int i = 1; i <= s.size(); i++)
        three[i] = three[i - 1] * 3;
 
    ModularInt ans = 0;
    ModularInt cnt = 1;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '0')
            continue;
 
        ans += cnt * three[s.size() - i - 1];
        cnt *= 2;
    }
    ans += cnt;
    cout << ans << endl;
}


Measured memory_bytes: 4480
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private fun eratosthenes(bound: Int): Array<Boolean> {
    val primeList = Array(bound + 2) { true }
    val sieveBound = Math.ceil(Math.sqrt(bound.toDouble())).toInt()
    primeList[0] = false
    primeList[1] = false
    for (i in 2 .. sieveBound) {
        if (!primeList[i]) continue
        for (j in (2 * i .. bound).step(i)) {
            primeList[j] = false
        }
    }
    return primeList
}

private fun Array<Boolean>.toPrimes() = mapIndexedNotNull { index, isPrime ->
    if (isPrime) index else null
}

private val primes = eratosthenes(1000).toPrimes()

private fun pFactorIn(n: Int, p: Int): Int {
    var pPow = p
    var res = 0
    while (pPow <= n) {
        res += n / pPow
        pPow *= p
    }
    return res
}

fun main(args: Array<String>) {
    val N = readInts()[0]
    val pFactors = primes.map { pFactorIn(N, it) }
    val ans = pFactors.map { it.toLong() + 1L }.reduce { l1, l2 -> (l1 * l2) % 1000000007L }
    println(ans)
}

Measured memory_bytes: 36204
import Control.Applicative

main = solve

solve = do
    n <- fmap (read :: String -> Int) . words <$> getLine
    let a = n !! 0
        b = n !! 1
        c = n !! 2
    putStrLn $ show (calc a b c)

calc :: Int -> Int -> Int -> Int
calc a b c = length . filter (\x -> c `mod` x == 0) $ [a..b]

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

#define int long long

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

int n;
	cin >> n;
	int k = n%10;
	map<int, string> mp;
	mp[2] = "hon"; mp[5] = "hon"; mp[7] = "hon"; mp[9] = "hon"; mp[4] = "hon";
	mp[0] = "pon"; mp[1] = "pon"; mp[6] = "pon"; mp[8] = "pon";
	mp[3] = "bon";
	cout << mp[k];
	
	return 0;
}


Measured memory_bytes: 3656
import sys
from itertools import product

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


H, W = il()
S = imi(H, str)
tree = UnionFind(H * W)
for i, j in product(range(H), range(W)):
    for d in ((-1, 0), (0, -1), (1, 0), (0, 1)):
        x = i + d[0]
        y = j + d[1]
        if 0 <= x < H and 0 <= y < W:
            if S[i][j] != S[x][y]:
                tree.union((i * W + j), (x * W + y))

k = set(tree.par)
dot = {i: 0 for i in k}
sharp = {i: 0 for i in k}
for i, j in product(range(H), range(W)):
    if S[i][j] == ".":
        dot[tree.find(i * W + j)] += 1
    else:
        sharp[tree.find(i * W + j)] += 1

ans = 0
for i in k:
    ans += dot[i] * sharp[i]
print(ans)


Measured memory_bytes: 32312
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 


long long int N,M,K,sum=0,res=0;

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;
    if(N<=M){cout<<"unsafe"<<endl;}
    else{cout<<"safe"<<endl;}
    
}    


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-------------------------------------------------


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

    string s, t;
	cin >> s >> t;
	int sz = s.size();
	REP(i, sz) {
		bool flg = true;
		REP(j, sz)  {
			if (s[(i + j) % sz] != t[j]) flg = false;
		}
		if (flg) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
fir,sec = -1,-1
fi = -1
for i,x in enumerate(a):
    if x > fir:
        fir,fi = x,i
    elif x > sec:
        sec = x
for i in range(n):
    if i == fi:
        print(sec)
        continue
    print(fir)

Measured memory_bytes: 12640
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"

int modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin >> n;
    int arr[n];
    FOR(i,0,n) cin >> arr[i];
    int suff[n] = {0}, pref[n] = {0};
    if (n > 1)
    {
        pref[1] = arr[0];
        suff[n-2] = arr[n-1];
    }

    FOR(i,2,n) pref[i] = __gcd(pref[i-1], arr[i-1]);
    FORR(i,n-2,-1) suff[i] = __gcd(suff[i+1], arr[i+1]);
    
    int ans = 0;
    FOR(i,0,n)
    {
        if (i == 0 or i == n-1)
        {
            if (i == 0)
                ans = max(ans, suff[0]);
            else
                ans = max(ans, pref[n-1]);
            continue;
        }
        ans = max(ans, __gcd(pref[i], suff[i]));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr ll INF = 1e18;

void chmax(ll &x, ll y) {
  x = max(x, y);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<ll> LF(N + 1, -INF);
  vector<ll> RF(N + 1, -INF);
  vector<ll> LB(N + 1, -INF);
  vector<ll> RB(N + 1, -INF);
  LF[0] = 0;
  for (int i = 0; i + 2 <= N; i += 2) {
    chmax(LF[i + 2], LF[i] + A[i]);
    chmax(RF[i + 2], LF[i] + A[i + 1]);
    chmax(RF[i + 2], RF[i] + A[i + 1]);
  }
  RB[N] = 0;
  for (int i = N; i - 2 >= 0; i -= 2) {
    chmax(RB[i - 2], RB[i] + A[i - 1]);
    chmax(LB[i - 2], RB[i] + A[i - 2]);
    chmax(LB[i - 2], LB[i] + A[i - 2]);
  }
  ll ans = 0;
  if (N % 2 == 0) {
    ll cand0 = 0, cand1 = 0;
    for (int i = 0; i < N; i += 2) {
      cand0 += A[i];
      cand1 += A[i + 1];
    }
    ans = max(cand0, cand1);
  } else {
    ll cand = 0;
    for (int i = 0; i < N; i += 2) {
      cand += A[i];
    }
    ans = cand;
  }
  if (N % 2 == 1) {
    for (int i = 0; i < N; i += 2) {
      chmax(ans, max(LF[i], RF[i]) + max(LB[i + 1], RB[i + 1]));
    }
  } else {
    for (int i = 0; i <= N; i++) {
      chmax(ans, LF[i] + RB[i]);
      chmax(ans, LF[i] + RB[i]);
      chmax(ans, RF[i] + RB[i]);
    }
  }
  cout << ans << endl;
}

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

ll n, m, a[1000000], b, c, ans;
l_l cb[1000000];

int main() {
    cin >> n >> m;
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<m; i++) {
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }
    sort(a, a+n);
    sort(cb, cb+m, greater<l_l>());

    int it, nit = -1;
    for (int i=0; i<n; i++) {
        ll B = cb[i].second;
        ll C = cb[i].first;
        it = nit;
        nit = it + B;
        if (nit >= n || a[nit] > C) {
            for (int j = it+1; j<n; j++) ans += max(C, a[j]);
            break;
        }
        ans += C*B;
    }  
    cout << ans << endl;
}


Measured memory_bytes: 5888
#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal

#N=int(input())
#A,B = map(float,input().split())
#T=int(input())
#A = list(map(int,input().split()))
S=str(input())

print(S[:3])


Measured memory_bytes: 8936
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = n - 1 downto 0 do
    acc.(i) <- as_.(i) +^ acc.(i + 1)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( +^ ) 0 @@
  Array.init (n - 1) @@ fun i -> as_.(i) *^ acc.(i + 1)



Measured memory_bytes: 10728
#include<stdio.h>
int main(){
  int A,B,T,n=0;
  scanf("%d%d%d", &A,&B,&T);
  int t=A;
  
  while(t < T+1){
    n+=B;
    t+=A;
  }
  printf("%d", n);
    
  return 0;
}

Measured memory_bytes: 128