akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    return a%b?gcd(b,a%b):b;
}

int main(){
    ll n, x; cin >> n >> x;
    cout << 3 * (n-gcd(n,x));
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin,v.end()
using namespace std;
typedef pair<int,int>P;

int n,k,a[100],ans=1e17;

void dfs(int now,int pre,int kane,int num){
  if(now==n){
    if(num>=k)ans=min(ans,kane);
  }
  else{
    if(a[now]<pre){
      dfs(now+1,pre,kane,num);
      dfs(now+1,pre+1,kane+abs(a[now]-pre)+1,num+1);
    }
    else if(a[now]==pre){
      dfs(now+1,pre,kane,num);
      dfs(now+1,pre+1,kane+1,num+1);
    }
    else dfs(now+1,max(pre,a[now]),kane,num+1);
  }
}
main(){
  cin>>n>>k;
  r(i,n)cin>>a[i];
  dfs(0,0,0,0);
  cout<<ans<<endl;
}

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

/* 
 * g++ -std=c++17 main.cpp -o main
 */
int main() {
  ios::sync_with_stdio(false);
  int N,A;
  cin>>N>>A;
  vector<int> as(51);
  vector<vector<vector<ll>>> dp(51, vector<vector<ll>>(51, vector<ll>(2501)));
  dp[0][0][0] = 1;
  for(int i = 1; i<=N; i++) {
    int a;
    cin>>a;
    as[i] = a;
  }
  for(int i = 1; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      for(int k = 0; k <= A * N; k++) {
        dp[i][j][k] = dp[i-1][j][k];
      }
    }
    for(int j = 0; j < N; j++) {
      for(int k = 0; k <= A * N; k++) {
        dp[i][j+1][k+as[i]] += dp[i-1][j][k];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N; j++) {
    ans += dp[N][j][j * A];
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 52224
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

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

    vector<P> A[N];
    for (int i = 0; i < N; i++)
    {
        int a = 0;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x, y;
            cin >> x >> y;
            x--;
            A[i].push_back(P(x, y));
        }
    }

    // bit全探索
    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        int honest = 0;
        int ok = true;
        for (int i = 0; i < N; i++)
        {
            if (bit & (1 << i))
            {
                // cout << "bitは" << bit << " iは" << i << " シフトは" << (1 << i) << endl;
                for (P o : A[i])
                {
                    int x, y;
                    tie(x, y) = o;
                    // cout << "x, y =" << x << " " << y << "シフト=" << (bit & (1 << x)) << endl;
                    // if ((bit & (1 << x)) != y)
                    if (((bit >> x) & 1) != y)
                    {
                        ok = false;
                        break;
                    }
                }
                if (!ok)
                    break;
                // cout << "find honest: bit=" << bit << "i=" << i << endl;
                honest++;
            }
        }
        if (ok)
        {
            // cout << "all ok bit=" << bit << " honest = " << honest << endl;
            ans = max(ans, honest);
        }
    }

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

Measured memory_bytes: 256
s = list(input())
n = len(s)

if n!=26:
  for i in [chr(ord('a') + i) for i in range(26)]:
    if not i in s:
      tmp=i
      break
  s.append(tmp)
  print("".join(s))

else:
  if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)

  else:
    for j in range(n)[::-1]:
      for k in range(1,122-ord(s[j])+1):
        tmp = chr(ord(s[j])+k)
        if tmp not in s[:j]:
          s[j]=tmp
          del s[j+1:]
          print("".join(s))
          exit()

Measured memory_bytes: 9076
use std::str::FromStr;
use std::string::String;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let a : String = get_one();
    let n : usize = get_one();
    let mut rvsd = false;
    let mut front = Vec::new();
    let mut back = Vec::new();
    for i in 0..n {
        let q : String = get_one();
        let t = q.chars().nth(0).unwrap();

        if t == '1' {
            rvsd = !rvsd;
        }
        else {
            let f = q.chars().nth(2).unwrap();
            let c = q.chars().nth(4).unwrap();
            if (f == '1' && !rvsd) || (f == '2' && rvsd) {
                front.push(c);
            }
            else {
                back.push(c);
            }
        }
    }
    let mut ans = [front.into_iter().rev().collect::<String>(), a, back.into_iter().collect::<String>()].connect("");
    if rvsd {
        ans = ans.chars().rev().collect::<String>();
    }
    println!("{}", ans);
}


Measured memory_bytes: 6652
#include <bits/stdc++.h>
#define ll long long
#define pi 3.1415926535897932384626433832795
#define fin(a,n)  for(ll i=0;i<n;i++) cin>>a[i];
#define fout(a,n)  for(ll i=0;i<n;i++) cout<<a[i]<<" ";

