akhauriyash/Code-Regression huggingface dataset:
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ----------- debug ---------- */

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    return b == 0 ? a : gcd(b, a % b);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

template <typename T>
T iceil(T n, T d) {
    return (n + d - 1) / d;
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int n,p;
int a[100100];
int e,o;
ll ans;

int main(){
	cin>>n>>p;
	REP(i,n){
		cin>>a[i];
		if(a[i]%2==0)e++;
		if(a[i]%2==1)o++;
	}
	if(p==1&&o==0){
			cout<<0<<endl;
			return 0;
	}else if(o==0){
		cout<<(ll)pow(2LL,n)<<endl;
		return 0;
	}
	cout<<(ll)pow(2LL,n-1)<<endl;
	return 0;
}	

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000

int linerSearch(int [],int,int);
int main(){
    int A[N],i,n,q,key,x,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&key);
        x= linerSearch(A,n,key);
        if(x == 0) cnt++;
    }
    printf("%d\n",cnt);

    return 0;
}


  int  linerSearch(int A[],int n, int key){
        int i=0;
        A[n]=key;
        while(A[i]!=key){
            i++;
        }
        if(i==n) return 1;
        else return 0;
    }



Measured memory_bytes: 2108
//iejr Header files
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <limits.h>
#include <ctime>
#include <cctype>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

//iejr: Type defination
typedef unsigned long long int             ULLN;
typedef long long int                      LLN;
typedef vector<int>                        VI;
typedef vector<vector<int> >               VVI;
typedef vector<string>                     VS;
typedef vector<vector<string> >            VVS;


//iejr: Compile Options
//#define C11_Standard
//
#ifdef C11_Standard
    #include <unordered_set>
    #include <unordered_map>

    #define HASHSET                  unordered_set
    #define HASHMAP                  unordered_map;
#endif // C11_Standard


//iejr: Local Debug
//#define INPUT_REDIRECTION
//#define OUTPUT_REDIRECTION


//iejr: Main Function
int main()
{

#ifdef INPUT_REDIRECTION
    freopen( "in.txt", "r", stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    freopen( "out.txt", "w", stdout );
#endif // OUTPUT_REDIRECTION

    LLN A, B, C;
    while( scanf( "%lld%lld%lld", &A, &B, &C ) != EOF ){
        LLN diff = LONG_LONG_MAX;

        LLN half = A / 2;
        LLN another = A - half;
        diff = min( diff, abs( another - half ) * B * C );

        half = B / 2 ;
        another = B - half;
        diff = min( diff, abs( another - half ) * A * C );

        half = C / 2;
        another = C - half;
        diff = min( diff, abs( another - half ) * A * B );

        printf( "%lld\n", diff );
    }

#ifdef INPUT_REDIRECTION
    fclose( stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    fclose( stdout );
#endif // OUTPUT_REDIRECTION

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<algorithm>
typedef signed long long int int64;
inline unsigned getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register unsigned x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
const int64 inf=0x7ffffffffffffff;
const int N=200001;
int n;
class FenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		FenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			val[p]=x;
			while(p<=n) {
				val[p]=std::min(val[p],x);
				p+=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p) {
				ret=std::min(ret,val[p]);
				p-=lowbit(p);
			}
			return ret;
		}
};
FenwickTree ta;
class RevFenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		RevFenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			val[p]=x;
			while(p) {
				val[p]=std::min(val[p],x);
				p-=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p<=n) {
				ret=std::min(ret,val[p]);
				p+=lowbit(p);
			}
			return ret;
		}
};
RevFenwickTree tb;
int64 f[N];
inline void modify(const int &p,const int64 x) {
	if(x<f[p]) {
		f[p]=x;
		ta.modify(p,x-p);
		tb.modify(p,x+p);
	}
}
int main() {
	n=getint();
	int q=getint(),a=getint(),b=getint();
	std::fill(&f[0],&f[N],inf);
	modify(a,0);
	int64 sum=0;
	while(q--) {
		a=b;
		b=getint();
		sum+=abs(a-b);
		int64 t1=ta.query(b)+b,t2=tb.query(b)-b;
		modify(a,std::min(t1,t2)-abs(a-b));
	}
	int64 tmp=inf;
	for(int i=1;i<=n;i++) {
		tmp=std::min(tmp,f[i]);
	}
	printf("%lld\n",tmp+sum);
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> p1,pair<int,int> p2)
{
  return (p1.second<p2.second);
}
int main()
{
 int n;
  cin>>n;
  pair<int,int> arr[n];
  for(int i=0;i<n;i++)
  {
    arr[i].first=i+1;
    cin>>arr[i].second;

  }
  sort(arr,arr+n,comp);
  for(int i=0;i<n;i++)
  {
    cout<<arr[i].first<<" ";
  }
  
  
}