using namespace std;

int main() 
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); cout.tie(NULL);
	int t,ac=0,tle=0,wa=0,re=0;
	cin>>t;
	while(t--) {
		string s;
		cin>>s;
		if(s == "AC") { ac++;}
		else if(s == "WA") { wa++;}
		else if(s == "TLE") { tle++;}
		else if(s == "RE") { re++;}
	}
	cout<<"AC x "<<ac<<'\n';
	cout<<"WA x "<<wa<<'\n';
	cout<<"TLE x "<<tle<<'\n';
	cout<<"RE x "<<re<<'\n';
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Univ = vector<vector<vector<int>>>;

int	main()
{
	Univ	univ(4, vector<vector<int>>(3, vector<int>(10, 0)));
	int	n;
	cin >> n;
	int	b, f, r, v;
	for (int i = 0; i < n; ++i) {
		cin >> b >> f >> r >> v;
		--b; --f; --r;
		univ.at(b).at(f).at(r) += v;
	}
	for (b = 0; b < 4; ++b) {
		if (b > 0)
			cout << string(20, '#') << "\n";
		for (f = 0; f < 3; ++f) {
			for (r = 0; r < 10; ++r)
				cout << " " << univ.at(b).at(f).at(r);
			cout << "\n";
		}
	}
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int H,W;

  cin >> H >> W ;

  vector<string> C(H);

  for(int i=0;i<H;i++) cin >> C.at(i);

  for(int i=0;i<H;i++){
    cout << C.at(i) << endl;
    cout << C.at(i) << endl;
  }

  return 0;
}

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

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

  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  int ans = 0;
  vector<int> yen(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (s.at(i) == s.at(j)) {
        yen.at(i)++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (s.at(i) == t.at(j)) {
        yen.at(i)--;
      }
    }
    if (yen.at(i) > ans) {
      ans = yen.at(i);
    }
  }
  cout << ans << endl;
}

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

res = 0
if N == 1 or M == 1:
	if N == 1 and M == 1:
		res = 1
	elif N == 1:	# if M != 1
		res = M - 2
	elif M == 1: # if N != 1
		res = N - 2
else:	# if N != 1 and M != 1
	res = (N - 2) * (M - 2)

print(res)

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

int main() {
	string s,t;
	cin>>s>>t;
	int n=s.length();
	int m=t.length();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)
	{
	    for(int j=0;j<=m;j++)
	    {
	        if(i==0 || j==0)
	        dp[i][j]=0;
	        else 
	        {
	            if(s[i-1]==t[j-1])
	            dp[i][j]=1+dp[i-1][j-1];
	            else 
	            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	        }
	    }
	}
	vector<char> ans;
	int i=n;int j=m;
	        while(i>0 && j>0){
	        if(s[i-1]==t[j-1])
	        {
	            ans.push_back(s[i-1]);
	            i--;
	            j--;
	        }
	        else
	        {
	            if(dp[i-1][j]>dp[i][j-1])
	            i--;
	            else 
	            j--;
	        }
	        }
	        
	        
	       for(int i=ans.size()-1;i>=0;i--)
	       cout<<ans[i];
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 38764
#include<iostream>
#include<map>
#include<queue>
using namespace std;
//構造体のpriority_queue
struct node{
  int v,cost;
  node(int vv,int c): v(vv),cost(c){}
  bool operator >(const node &e) const{
    return cost > e.cost;
  }
};