Measured memory_bytes: 4272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  ll n; cin >> n;
  if(n % 2){
    cout << 0 << endl;
  }else{
    ll now = 5;
    ll ans = 0;
    ll div = 1;
    while(now < n){
      ans += (n/now)/2;
      now *= 5;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

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

    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int jj = 0;

    for (int j = 1; j <= n - 2; ++j) {
        if ((p[j] - p[j - 1]) * (p[j] - p[j + 1]) < 0) { ++jj; }
    }

    cout << jj << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> vec;
    ll res = 2e18;
    bool zero = false;
    for (int i = 0; i < n; i++) {
        ll in;
        cin >> in;
        if (in == 0)
            zero = true;
        vec.push_back(in);
    }
    if (!zero)
        vec.push_back(0);
    sort(vec.begin(), vec.end());
    int idx = 0;
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] == 0)
            idx = i;
    }
    for (int i = idx; i < vec.size(); i++) {
        ll curr = vec[i];
        ll cnt = i - idx + zero;
        ll lft = k - cnt;
        if (lft == 0) {
            res = min(res, curr);
        }
        else {
            if (idx - lft >= 0) {
                res = min(res, curr + abs(curr - vec[idx - lft]));
            }
        }
    }

    for (int i = idx; i >= 0; i--) {
        ll curr = abs(vec[i]);
        ll cnt = idx - i + zero;
        ll lft = k - cnt;
        if (lft == 0) {
            res = min(res, curr);
        }
        else {
            if (idx + lft < vec.size()) {
                res = min(res, curr + abs(vec[i] - vec[idx + lft]));
            }
        }
    }
    cout << res;
    return  0;
}

Measured memory_bytes: 1400
import bisect

def solve():
    N = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i] + Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i -1
            else:
                pass
    print(ans)

solve()



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
 ll int dp[100001][101];
int main() {

 ll int n,k;
  cin>>n>>k;

  memset(dp,0,sizeof dp);
 ll int a[101];
  for(ll int i=0;i<n;i++)
    cin>>a[i];
  for(ll int i=0;i<n;i++)
    dp[0][i]=1;
//cout<<endl<<endl;  
 //ll int sum=a[0];
  for(int i=0;i<=a[0];i++)
  {dp[i][0]=1;}

for(ll int i=1;i<n;i++)
{
ll int sums[k+1]={0};
        sums[0]=dp[0][i-1];
        //cout<<"sum -> "<<sums[0];
        for(int j=1;j<=k;j++)
        {
            sums[j]=(sums[j-1]+dp[j][i-1]);  ///Calculate the prefix sums for i-1
        
        }
//cout<<endl;
for(ll int j=1;j<=k;j++)
{
ll int unreach=j-a[i]-1;
ll int tr=0;
if(unreach>=0)
{
tr=sums[unreach];
}
 dp[j][i]=(sums[j]-tr+mod)%mod;


}



}


 cout<<dp[k][n-1]<<endl;

  

}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1450555;
const int M = 1155;
const int L = 20;

void solve() {
    int n, k;
    cin >> n >> k;

    VI v;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        v.PB(x);
    }

    sort(ALL(v));

    int sum = 0;
    for (int i = 0; i < k; i++){
        sum += v[i];
    }

    cout << sum;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3680
#define _USE_NATH_DEFINES
#include <iostream>
#include<sstream>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
	else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
    int N,ryou = 0,first = 0,last = 0,AB = 0,a,i,j;
    char S[12];
    scanf("%d",&N);
    for (i = 0;i < N;i++) {
        scanf("%s",S);
        a = strlen(S);
        for (j = 0;j < a - 1;j++) {
            if (S[j] == 'A' && S[j + 1] == 'B') AB++;
        }
        if (S[0] == 'B' && S[a - 1] == 'A') {
            ryou++;
        } else if (S[0] == 'B') {
            first++;
        } else if (S[a - 1] == 'A') {
            last++;
        }
    }
    if (first == 0 && last == 0 ) {
        if (ryou == 0) {
            printf("%d\n",AB);
        } else {
            printf("%d\n",ryou + AB - 1);            
        }
    } else if (first <= last) {
        printf("%d\n",first + ryou + AB);
    } else {
        printf("%d\n",last + ryou + AB);
    }
    return 0;
}


Measured memory_bytes: 128
(* O(n^2) *)
let s = read_line ()
let n = String.length s
let i = ref 2
let is_even s = let m = String.length s in String.sub s 0 @@ m / 2 = String.sub s (m / 2) @@ m / 2
let _ =
  while !i < n do
    if is_even @@ String.sub s 0 @@ n - !i then (Printf.printf "%d\n" @@ n - !i; exit 0);
    i := !i + 2
  done

Measured memory_bytes: 384
N, M = map(int, input().strip().split())

ab = []
for i in range(0,M):
    inp = list(map(int,input().strip().split()))
    ab.append((inp[0],inp[1]))

abl = sorted(ab,key=lambda x: x[1])

rightest_cut = 0
count = 0

for m in abl:
    if m[0] <= rightest_cut:
        continue
    rightest_cut = m[1] -1
    count += 1

print(count)





Measured memory_bytes: 18968
def main():
    N = int(input())
    X = list(map(int, input().split()))

    P = sum(X) // N
    ans1 = 0
    for x in X:
        ans1 += (x - P) ** 2
    ans2 = 0
    for x in X:
        ans2 += (x - (P + 1)) ** 2
    print(min(ans1, ans2))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>

#define N 2000
#define MAX 2000

int solve(int,int);

int g,a[MAX];;