int main()
{
  int n;
  for(;cin>>n;)
    {
      string code[n];
      map<string, int> link;
      cin.ignore(); // 次の改行文字まで(改行文字を含めて)最大1文字読み捨てる。
      // 1文字だと駄目な場合は cin.ignore(/*読み飛ばしたい最大文字数*/); とすれば良い。
      int move[n];
      for(int i=0;i<n;i++)
	{
	  getline(cin, code[i]);
	  if(string(code[i],0, 4)!="goto")
	    link.insert( map<string,int>::value_type(string(code[i],0,code[i].size()-1),i));
	}
      /*
      map<string, int>::iterator it = link.begin();

      while( it != link.end() )
	{
	  cout << (*it).first << ":" << (*it).second << endl;
	  ++it;
	}
      */
      for(int i=0;i<n;i++)
	{
	  if(string(code[i],0, 4)=="goto")
	    {
	      // cout<<string(code[i],5, code[i].size()-6)<<endl;
	      move[i]=link[string(code[i],5, code[i].size()-6)];
	    }
	  else
	    move[i]=i+1;
	  ///	  cout<<"move"<<i<<":"<<move[i]<<endl;
	}
      int min[n];
      for(int i=0;i<n;i++)
	{
	  min[i]=-1;
	}
      priority_queue<node, vector<node>, greater<node> > P;
      P.push(node(0,0));
      int ans=-1;
      for(;ans==-1;)
	{
	  node tmp =  P.top();  // 次に取り出される要素を出力
	  P.pop();
	  //cout<<tmp.v<<":"<<tmp.cost<<endl;
	  if(tmp.v==n)
	    {
	      ans=tmp.cost;
	      break;
	    }
	  if(min[tmp.v]!=-1)
	    continue;
	  else
	    min[tmp.v]=tmp.cost;
	  if(move[tmp.v]==tmp.v+1)
	    P.push(node(tmp.v+1,tmp.cost));
	  else
	    {
	      P.push(node(move[tmp.v],tmp.cost));
	      P.push(node(tmp.v+1,tmp.cost+1));
	    }
	}
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

const int N = 3007;
const double eps = 1e-9;

double ans = -1;

int A, B, C, D, E, F, a, b;

bitset<N> vis[N];

void dfs(int a, int b)
{
	vis[a][b] = 1;

	if(a+b+100*A<=F && !vis[a+100*A][b])
		dfs(a+100*A, b);

	if(a+b+100*B<=F && !vis[a+100*B][b])
		dfs(a+100*B, b);

	if(a+b+C<=F && !vis[a][b+C])
		dfs(a, b+C);

	if(a+b+D<=F && !vis[a][b+D])
		dfs(a, b+D);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> A >> B >> C >> D >> E >> F;

	dfs(0, 0);

	for(int i = 0; i <= F; ++i)
	{
		for(int j = 0; j <= F; ++j)
		{
			if(vis[i][j] && (i || j))
			{
				if((double)E/100*i+eps>j && (double)100*j/(i+j)>ans)
				{
					ans = (double)100*j/(i+j);
					a = i;
					b = j;
				}
			}
		}
	}

	cout << a+b << " " << b;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ge = n % 10;
	int shi = n / 10 % 10;
	int bai = n / 100 % 10;
	int qian = n / 1000;
	if(shi == bai)
	{
		if (ge == shi || qian == bai)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
	}
	else
	{
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    cakes = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    res = - 10 ** 15

    for a in [1, -1]:
        for b in [1, -1]:
            for c in [1, -1]:
                gains = [a*x + b*y + c*z for x, y, z in cakes]
                gains.sort(reverse=True)
                res = max(res, sum(gains[:M]))
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D,N;
    cin >> D >> N;
    if(D == 0) {
        if(N == 100) {
            cout << 101 << endl;
        }
        else {
            cout << N << endl;
        }
    }
    if(D == 1) {
        if(N == 100) {
            cout << 10100 << endl;
        }
        else {
            cout << 100*N << endl;
        }
    }
    if(D == 2) {
        if(N == 100) {
            cout << 1010000 << endl;
        }
        else {
            cout << 10000*N << endl;
        }
    }
}


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

  #define ll long long
  #define int long long
  #define f(i,l,n) for(ll i=l;i<n;i++)
  #define E "\n"
  #define bp __builtin_popcount
  const int N = 2e3 + 5;
string s,t;
  
  int32_t main()
  {

  

   
   cin >> s >> t;

   int n=s.size(),m=t.size();
   int ans=n;
   
   for(ll i=0;i<n-m+1;i++)
    {
        ll sum = 0;
        for(ll j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])   sum++;
        }
        ans = min(ans,sum);
    }
    cout<<ans;
    return 0;
  }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    if (s.back() == 's')
    {
        cout << s << "es" << endl;
    }
    else
    {
        cout << s << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

  vector<ll> acc;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    if (i == 0)
      acc.emplace_back(tmp);
    else
      acc.emplace_back(tmp + acc[i - 1]);
  }

  ll ans = acc[acc.size() - 1];
  for (int i = 1; i <= N - 3; i++) {
    ll sum0 = acc[i];
    auto pos0 = upper_bound(acc.begin(), acc.begin() + i - 1, sum0 / 2);
    if( pos0 != acc.begin() && abs(sum0 - 2*(*pos0)) >  abs(sum0 - 2*(*(pos0-1)) ))
      pos0--;

    ll sum1 = acc[acc.size() - 1] - acc[i];
    auto pos1 = upper_bound(acc.begin() + i + 1, acc.end(), sum1 / 2 + acc[i]);
    if( pos1 != acc.begin() + i + 1 && abs(sum1 - 2*((*pos1)-acc[i])) >  abs(sum1 - 2*((*(pos1-1)-acc[i]))) )
      pos1--;

    ll v0 = *pos0;
    ll v1 = acc[i] - *pos0;
    ll v2 = *pos1 - acc[i];
    ll v3 = acc[acc.size() - 1] - *pos1;
    vector<ll> cands = {v0, v1, v2, v3};
    ll max = *max_element(cands.begin(), cands.end());
    ll min = *min_element(cands.begin(), cands.end());
    if (max - min < ans) ans = max - min;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2420
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll rec(ll i, ll count) {
    if(i%2==1) {
        return count;
    }

    return rec((i / 2), count+1);
}

int main() {
    int n;
    ll ans = pow(2, 32);
    cin >> n;
    rep(i, n) {
        ll a;
        cin >> a;
        if (a%2==1) {
            ans = 0;
            break;
        }
        ans = min(ans, rec(a, 0));
    }
    print(ans);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    long long int count[N];
    long long int com[N], difcom[N];
    REP(i,N){
        count[i] = 0;
        com[i] = 0;
        difcom[i] = 0;
    }
    int A[N];
    REP(i,N){
        cin >> A[i];
        count[A[i]-1] += 1;
    }
    REP(i,N){
        if(count[i]>=2){
            com[i] = count[i]*(count[i]-1)/2;
        }
        if(count[i]-1>=2){
            difcom[i] = (count[i]-1)*(count[i]-2)/2;
        }
    }
    long long int sum = 0;
    REP(i,N) sum += com[i];
    REP(i,N){
        cout << (sum-com[A[i]-1]+difcom[A[i]-1]) << endl;
    }
}


Measured memory_bytes: 8704
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)):
    mini = i
    for j in xrange(i, len(A)):
        if A[j] < A[mini]:
            mini = j
    if A[i]!=A[mini]:
	    cnt += 1
	    A[i], A[mini] = A[mini], A[i]