int main(){
  int i,j,n,k;
  int b[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  g=n;

  scanf("%d",&j);
  for(i=0;i<j;i++){
    scanf("%d",&b[i]);
    if(solve(0,b[i])) printf("yes\n");
    else printf("no\n");
  }

/*  g = j;

  for(i=0;i<n;i++){
  k = solve(j,b[i],a);

  if(k==0) printf("yes\n");
  else printf("no\n");
  }*/

  return 0;

}

int solve(int i,int m){
  int res;

  if(m == 0)
    return 1;
  if(i >= g)
    return 0;
  res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;

}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
int abs(int a,int b){
  int res=max(a,b)-min(a,b);
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<int> high(n);
  for(int i=0;i<n;i++)
    cin >> high.at(i);
  vector<int> sco(n,0);
  sco.at(1)=abs(high.at(1),high.at(0));
  for(int i=2;i<n;i++){
    sco.at(i)=min(sco.at(i-1)+abs(high.at(i),high.at(i-1)),
                  sco.at(i-2)+abs(high.at(i),high.at(i-2)));
  }
  cout << sco.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>

#define N 3

int main(){
    std::array<int, N> a;
    for(int i=0; i<N; i++) std::cin >> a[i];
    
    int c = 1;
    while(c>0){
        c = 0;
        for(int i=0; i<N-1; i++){
            if(a[i] > a[i+1]){
                int tmp = a[i];
                a[i] = a[i+1];
                a[i+1] = tmp;
                c++;
            }
        }
    }
    for(int i=0; i<N ; i++){
        if(i) std::cout << " ";
        std::cout << a[i];
    }
    std::cout << std::endl;
    
    return 0;
}



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

using namespace std;

int main() {
    long long n, m, k;
    cin >> n >> m >> k;

    long long cn = n * m - 2, ck = min(k - 2, cn - k + 2);
    long long mod = 1000000007;

    vector<long long> inv(ck + 1, 0);
    inv[1] = 1;
    for (int i = 2; i <= ck; i++) {
        inv[i] = mod - (inv[mod % i] * (mod / i)) % mod;
    }

    long long c = 1;
    for (int i = 0; i < ck; i++) {
        c *= (cn - i) % mod * inv[i + 1] % mod;
        c %= mod;
    }

    long long res = 0;
    for (int i = 1; i < n; i++) {
        res += i * (n - i) % mod * m % mod * m % mod * c % mod;
        res %= mod;
    }
    for (int i = 1; i < m; i++) {
        res += i * (m - i) % mod * n % mod * n % mod * c % mod;
        res %= mod;
    }

    cout << res << endl;
}


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

int main()
{
    int x[10];
    for (unsigned int i = 0; i < (sizeof(x) / sizeof(int)); i++)
        cin >> x[i];
    int first = 0;
    unsigned first_num;
    for (unsigned int i = 0; i < (sizeof(x) / sizeof(int)); i++)
        if (x[i] > first) {
            first = x[i];
            first_num = i;
        }
    int second = 0;
    unsigned second_num;
    for (unsigned int i = 0; i < (sizeof(x) / sizeof(int)); i++)
        if (x[i] > second && i != first_num) {
            second = x[i];
            second_num = i;
        }
    int third = 0;
    unsigned third_num;
    for (unsigned int i = 0; i < (sizeof(x) / sizeof(int)); i++)
        if (x[i] > third && i != first_num && i != second_num) {
            third = x[i];
            third_num = i;
        }
    cout << first << endl;
    cout << second << endl;
    cout << third << endl;
}

Measured memory_bytes: 3084
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W >> K;
	vector< vector< int > > grid(H, vector< int >(W, 0));
	rep(i, K) {
		int r, c, v;
		cin >> r >> c >> v;
		--r;
		--c;
		grid[r][c] = v;
	}
	int ans = 0;
	vector< vector< vector< int > > > dp(H, vector< vector< int > >(W, vector< int >(4, -1)));
	auto f = [&](auto &&f, int i, int j, int k) -> int {
		if (dp[i][j][k] != -1)
			return dp[i][j][k];
		if (i == 0 && j == 0) {
			if (k > 0)
				return grid[0][0];
			else
				return 0;
		}
		int ret = 0;
		if (grid[i][j] > 0 && k > 0) {
			if (i > 0) {
				chmax(ret, grid[i][j] + f(f, i - 1, j, 3));
			}
			if (j > 0 && k > 0) {
				chmax(ret, grid[i][j] + f(f, i, j - 1, k - 1));
			}
		}
		if (i > 0)
			chmax(ret, f(f, i - 1, j, 3));
		if (j > 0)
			chmax(ret, f(f, i, j - 1, k));
		return dp[i][j][k] = ret;
	};
	rep(k, 4) chmax(ans, f(f, H - 1, W - 1, k));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 706880
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a,b;cin>>a>>b;
	if(a<10 && b<10) cout<<a*b<<endl;else cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(123456789012345678)


int main(void){
  int N;  cin >> N;
  int mode = N % 2;
  int M = N*(N-1)/2;
  if (mode)  {
    cout << M-(N-1)/2 << endl;
    reps(i, N-1) {
      for(int j=i+1; j<=N; j++) {
        if (j != N-i) {
          cout << i << " " << j << endl;
        }
      }
    }
  } else  {
    cout << M-N/2 << endl;
    reps(i, N-1) {
      for(int j=i+1; j<=N; j++) {
        if (j != N+1-i) {
          cout << i << " " << j << endl;
        }
      }
    }
  }

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	public static void main(String[] args) {
		try {
			//Input
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str;
			String[] num;
			position pos = new position("0", "0", 90);

			while ((str = br.readLine()) != null) {
				num = str.split(",", 0);
				if ((Integer.parseInt(num[0]) == 0) && (Integer.parseInt(num[1]) == 0)) {
					break;
				} else {
					BigDecimal dis = new BigDecimal(num[0]);
					int deg = Integer.parseInt(num[1]);
					pos.move(dis, deg);
				}
			}
			//Output
			System.out.println(pos.x.intValue());
			System.out.println(pos.y.intValue());
		} catch (Exception e) {
			System.out.println("error");
		}

	}

}

class position {
	BigDecimal x;
	BigDecimal y;
	int degree;

	public position (String a, String b, int c) {
		this.x = new BigDecimal(a);
		this.y = new BigDecimal(b);
		this.degree = c;
	}

	public void move (BigDecimal dis, int deg) {
		double sin = Math.sin(Math.toRadians(this.degree));
		double cos = Math.cos(Math.toRadians(this.degree));
		BigDecimal move_x = new BigDecimal(dis.multiply(BigDecimal.valueOf(cos)).toPlainString());
		BigDecimal move_y = new BigDecimal(dis.multiply(BigDecimal.valueOf(sin)).toPlainString());
		this.x = this.x.add(move_x);
		this.y = this.y.add(move_y);
		this.degree = this.degree - deg;
	}
}

Measured memory_bytes: 24644
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s = S().rstrip()
	while len(s) > 0:
		if s[-7:] == 'dreamer':
			s = s[:-7]
		elif s[-5:] == 'dream':
			s = s[:-5]
		elif s[-6:] == 'eraser':
			s = s[:-6]
		elif s[-5:] == 'erase':
			s = s[:-5]
		else:
			print('NO')
			break
	else:
		print('YES')

if __name__ == '__main__':
    main()

Measured memory_bytes: 27348
#include <limits.h>
#include <algorithm>
#include <bitset>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

    string s;
    cin >> s;

    // white
    int ans1 = 0;
    REP(i, s.size()) {
        char c = s[i];
        if (i % 2 == 0) {
            // white
            if (c == '1') {
                ans1++;
            }
        }
        else {
            if (c == '0') ans1++;
        }
    }

    int ans2 = 0;
    REP(i, s.size()) {
        char c = s[i];
        if (i % 2 == 1) {
            // white
            if (c == '1') ans2++;
        }
        else {
            if (c == '0') ans2++;
        }
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int kaku_keta_wa(int N);

int main(void) {
	int N; cin >> N;

	if (N % 10 == 0) { cout << kaku_keta_wa(N) << "0"; }
	else { cout << kaku_keta_wa(N); }

	return 0;
}

int kaku_keta_wa(int N) {
	int M, sum = 0;
	while (N) {
		M = N % 10;
		sum = sum + M;
		N = N / 10;
	}
	return sum;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
			pr.println("Bad");
		} else {
			pr.println("Good");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long long A,B,a,b,c=0,k,d=0,i,n,j,temp,p,m,ex1,ex2,ex3,ex4,x,y;
	    string s;
	    cin>>n;
	    A=1;B=1;
	    long long ans;
	    for(i=0;i<n;i++)
	    {
	        cin>>a>>b;
	        k=max((A-1)/a,(B-1)/b)+1;
	        A=k*a;B=k*b;
	    }
	    cout<<A+B;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  int N;
  cin >> N;
  if(N%2==0) {
    cout << N/2 << endl;
  } else {
    cout << (N+1)/2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n, m, v, p; cin >> n >> m >> v >> p;
	map<int64_t, int64_t> cnt;
	rep(i,n) {
		int64_t a; cin >> a;
		cnt[a]++;
	}
	int64_t sum = 0;
	int64_t ans = 0;
	int64_t bor = -1, borsum, disum = 0, dicnt = 0;
	for(auto itr = cnt.rbegin(); itr != cnt.rend(); ++itr) {
		auto e = *itr;
		int64_t idx = e.first;
		int64_t tmp = e.second;
		if(sum + tmp >= p and bor == -1) {
			bor = idx;
			borsum = sum;
		} else {
			auto pre = itr;
			pre = prev(pre);
			if((*(pre)).first < bor) {
				disum += (bor - (*(pre)).first) * (*(pre)).second;
				dicnt += (*(pre)).second;
			}
		}
		if(sum + tmp <= p or sum < p) {
			ans += tmp;
			sum += tmp;
			continue;
		}
		sum += tmp;
		int64_t x = (n - sum + tmp - 1);
		if(x >= v - 1) {
			if(idx + m >= bor) {
				ans += tmp;
			} else {
				break;
			}
		} else {
			// cerr << idx << " " << dicnt << " " << disum << endl;
			int64_t mo = v - 1 - x;
			if(p - 1 >= mo) {
				if(idx + m >= bor) {
					// cerr << mo << " " << x << '\n';
					ans += tmp;
				} else {
					break;
				}
			} else {
				mo -= (p - 1);
				int64_t usum = n - (x + 1) - (p - 1);
				if(usum <= mo) {
					break;
				}
				if(dicnt >= mo) {
					// cerr << dicnt << " " << mo << endl;
					int64_t ne = mo * m - disum;
					if(ne <= 0) {
						if(idx + m >= bor) {
							// cerr << idx << " " << ne << '\n';
							// cerr << mo << " " << x << '\n';
							ans += tmp;
						} else {
							break;
						}
					} else {
						int64_t pl = ne / usum;
						assert(pl >= 0);
						int64_t am = ne % usum;
						assert(am >= 0);
						if(am == 0) {
							if(idx + m >= bor + pl) {
								ans += tmp;
							} else {
								break;
							}
						} else {
							if(borsum + am < p) {
								if(idx + m >= bor + pl) {
									ans += tmp;
								} else {
									break;
								}
							} else {
								if(idx + m >= bor + pl + 1) {
									ans += tmp;
								} else {
									break;
								}
							}
						}
					}
				}
			}
		}
	}
	cout << ans <<'\n';
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll n;
    sc(n);
    ll cnt =0;
    for(ll i=1;i<=n;i++)
    {
        ll x;
        sc(x);
        if(i%2==1 and x%2==1)cnt++;
    }
    printf("%lli\n",cnt);
}

int main()
{
    ll t=1;
 //   sc(t);
    while(t--) solve();
}





Measured memory_bytes: 3772
#include<bits/stdc++.h> 
using namespace std; 
int gcdEx(int a, int b, int *x, int *y){if(!a){*x=0;*y=1;return b;} 
int x1,y1,gcd=gcdEx(b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
int modI(int b, int m)      {int x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
typedef long long           ll;
typedef pair<int, int>      pii;
typedef vector<int>         vi;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(b,n)           for(int i=b;i<n;i++)
#define loopv(b,n,a)         for(int i=b;i<n;i+=a)
#define loopr(b,n)           for(int i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define MOD                 1000000007 
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(int)(MOD+((a%MOD)-(b%MOD))%MOD):(int)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (int)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;}
y=y>>1; x=(x*x)%MOD;} return r;}


int main()
{ 
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n,a,b,ans;
    cin>>n>>a>>b;
    ans=min(a*n,b);
    cout<<ans<<"\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<cstdint>

//RMQ
class segmentTree{
private:
    using Int = int_fast64_t;
    
    size_t size;
    const Int INF = (1ll << 31) - 1ll;
public:
    std::vector<Int> arr;
    segmentTree(size_t range){
        size = 1;
        while(size < range) size <<= 1;
        arr.assign(2*size-1, INF);
    }
    segmentTree(const std::vector<Int>& vec){
        size = 1;
        while(size < vec.size()) size <<= 1;
        arr.assign(2*size-1, INF);
        for(size_t i = 0; i < vec.size(); ++i) arr[i+size-1] = vec[i];
        for(size_t i = size-2; i >= 0; i--) arr[i] = std::min(arr[2*i+1], arr[2*i+2]);
    }
    
    void update(size_t idx, Int value){
        idx += (size - 1);
        arr[idx] = value;
        while(idx > 0){
            idx = (idx-1) / 2;
            arr[idx] = std::min(arr[2*idx+1], arr[2*idx+2]);
        }
    }

    Int minQuery(size_t L, size_t R, size_t idx=0, size_t l=0, size_t r=1e16+9){
        if(r > 1e16) r = size;

        if(r <= L || R <= l) return INF;
        if(L <= l && r <= R) return arr[idx];

        Int MIN = INF;
        MIN = std::min(minQuery(L, R, 2*idx+1, l, (l+r)/2), MIN);
        MIN = std::min(minQuery(L, R, 2*idx+2, (l+r)/2,r), MIN);
        return MIN;
    }
};
#include<iostream>
using namespace std;
int main(){
    int N,Q;
    cin >> N >> Q;

    segmentTree segTree(N);
    for(size_t q = 0; q < Q; q++){
        size_t com, x, y;
        cin >> com >> x >> y;
        if(!com) segTree.update(x, y);
        else cout << segTree.minQuery(x, y+1) << endl;
    }
}



Measured memory_bytes: 4916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
    
    int a, b, c,d ;
    cin>>a>>b>>c>>d;
    int cnt=1;
    while(a>0 && c>0){
        if(cnt%2==0){
            a-=d;
        }else{
            c-=b;
        }
        cnt++;
    }
    if(a>0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cctype>
#define rep(x,y,z) for(long long x=y;x<z;++x)
#define dwn(x,y,z) for(long long x=y;x>z;--x)
using namespace std;

typedef long long ll;

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

int main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    if (n < m) {
        swap(n, m);
        swap(s, t);
    }
    ll nod = Nod(n, m);
    ll nok = n * m / nod;
    for (int i = 0; i < nod; i++) {
        if (s[i * (n / nod)] != t[i * (m / nod)]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << nok << endl;
    return 0;
}

Measured memory_bytes: 512
def f(v, i):
    s = 4 * 2 ** v - 3
    n = 2 * 2 ** v - 1
    m = (s + 1) / 2
    return 0 if i < 1 or i > s else [0, f(v - 1, i - 1), n / 2 + 1, f(v - 1, i - s / 2 - 1) + n / 2 + 1, n, 1][(i > 1) + (i >= m) + (i > m) + (i >= s) + (v == 0) * 3]

print f(*map(int, raw_input().split()))

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

int main() {
    int n;
	cin >> n;
	double a;
	double r=0.0;
	string s;
	
	for(int i=0;i<n;i++){
	      cin >> a >> s;
		  if(s== "JPY") r+=a;
		  else r+= a* 380000.0;
	      
	}
	cout << r << endl;
}


Measured memory_bytes: 256
<?php 
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    /**
    * @return mixed
    */
    public function next() {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    /**
    * @return bool
    */
    public function hasNext() {
        return $this->pointer < $this->count;
    }

    /**
    * @return int
    */
    public function nextInt() {
        return (int)$this->next();
    }

    /**
    * @return float
    */
    public function nextDouble() {
        return (double)$this->next();
    }
}

// 入力を取得する
$sc = new Scanner();
$n = $sc->nextInt();
$nodeCostList = array();
$edgeList = array();
foreach (range(0,$n-1) as $lineNum) {
    $u = $sc->nextInt();
    $nodeCostList[$u] = INF;

    $k = $sc->nextInt();

    foreach (range(0, $k-1) as $setNum) {
        $v = $sc->nextInt();
        $c = $sc->nextInt();
        $edgeList[$u][$v] = $c;
    }
}

/**
 * 入力
 * 5
 * 0 3 2 3 3 1 1 2
 * 1 2 0 2 3 4
 * 2 3 0 3 3 1 4 1
 * 3 4 2 1 0 1 1 4 4 3
 * 4 2 2 1 3 3
 */

/*
 * $edgeList
 * [
 *      0 => [
 *               2 => 3,
 *               3 => 1,
 *               1 => 2,
 *           ],
 *      1 => [
 *               0 => 2,
 *               3 => 4,
 *           ],
 * ]
 */
//var_dump($edgeList);

/*
 * 結果
 * [
 *      0 => 0,
 *      1 => 2,
 *      2 => 2,
 *      3 => 1,
 *      4 => 3
 * ]
 */
$result = [];

$nodeCostList[0] = 0;
$targetNode = 0;

while (true) {
	// 0から伸びる経路で最もコストの低いノードを選択する
	// $nodeCostListから
	$minNode = 0;
	$minCost = INF;
	foreach ($nodeCostList as $node => $cost) {
		if (isset($result[$node])) {
			continue;
		}
		if ($cost < $minCost) {
			$minCost = $cost;
			$minNode = $node;
		}
	}
	$result[$minNode] = $minCost;
	if (count($result) == $n) {
		break;
	}
	$targetNode = $minNode;

	// $nodeCostListを更新する
	foreach ($edgeList[$targetNode] as $node => $cost) {

		// fixしたノードは選択しない
		if (isset($result[$node])) {
			continue;
		}

		// 現在地（targetNode）までのコストとそこから伸びるノードへのコストを足したものが小さければ更新する
		if ($nodeCostList[$targetNode] + $cost < $nodeCostList[$node]) {

			// 選択したノードとそのコストを最短経路としてfixする
			$nodeCostList[$node] = $nodeCostList[$targetNode] + $cost;
		}
	}
}

ksort($result);
foreach ($result as $node => $cost) {
	echo $node . ' ' . $cost . "\n";
}



Measured memory_bytes: 10232
#include <bits/stdc++.h>
using namespace std;
//
//int f(int x, int y){
//	if(y==1){
//		return DP[x][y] = arr[x]*(-1)+f(x+1,0);
//	} else{
//		return DP[x][y] = max(arr[x]+f(x+1,0),arr[x]+f())
//	}
//}

int neg,n;
long long arr[100005],sum,mini;


int main(){
	scanf("%d",&n);
	mini = 1000000000;
	for(int i =1;i<=n;i++){
		scanf("%lld",&arr[i]);
		sum+=abs(arr[i]);
		mini = min(abs(arr[i]),mini);
		if(arr[i]<0) neg++;
	}
	
	if(neg&1){
		printf("%lld\n",sum-mini-mini);
	} else printf("%lld\n",sum);

	return 0;
}

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

bool is_int(double x)
{
    return floor(x) == x;
}

int main()
{
    int a, b, c;
    double d;
    cin >> a >> b;
    c = stoi(to_string(a) + to_string(b));
    d = sqrt(c);

    if (is_int(d))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int t,n,k;
    int x[100009];
    int u[100009];
    cin>>t;
    for(int y=0;y<t;y++){
        cin>>n>>k;
        for(int i=0;i<n;i++)
            cin>>x[i];
        for(int i=0;i<n-1;i++)
            u[i]=x[i+1]-x[i];
        sort(u,u+n-1);
        int sum=0;
        for(int i=0;i<n-k;i++)
            sum+=u[i];
        cout<<sum<<"\n";
        
    }
}

Measured memory_bytes: 1956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n  ,d , s=0;
    cin >> n>>d;
    d=d*2+1;
    while(n>=1)
    {
        s++;
        n=n-d;

    }
    cout << s ;

    return 0 ;
}

Measured memory_bytes: 256
fn polygon() -> Result<&'static str, &'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;
    let n: u32 = input.trim_right().parse()
        .map_err(|_| "parse error")?;

    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;
    let l: Vec<u32> = input.trim_right()
        .split_whitespace()
        .filter_map(|s| s.parse::<u32>().ok())
        .collect();

    let max = l.iter().max().ok_or("input empty")?;
    let sum = l.iter().sum();

    if max * 2 < sum {
        Ok("Yes")
    }
    else {
        Ok("No")
    }
}

fn main() {
    println!("{}", polygon().unwrap());
}

Measured memory_bytes: 4352