for x in A:
	print x,
print
print cnt

Measured memory_bytes: 4224
import sys
N,M = map(int, input().split())
abc = [[] for _ in range(N)]
for i in range(M):
    a,b,c = map(int, input().split())
    abc[a-1].append((b-1,c))
    
S = [-float("inf")]*N
S[0] = 0
T = [0]
m = 0
n = 0
j = False
while T:
    t = T.pop(0)
    m += 1
    for tb,tc in abc[t]:
        if S[tb] < S[t]+tc:
            S[tb] = S[t]+tc
            T.append(tb)
    if m > M+1:
        d = abc[tb]
        if N-1 in list(d[i][0] for i in range(len(d))):
            j = True
        n += 1
    if n > M:
        if j:
            print("inf")
            sys.exit()
        else:
            break

print(S[-1])

Measured memory_bytes: 9352
#include<stdio.h>
#include<algorithm>
using namespace std;
long long int n,x[200001],x1[200001],t1,t2,b[200001],i;
int main(void)
{
	
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&x[i]);
		x1[i]=x[i];
	}
	sort(x,x+n);
	t1=x[n/2];
	t2=x[n/2-1];
	// printf("%lld %lld\n",t1,t2);
	for(i=0;i<n;i++){
		if(x1[i]>t2) b[i]=t2;
		else b[i]=t1;
	}
	for(i=0;i<n;i++) printf("%lld\n",b[i]);
	return 0;
}

Measured memory_bytes: 6784
S = gets.chomp

if S[0] == S[1]
    if S[2] == S[3] && S[0] != S[2]
        puts "Yes"
    else
        puts "No"
    end
elsif S[0] == S[2]
    if S[1] == S[3] && S[0] != S[1]
        puts "Yes"
    else
        puts "No"
    end
elsif S[0] == S[3]
    if S[1] == S[2] && S[0] != S[1]
        puts "Yes"
    else
        puts "No"
    end
else
    puts "No"
end

Measured memory_bytes: 1788
'use strict';

function Main(INPUT) {
    const input = INPUT.split(" ").map(n => Number(n));
    const X = input[0];
    const Y = input[1];
    let ans = -1;
    if (X % Y != 0) {
        ans = X;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=12;
char s[N];
int n;
int main()
{
	ll n,ans=0;
	cin>>n;
	ll d=n/500;
	ans=d*1000;

	n=n%500;
	d=n/5;
	ans+=d*5;
	cout<<ans<<endl;
}


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

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

	int	n;
	cin >> n;
	vector<int>	S(n);
	rep(i, n)
		cin >> S.at(i);

	int m;
	cin >> m;

	int	count;
	count = 0;
	rep(i, m)
	{
		int	a;
		cin >> a;
		rep(j, n)
		{
			if (S.at(j) == a)
			{
				count++;
				break;
			}
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 3228
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  path[a-1].append(b-1)
  path[b-1].append(a-1)
good = 0
for i in range(n):
  for j in path[i]:
    if h[i] <= h[j]:
      break
  else:
    good += 1
print(good)

Measured memory_bytes: 29476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mod 1000000007
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi>
#define pb push_back
#define vs vector<string>
#define all(x) x.begin(),x.end()
#define mii map<int,int>
const int inf=0x3f3f3f3f3f3f3f3f;
void print(vi &v){
    for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
    cout<<endl;
}
int power(int a,int b){
    int res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t = 1;
    while(t--){
        int n;
        cin>>n;
        int x = n/500,y = n%500;
        cout<<x*1000+5*(y/5)<<endl;
    }
    return 0;
}

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

using ll = long long;
ll n;
const ll MAX = 1000000;

// table[x]:=xの最小の素因数
std::vector<ll> table(MAX + 1, 1);

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

void initTable(){
    table[0] = 0;
    table[1] = 0;
    // init
    for(int i = 2; i <= MAX; i++) table[i] = i;

    for(ll i = 2; i*i <= MAX; i++){
        if(table[i] == i){
            for(ll j = i*i; j <= MAX; j += i){
                table[j] = i;
            }
        }
    }
}

int main(){
    initTable();
    std::vector<ll> cnt(MAX + 1, 0);
    ll maxCnt = 0;

    std::cin >> n;
    std::vector<ll> a(n);
    std::cin >> a[0];
    ll g = a[0];
    while(table[a[0]] > 1){
        ll d = table[a[0]];
        while(a[0] % d == 0){
            a[0] /= d;
        }
        cnt[d]++;
    }

    for(int i = 1; i < n; i++){
        std::cin >> a[i];
        g = gcd(g, a[i]);
        while(table[a[i]] > 1){
            ll d = table[a[i]];
            while(a[i] % d == 0){
                a[i] /= d;
            }
            cnt[d]++;
            maxCnt = std::max(maxCnt, cnt[d]);
        }
    }


    if(maxCnt >= 2 && g > 1){
        std::cout << "not coprime" << std::endl;
    }else if(maxCnt >= 2 && g == 1){
        std::cout << "setwise coprime" << std::endl;
    }else{
        std::cout << "pairwise coprime" << std::endl;
    }

    return 0;
}


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

vector<string> queries({ "dream", "dreamer", "erase", "eraser"});
string s;

bool is_accept(int i){
  if(i == s.size()) return true;

  bool is_succeed = false;
  for(string q: queries){
    if(s.substr(i, q.size()) == q){
      is_succeed |= is_accept(i+q.size());
    }
  }
  return is_succeed;
}

int main() {

  cin >> s;
  bool is_succeed = is_accept(0);
  if(is_succeed) cout << "YES" << endl;
  else   cout << "NO" << endl;


  return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int s;
    cin>>s;
    
    bool check[100001]={false};
    check[s]=true;
    
    int n,pre=s;
    int i=2;
    while(1){
        if(pre%2==0){
            n=pre/2;
        }else{
            n=3*pre+1;
        }
        
        if(check[n])break;
        
        check[n]=true;
        pre=n;
        i++;
    }
    
    cout<<i<<endl;
    
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

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

    std::vector<int> R(n);
    for (int i = 0; i < n; i ++) {
        scanf("%d", &R[i]);
    }

    int cum_min = R[0];
    int max_profit = R[1] - R[0];
    for (int i = 1; i < n; i ++) {
        max_profit = std::max(R[i] - cum_min, max_profit);
        cum_min = std::min(R[i], cum_min);
    }
    std::cout << max_profit << std::endl;
}



Measured memory_bytes: 3600
#include <stdio.h>

int main(void) {
    double b;
    long int ans, a;
    scanf("%ld %lf", &a, &b);
    int c = b * 100 + 0.001;
    ans = (long)(a * c) / 100;
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 1720
#include <stdio.h>
#include <stdlib.h>

int sum = 0;

void merge(int A[], int left, int right){
    int mid = (left+right)/2;
    int len1 = mid - left + 1;
    int len2 = right - mid;

    int A1[len1], A2[len2];
    for(int i=0; i<len1; i++)
        A1[i] = A[left+i];
    for(int i=0; i<len2; i++)
        A2[i] = A[mid+1+i];
    
    int counter1 = 0, counter2 = 0, counter = left;
    while(counter1 != len1 && counter2 != len2){
        if(A1[counter1] <= A2[counter2]){
            A[counter] = A1[counter1];
            counter++;
            counter1++;
        }else{
            A[counter] = A2[counter2];
            counter++;
            counter2++;
        }
        sum++;
    }

    while(counter1 != len1){
        A[counter] = A1[counter1];
        counter++;
        counter1++;
        sum++;
    }

    while(counter2 != len2){
        A[counter] = A2[counter2];
        counter++;
        counter2++;
        sum++;
    }
}

void mergeSort(int A[], int left, int right){
    if(left != right){
        int mid = (left+right)/2;

        mergeSort(A,left,mid);
        mergeSort(A,mid+1,right);
        merge(A,left,right);
    }
}

int main(){    
    int n;
    scanf("%d",&n);
    int A[n];
    for(int i=0; i<n; i++)
        scanf("%d",&A[i]);
    mergeSort(A,0,n-1);
    for(int i=0; i<n-1; i++)
        printf("%d ",A[i]);
    printf("%d\n",A[n-1]);
    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 5580
n,k = map(int,input().split())
a = list(map(int,input().split()))
x = [1]
y = [False]*n
i = 0
s = 0
t = 0
xa = x.append
while True:
  if y[i] == True:
    for j in range(len(x)):
      if i == x[j]-1:
        s = j
        t = len(x)-j-1
        break
    break
  else:
    y[i] = True
    xa(a[i])
    i = a[i]-1
if k < s:
  print(x[k])
  exit()
x = x[s:-1]
print(x[(k-s)%t])

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

int main() {
  int a,b,c,x,y;
  cin >>a>>b>>c>>x>>y;
  int okane=a*x+b*y;
  int hikaku=c*max(2*x,2*y);
  /*if(hikaku<okane){
    cout<<hikaku<<endl;
    return 0;
  }*/
  for(int i=1;i<=max(x*2,y*2);i++){
    if(i%2==1){
      okane=min(okane,c*i+a*(max(0,x-i/2+1))+b*(max(y-i/2+1,0)));
    }else{
      okane=min(okane,c*i+a*(max(x-i/2,0))+b*(max(0,y-i/2)));
    }
  }
  cout<<okane<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int vec[100002];
int psum[100002];

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

	for (int i = 1; i <= n; i++)
		scanf("%d", &vec[i]);
	vec[n + 1] = vec[0];
	
	for (int i = 1; i <= n + 1; i++)
		psum[i] = psum[i - 1] + abs(vec[i] - vec[i - 1]);

	// 부분합으로, -> 방향 해준다음에. 그 앞에서 하나 끊고, 

	int sum;
	for (int i = 1; i <= n; i++) {
		sum = psum[i - 1];
		sum += abs(vec[i - 1] - vec[i + 1]);
		sum += psum[n + 1] - psum[i + 1];

		printf("%d\n", sum);
	}
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main(void)
{
	ll n,c=1;
	string s;
	cin>>n;
	cin>>s;
	for(ll i=0;i<n-1;i++)
	{
		if(s[i]!=s[i+1])
		{
			c++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN];
int main() {
	scanf("%s", s + 1), s[4] = 0;
	printf("%s\n", s + 1);
	return 0;
}


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

int main() {
  long long n;
  cin >> n;
  string ans;
  //n--;
  while (n) {
    ans += 'a' + ((n + 25) % 26);
    n--;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  //for (int i = 0; i + 1 < ans.length(); ++i) ans[i]--;
  cout << ans << endl;
  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
    vec p(N);
    rep(i, N) cin >> p[i];
    int res1=0, res2=0;
    rep(i, N){
        if(p[i] == i+1) res1++;
    }
    rep(i, N-1){
        if(p[i] == i+1 && p[i+1] == i+2){
            res2++;
            i++;
        }
    }

    cout << res1 - res2 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void recur(int s,int n,int &num,vector <int> &v,vector <int> &out){
	if(s == n){
		out.push_back(num);
		return;
	}
	else{
		for(int i : v){
			num = num * 10 + i;
			recur(s + 1,n,num,v,out);
			num = (num - i) / 10;
		}
	}
	return;
}

void solve(){
	int n;
	cin >> n;
	int l = log10(n) + 1;
	vector <int> out;
	vector <int> v = {3,5,7};
	for(int i = 1;i <= l;++i){
		int num = 0;
		recur(0,i,num,v,out);
	}
	vector <int> out2;
	int k = out.size();
	for(int i = 0;i < k;++i){
		int num = out[i];
		bool flag3 = 0,flag5 = 0,flag7 = 0;
		while(num > 0){
			if(num % 10 == 3) flag3 = 1;
			else if(num % 10 == 5) flag5 = 1;
			else if(num % 10 == 7) flag7 = 1; 
			num = num / 10;
		}
		if(flag3 and flag5 and flag7) out2.push_back(out[i]);
	}
	auto ans = upper_bound(out2.begin(),out2.end(),n);
	cout << ans - out2.begin() << newl;
	
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

int main() {
	string S; cin >> S;
	if(S[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	for(int i = 2 ; i < S.size() - 1 ; i++){
		if(S[i] == 'C'){
			S[i] = 'g';
			for(int j = 1 ; j <= S.size() ; j++){
				if(isupper(S[j])){
					cout << "WA" << endl;
					return 0;
				}
			}
			cout << "AC" << endl;
			return 0;
		}
	}
	cout << "WA" << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use procon::*;
use std::cmp::{max, min};
use std::collections::*;
use std::ops::*;
use std::*;

pub fn main() {
    let N = read_line().parse::<usize>().unwrap();
    let A = read_words::<i64>();

    let mut l = 0;
    let mut r = 0;
    let mut k = 0;
    let mut bs = 0_i64;

    // [l, l + 1) は数えない

    while l < N {
        // [l, r) はdisjoint
        // [l-i, _) はすべて列挙済み

        while r < N && (bs & A[r]) == 0 {
            bs ^= A[r];
            r += 1;
        }

        // [l, r) は disjoint
        // [l, r - i) はすべて disjoint
        // lが異なる区間はほかのタイミングで数える
        k += r - l;

        // drop leftest
        bs ^= A[l];
        l += 1;
    }

    println!("{}", k);
    return;
}

pub mod procon {
    use std;
    use std::collections::*;
    use std::io;
    use std::mem;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec(len: usize) -> Vec<String> {
        let mut vec = Vec::new();
        while vec.len() < len {
            let line = read_line();
            for word in line.split_whitespace() {
                vec.push(word.to_owned());
            }
        }
        assert!(vec.len() == len);
        vec
    }
}


Measured memory_bytes: 10492
N = int(input())
if 100 <= N <= 111:
    print(111)
elif 112<= N <= 222:
    print(222)
elif 223 <= N <= 333:
    print(333)
elif 334 <= N <= 444:
    print(444)
elif 445 <= N <= 555:
    print(555)
elif 556 <= N <= 666:
    print(666)
elif 667 <= N <= 777:
    print(777)
elif 778 <= N <= 888:
    print(888)
elif 889 <= N <= 999:
    print(999)


Measured memory_bytes: 3060
N = input()

for i in range(2 ** 3):

    ops = format(i,"b")
    ops = ops.zfill(3)

    op_lis = []

    for j in ops:

        if j == "0":
            op_lis.append(1)
        else:
            op_lis.append(-1)

    if int(N[0]) + op_lis[0] * int(N[1]) +op_lis[1] * int(N[2]) + op_lis[2] * int(N[3]) == 7:

        ans = N[0]

        for k in range(len(op_lis)):
            if op_lis[k] == 1:
                ans += "+"
            else:
                ans += "-"

            ans += N[k+1]

        ans += "=7"

        print (ans)
        break


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+10;
int n,A[N],suma[N],sumb[N],sumc[N],L[N],R[N];
int ss[N],sumL[N],Ans=1e18;
void Get(int *sa,int *sb,int *val)
{
	int p=0;
	for(int i=1;i<=n;i++)
	{
		ss[i]=sa[i]-sb[i];
		if(ss[i]<ss[p]) p=i;
		val[i]=sb[i]+ss[p];
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>A[i];
	//Get L
	for(int i=1;i<=n;i++)
	{
		suma[i]=suma[i-1]+A[i];
		sumb[i]=sumb[i-1]+(A[i]==0?2:(A[i]&1));
	}
	Get(suma,sumb,L);
	
	//Get R
	reverse(A+1,A+n+1);	
	for(int i=1;i<=n;i++)
	{
		suma[i]=suma[i-1]+A[i];
		sumb[i]=sumb[i-1]+(A[i]==0?2:(A[i]&1));
	}
	Get(suma,sumb,R);
	reverse(R+1,R+n+1);
	reverse(A+1,A+n+1);
	
	//Get Ans
	for(int i=1;i<=n;i++)
		sumc[i]=sumc[i-1]+1-(A[i]&1);
	Get(L,sumc,sumL);
	for(int i=0;i<=n;i++)
		Ans=min(Ans,sumL[i]+R[i+1]);
	cout<<Ans<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans=999;
  for (int i=0;i<s.size()-2;i++){
    int t=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
    ans=min(ans,abs(t-753));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long> a(3*N);
  for(int i=0;i<3*N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  long long sum=0;
  for(int i=N;i<3*N;i++){
    if((i-N)%2==0)sum+=a[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MAXX=1010;
const int MAXY=1010;
bool map2d[MAXX][MAXY];
int depth[MAXX][MAXY];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};

void bfs(ll sx, ll sy) {
  deque<pair<ll,ll>> dq; //探索予定地 必要ならpairにしてどこから来たのか記録
  rep(i,MAXX) rep(j,MAXY) depth[i][j]=-1;
  dq.emplace_back(sx,sy); // 始点を探索予定地に
  depth[sx][sy]=0; // 始点の深さを0に
  while(!dq.empty()) {
    ll vx = dq.front().first;// vは行く元
    ll vy = dq.front().second;// vは行く元
    dq.pop_front();
    rep(i,4){
      ll x=vx+dx[i]; ll y=vy+dy[i];
      if(x<0 or x>=MAXX or y<0 or y>=MAXY) continue;
      if(map2d[x][y]==0) continue;
      if(depth[x][y]!=-1) continue;
      depth[x][y]=depth[vx][vy]+1;
      dq.emplace_back(x,y);
    }
  }
}

void Main(){

  int H,W;
  cin>>H>>W;

  int white=0;

  rep(i,H){
    rep(j,W){
      char c; cin>>c;
      map2d[i][j]= c=='.';
      white += c=='.';
    }
  }

  bfs(0,0);

  if(depth[H-1][W-1]==-1){
    cout<< -1<<"\n";
    return;
  }

  cout<< white-1-depth[H-1][W-1] <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 4352
# https://atcoder.jp/contests/dp/tasks/dp_l

'''
dp[i,j] ... dequeに[i,j]が残っているときに行動するプレイヤーのスコアの最大
dp[i,j] = max(a[i-1]-dp[i-1,j], a[j+1]-dp[i,j+1]) #これじゃgreedyと同じじゃん

dp[i,j] ... dequeに[i,j)が残っているときにその状態からスタートするプレイヤーが達成できるスコアの最大 (区間を伸ばしていく感じ)

初期値 dp[i,i]==0

dp[i,j]=max(a[i]-dp[i+1,j], a[j-1]-dp[i,j-1])
'''
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)


def a_int(): return int(readline())


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

N = a_int()
A = ints()

dp = full((N + 1, N + 1), -10**11)
dp[np.arange(N + 1), np.arange(N + 1)] = 0

from numba import njit


@njit('(i8,i8[:],i8[:,:])', cache=True)
def solve(N, A, dp):
    for i in range(N - 1, -1, -1):
        for j in range(i + 1, N + 1):
            dp[i, j] = max(A[i] - dp[i + 1, j], A[j - 1] - dp[i, j - 1])
    print(dp[0, N])
    # print(*dp, sep='\n')


solve(N, A, dp)


Measured memory_bytes: 181040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		int sum = 0;
		for(int i = 0; i < 2; i++) {
			sum += Math.max(A, B);
			if (Math.max(A, B) == A) {
				A--;
			} else {
				B--;
			}
		}

		System.out.println(sum);
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n, d, sum = 0, count = 0;
	cin >> n >> d;
	int x[10][20];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	for (int point = 0; point < n - 1; point++) {
		for (int i = point + 1; i < n; i++) {
			for (int j = 0; j < d; j++) {
				sum += (x[i][j] - x[point][j]) * (x[i][j] - x[point][j]);
			}
			if ((double)sqrt(sum) == (int)sqrt(sum)) count += 1;
			sum = 0;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<50);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
	ll n;cin>>n;ll l;cin>>l;
  vector<string>v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  rep(i,n)cout<<v[i];
  cout<<endl;
  
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	solve();
}


Measured memory_bytes: 256
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for _ in[0]*N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Measured memory_bytes: 12480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+7;
int a[maxn];
int main()
{
    int n, sum=0;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
        sum+=a[i]*a[j];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 10000000000　+　7    //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
/*整数をqsortする為だけのもの*/
long long compare(const long long *a, const long long *b)
{
    if (*a < *b)
        return -1;
    else if (*a > *b)
        return 1;
    return 0;
}
/*intで収まる範囲であってくれ*/
ll nCr(int n, int r)
{
    ll val = 1;
    int i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(int n, int r)
{
    ll val = 1;
    int i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}

void chmin(ll &a, ll b)
{
    if (a > b)
        a = b;
}
void chmax(ll &a, ll b)
{
    if (a < b)
        a = b;
}

/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/


int main()
{
    string S;
    int N;
    cin >> N;
    cin >> S;
    int count = 0;
    for(int i=0;i<N-2;i++){
        if(S[i] == 'A'&&S[i+1] == 'B'&&S[i+2]=='C'){
            count++;
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 256
x,y = map(int, input().split())
L1 = [1,3,5,7,8,10,12]
L2 = [4,6,9,11]

if x == 2 or y == 2:
 print("No")

elif x in L1 and y in L1:
 print("Yes")

elif x in L2 and y in L2:
 print("Yes")

else:
 print("No")

Measured memory_bytes: 3316