akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int N;
  cin >> N;
  vector<pair<pair<string,int>,int>> rest(N);
  rep(i, N) {
    string a;
    int b;
    cin >> a >> b;
    rest[i] = make_pair(make_pair(a,-b),i);
  }
  sort(rest.begin(), rest.end());
  rep(i, N) {
    cout << rest[i].second + 1 << endl;
  }
}

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

#define f first
#define s second
#define p_b push_back
#define ull unsigned long long
#define ll  long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(nullptr);cout.tie(nullptr);ios_base::sync_with_stdio(false);
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int) x.size()
#define endl '\n'
#define len(x) x.length()

using namespace std;

signed main()
{
    fast_io;
    vector<ll>a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    if((a[0]==a[1] && a[1]!=a[2])|| (a[1]==a[2] && a[1]!=a[0])){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n,k;
int a[maxn];
long double _=1.00;

int check(int x)
{
    int ret=0;
    for (int i=1;i<=n;i++)
    {
        if (a[i]==0) ret+=(x>=0 ? n : 0);
        else if (a[i]>0) ret+=upper_bound(a+1,a+n+1,floor(x*_/a[i]))-a-1;
        else if (a[i]<0) ret+=n-(lower_bound(a+1,a+n+1,ceil(x*_/a[i]))-a-1);
    }
    for (int i=1;i<=n;i++)
        if (a[i]*a[i]<=x) ret--;
    return ret/2;
}

int32_t main()
{
    IOS
    cin>>n>>k;
    for (int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    int L=-1e18-7,R=1e18+7;
    while (R-L>1)
    {
        int M=(L+R)/2;
        if (check(M)<k) L=M;
        else R=M;
    }
    cout<<R<<endl;
}



Measured memory_bytes: 1792
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
function lower_bound(d,e,a,b){for(var c;1<b-a;)d[c=a+b>>1]<e?a=c:b=c;return d[a]<e?b:a};

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var s = next(1);
  var ans = 0;
  var r = [], g = [], b = [];
  var rs = new Set(),gs = new Set(),bs = new Set();
  for(var i = 0; i < n; i++){
    if(s[i] === "R")r.push(i),rs.add(i);
    else if(s[i] === "G")g.push(i),gs.add(i);
    else b.push(i),bs.add(i);
  }
  for(i = 0; i < r.length; i++){
    var m = r[i];
    for(var j = 0, q = g[0]; j < g.length && q < m; j++, q = g[j]){
      var z = b.length-lower_bound(b,m,0,b.length);
      if(bs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = b[0]; j < b.length && q < m; j++, q = b[j]){
      var z = g.length-lower_bound(g,m,0,g.length);
      if(gs.has(m+m-q))z--;
      ans += z;
    }
  }
  for(i = 0; i < g.length; i++){
    var m = g[i];
    for(var j = 0, q = r[0]; j < r.length && q < m; j++, q = r[j]){
      var z = b.length-lower_bound(b,m,0,b.length);
      if(bs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = b[0]; j < b.length && q < m; j++, q = b[j]){
      var z = r.length-lower_bound(r,m,0,r.length);
      if(rs.has(m+m-q))z--;
      ans += z;
    }
  }
  for(i = 0; i < b.length; i++){
    var m = b[i];
    for(var j = 0, q = g[0]; j < g.length && q < m; j++, q = g[j]){
      var z = r.length-lower_bound(r,m,0,r.length);
      if(rs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = r[0]; j < r.length && q < m; j++, q = r[j]){
      var z = g.length-lower_bound(g,m,0,g.length);
      if(gs.has(m+m-q))z--;
      ans += z;
    }
  }
  return ans;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

bitset<100005> sieve;

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    sieve.flip();
    sieve[1] = 0;
    for (int i = 2; i < 100005; i++) for (ll j = 1ll * i * i; j < 100005; j += i) sieve[j] = 0;

    set<int, greater<int>> v;
    for (int i = 2; i < 100005; i++) if (sieve[i]) v.insert(i);

    for (;;) {
        int m, a, b; cin >> m >> a >> b;
        if (!m) break;
        int bi = 0, bj = 0;
        for (int i = 1; i <= m; i++) if (sieve[i]) {
            auto it = v.lower_bound(min(m / i, i * b / a));
            if (it == v.end()) continue;
            int j = *it;
            // cout << i << " " << j << endl;
            if (i * j <= m && a * j <= i * b && i <= j && i * j > bi * bj) {
                bi = i, bj = j;
            }
        }
        cout << bi << " " << bj << endl;
    }
}


Measured memory_bytes: 3624
#include<cstdio>
using namespace std;
int main(){
    int a[5],k;
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    if(a[4]-a[0]<=k){
        printf("Yay!\n");
    }
    else{
        printf(":(\n");
    }
}

Measured memory_bytes: 128
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b, c, d = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    A = [i for i in range(a, b+1)]
    B = [i for i in range(c, d+1)]

    cnt = 0
    for a in A:
        for b in B:
            if a == b:
                cnt += 1
                break

    if cnt == 0:
        print(cnt)
    else:
        print(cnt -1)


resolve()

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  string s;
  cin >> s;
  int a = s[0] - '0';
  int b = s[1] - '0';
  int c = s[2] - '0';
  int d = s[3] - '0';

  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        int t = a;
        t += (i == 0 ? 1 : -1) * b;
        char op1 = (i == 0 ? '+' : '-');
        t += (j == 0 ? 1 : -1) * c;
        char op2 = (j == 0 ? '+' : '-');
        t += (k == 0 ? 1 : -1) * d;
        char op3 = (k == 0 ? '+' : '-');
        if (t == 7) {
          printf("%d%c%d%c%d%c%d=7\n", a, op1, b, op2, c, op3, d);
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll> 
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e4 + 3;

int main(){
    fast;
    int n;
    cin >> n;
    if(n >= 400 && n <= 599) cout << "8";
    else if(n >= 600 && n <= 799) cout << "7";
    else if(n >= 800 && n <= 999) cout << "6";
    else if(n >= 1000 && n <= 1199) cout << "5";
    else if(n >= 1200 && n <= 1399) cout << "4";
    else if(n >= 1400 && n <= 1599) cout << "3";
    else if(n >= 1600 && n <= 1799) cout << "2";
    else cout << "1";
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}

Measured memory_bytes: 3800
import heapq
class Edge:
    src=-1
    dest=-1
    cost=-1

def Dijkstra(graph,s):
    INF=int(1e9)
    d=[INF]*len(graph)
    d[s]=0
    used=[False]*len(graph)
    que=[]
    heapq.heappush(que,(0,s))
    while len(que)!=0:
        val=heapq.heappop(que)
        v=val[1]
        if used[v] : continue
        used[v]=True
        for i in range(0,len(graph[v])):
            e=graph[v][i]
            if d[v]+e.cost<d[e.dest]:
                d[e.dest]=d[v]+e.cost
                heapq.heappush(que,(d[e.dest],e.dest))
    return d

V=int(input())
graph=[[] for i in range(0,V)]
for i in range(0,V):
    vals=list(map(int,input().split(" ")))
    k=vals[1]
    for j in range(0,k):
        v=vals[2+j*2]
        c=vals[3+j*2]
        e=Edge()
        e.src=i
        e.dest=v
        e.cost=c
        graph[i].append(e)

d=Dijkstra(graph,0)
for i in range(0,V):
    print(str(i)+" "+str(d[i]))

Measured memory_bytes: 121108
#include <iostream>
#include <cmath>

using namespace std;

int l, r;
const int d = 2019;

int main()
{
    cin >> l >> r;
    int l_qu = l / d;
    int l_re = l % d;
    int r_qu = r / d;
    int r_re = r % d;

    if (l_qu != r_qu)
    {
        cout << 0 << endl;
    }
    else
    {
        int min = d;
        for (int i = l_re; i < r_re; ++i)
        {
            for (int j = i + 1; j <= r_re; ++j)
            {
                int val = i * j % d;
                if (val < min)
                {
                    min = val;
                }
            }
        }
        cout << min << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,h,w,a,b,ans = 0;
    cin >> n >> h >> w;
    rep(i, n){
        cin >> a >> b;
        if (a >= h && b >= w) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void initialize() {
  head = tail = 0;
}

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b;}

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++ ) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  while ( head != tail ) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if ( u.t > 0 ) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
 }
  }
  return 0;
}

Measured memory_bytes: 12708
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main(){
    int n;
    unsigned long long ans=0LL;
    cin>>n;
    vector<int> cnt(26,0);
    map<string,int> cnt_map;
    string s;
    for(int i=0; i<n; i++){
        cin>>s;
        // for(int j=0;j<10;j++){
        //     cnt[s[j]-'a']++;
        // }
        sort(s.begin(), s.end());
        cnt_map[s]++;
    }
    for(auto x:cnt_map){
        ans+=1LL*x.second*(x.second-1)/2LL;
    }
    cout<<ans<<"\n";
    return 0;
}


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

using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define int long long
#define fi first
#define se second

const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int digits(int n){return floor(log10(n))+1 ;}
bool ispoweroftwo (int x) { return x && (!(x&(x-1))); }


signed main(){
    int n;cin>>n;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    int dp[n+1];
    dp[0]=dp[1]=0;
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n]<<endl;
    
    
    
    return 0;
    
}




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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve(int &test) {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n, greater<int>());
    int ans = a[0];
    int cnt[n] = {0};
    int cur = 1;
    for(int i = 2; i < n; i++){
        if(cnt[cur] > 1)cur++;
        cnt[cur]++;
        ans += a[cur];
    }
    cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;

    start = clock(); 

    cout << fixed << setprecision(2);
    
   
     
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    cerr << time(start);
    return 0;
}

Measured memory_bytes: 6900
s1, s2, s3 = input().split()

S1 = []
for _ in s1:
  S1.append(_)
S2 = []
for _ in s2:
  S2.append(_)
S3 = []
for _ in s3:
  S3.append(_)
  
ans = S1[0]+S2[0]+S3[0]
print(str.upper(ans))

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;
#define min(a,b) ((a)<(b)?(a):(b))

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	int n = 1 << N;
	int *a = new int[n];
	for (int i = 0; i < n; i++) {
		a[i] = 5000000;
	}
	for (int i = 0; i < M; i++) {
		int A, b;
		scanf("%d %d", &A, &b);
		int C = 0;
		for (int j = 0; j < b; j++) {
			int c;
			scanf("%d", &c);
			C |= 1 << (c - 1);
		}
		if (a[C] > A)a[C] = A;
	}
	std::vector<int> c;
	int *dp = new int[n];
	for (int i = 0; i < n; i++) {
		dp[i] = 5000000;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((j&i) == i) {
				dp[i] = min(dp[i], a[j]);
			}
		}
	}
	for (int i = 0; i < N; i++)for (int j = i + 1; j < N; j++) {
		c.push_back((1 << i) | (1 << j));
	}
	for (int i = 0; i < c.size(); i++) {
		for (int j = 0; j < n; j++) {
			if ((c[i] & j) == j) {
				dp[c[i]] = min(dp[c[i]], dp[j] + dp[c[i] - j]);
			}
		}
		for (int j = N - 1; j >= 0; j--) {
			if (c[i] & (1 << j))break;
			c.push_back(c[i] | (1 << j));
		}
	}
	//for (int i = 0; i < n; i++)printf("%d ", dp[i]);
	if (dp[n - 1] == 5000000)printf("-1");
	else printf("%d", dp[n - 1]);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int maxN = 1005;
ll pref[maxN];
int n, k;
int main() {
    //freopen("input.txt", "r", stdin);
    srand(239);
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        pref[i] = pref[i - 1] + x;
    }
    vector < ll > all;
    for (int i = 0; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            all.push_back(pref[j] - pref[i]);
        }
    }
    ll ans = 0;
    for (int bit = 60; bit >= 0; bit--) {
        int cnt = 0;
        for (auto v : all) {
            if (v & (1LL << bit)) cnt++;
        }
        if (cnt < k) continue;
        if (cnt >= k) {
            ans |= (1LL << bit);
            vector < ll > nall;
            for (auto v : all) {
                if (v & (1LL << bit)) nall.push_back(v);
            }
            all = nall;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 6512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nextLong();
            long x = in.nextLong();
            long ans = n;
            long cn = x > n / 2 ? x : n - x;
            long cx = x > n / 2 ? n - x : x;
            while (cx > 0) {
                ans += 2 * cx * (cn / cx);
                if (cn % cx == 0)
                    ans -= cx;
                long temp = cx;
                cx = cn % cx;
                cn = temp;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 21204
#include <iostream>
#include <vector>
using namespace std;
const int lim = 1e5;
typedef long long int ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q, x;
	ll sum = 0;
	cin >> n;
	vector <ll> ar(lim+1, 0);
	vector <ll> v;
	while(n--){
		cin >> x;
		v.push_back(x);
		sum+=x;
		ar[x]++;
	}
	cin >> q;
	while(q--){
		ll a, b;
		cin >> a >> b;
		sum+=ar[a]*(b-a);
		ar[b]+=ar[a];
		ar[a] = 0;
		cout << sum << "\n";
	}
}

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

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

  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s.substr(i, 1) == "o") {
      output = output + 100;
    }
  }
  cout << output << endl;
}


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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
static const int INF = 1e9;
static const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main(){
    ios::sync_with_stdio(true);
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 string n;
 cin>>n;
 int sum = 0;
 for(int i=0;i<n.size();i++){
  sum =  sum +(n[i] - '0');
 }
 if(sum%9==0){
  cout<<"Yes\n";
 } else {
  cout<<"No\n";
 }
 return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,d;
    
    scanf("%d %d\n",&a,&b);
    scanf("%d %d\n",&c,&d);
    
    if(a!=c) printf("1\n");
    else     printf("0\n");
    
    return 0;
}


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

int main()
{
	int n;
	while(cin>>n && n){
		int sum = 2;
		int cnt = 1;
		bool flag = true;
		for(int i=3;;i+=2){
			if(cnt == n){
				cout<<sum<<endl;
				break;
			}
			for(int j=2;j*j<=i;j++){
				if(i % j==0){
					flag = false;
					break;
				}
			}
			if(flag){
				sum += i;
				cnt++;
			}
			flag = true;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int N = 3e5 + 4;
int W, H, A, B;
long long rev[N], fac[N];

long long Pow(long long x, long long y) {
    long long res = 1, z = x;
    while (y) {
        if (y & 1) res = res*z % MOD;
        z = z*z % MOD;
        y >>= 1;
    }
    return res;
}

int prepare() {
    fac[0] = 1; rev[0] = 1;
    for (int i = 1; i <= 300000; i++) {
        fac[i] = fac[i-1]*i % MOD;
        rev[i] = rev[i-1]*Pow(i, MOD - 2) % MOD;
    }
}

long long C(int x, int y) {
    return (fac[x]*rev[x-y] % MOD * rev[y]) % MOD;
}

long long O(int x, int y) {
    return C(x + y - 2, x - 1);
}

int main() {
    prepare();    cin >> H >> W >> A >> B;
    vector <long long> a; a.clear();
    for (int i = B + 1; i <= W; i++) a.push_back(O(H - A, i));
    vector <long long> b; b.clear();
    for (int i = 1; i <= W - B; i++) b.push_back(O(A, i));
    long long res = 0;
    for (int i = 0; i < a.size(); i++) res = (res + a[i]*b[b.size()-i-1]) % MOD;
    cout << res << endl;
}




















Measured memory_bytes: 7284
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    temp = 0
    for a, b in zip(A, B):
        temp += a * b
    temp += C
    if temp > 0:
        ans += 1
print(ans)

Measured memory_bytes: 62152
#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()
{
  int N, M;
  cin >> N >> M;
  cout << (N * (N - 1) / 2) + (M * (M - 1) / 2) << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
 
		int time[] = new int[3];
		time[0] = p + q;
		time[1] = r + q;
		time[2] = p + r;
 
		Arrays.sort(time);

		System.out.println(time[0]);
	}
}

Measured memory_bytes: 23764
n = int(raw_input())
a = [0] + map(int, raw_input().split()) + [0]
sum = 0

for i in range(0, n+1):
	sum = sum + abs(a[i+1]-a[i])

for i in range(0, n):
	print sum - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1]) + abs(a[i+2]-a[i])

Measured memory_bytes: 11132
from itertools import product

# コンプリートする問題は2**D通りあるが、最大でも1024通りなので全探索する
# 点数が足りない場合は配点が高い問題から解いていく

d, g = map(int, input().split())
P, C = [], []
for _ in range(d):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)

combination = list(product(*[[0, 1]]*d))

ans = float('inf')
for comb in combination:
    # 先ずは、コンプリートする問題の点数を計算する
    score, cnt = 0, 0
    for i, c in enumerate(comb):
        if c == 1:
            score += P[i]*100*(i+1) + C[i]
            cnt += P[i]
            
    if score >= g:  # 目標点数に到達
        ans = min(ans, cnt)
        
    else:  # 目標点数に未到達
        # 解いていない問題のうち、最も点数が高い問題を解く
        NoSolved = [i for i, c in enumerate(comb) if c == 0]
        i = NoSolved[-1]
        for _ in range(P[i]):
            score += (i+1)*100
            cnt += 1
            if score >= g:
                ans = min(ans, cnt)
                break
        else:  # 目標点数に達しなかった
            pass
print(ans)        

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}

signed main(){
    llin(x);
    ll y,z;
    y=x/500;
    z=(x%500)/5;
    sal(y*1000+z*5);
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			String s = in.next();
			int cnt1 = 0, cnt2 = 0;
			for(int i = 0; i < s.length() - 2; i++){
				if(s.charAt(i) == 'J' && s.charAt(i + 1) == 'O' && s.charAt( i + 2) == 'I') cnt1++;
				else if(s.charAt(i) == 'I' && s.charAt(i + 1) == 'O' && s.charAt( i + 2) == 'I') cnt2++;
			}
			System.out.println(cnt1);
			System.out.println(cnt2);
		}
	}

	
}

Measured memory_bytes: 27824
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  map<int,int> memo;
  memo[A]++;
  memo[B]++;
  memo[C]++;
  if(memo[5]==2 && memo[7]==1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define INF (1<<22)
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n, m; cin >> n >> m;
	int d[20];
	for (int i=0;i<m;++i)cin>>d[i];
	int dp[1000000]; fill(dp, dp + n + 1, INF);
	dp[0]=0;
	for(int i=0;i<m;++i)for(int j=d[i];j<=n;++j){
		dp[j]=min(dp[j],dp[j-d[i]]+1);
	}cout<<dp[n]<<endl;
}

Measured memory_bytes: 1388
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if (n == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35652
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
P p[55];
int n;
int cal(ll dx,ll dy)
{
    set<P> s;
    for(int i=1;i<=n;i++)s.insert(p[i]);
    int res=0;
    while(!s.empty())
    {
        P tp=*s.begin();
        ll x=tp.fi,y=tp.se;
        while(s.find(P(x,y))!=s.end())
        {
            s.erase(P(x,y));
            x+=dx,y+=dy;
        }
        res++;
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lld%lld",&p[i].fi,&p[i].se);
    map<P,int> mp;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(j==i)continue;
            int dx=p[i].fi-p[j].fi,dy=p[i].se-p[j].se;
            mp[P(dx,dy)]++;
        }
    }
    int ans=0;
    for(auto x:mp)ans=max(ans,x.second);
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 384
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

data = {}
for x in ["a","b","c"]:
    data[x] = input()

pick = "a"
while True:
    if data[pick] == "":
        break
    temp = data[pick][0]
    data[pick] = data[pick][1:]
    pick = temp
print(pick.upper())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;cin>>s;
    int N=s.size();
    int count1=0;int count2=0;
    for(int i=0;i<N;i++){
        if(i%2==0 && s[i]=='0')count1++;
        if(i%2==0 && s[i]=='1')count2++;
        if(i%2==1 && s[i]=='0')count2++;
        if(i%2==1 && s[i]=='1')count1++;
    }
    cout<<min(count1,count2)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,nu,i,c=0;
	cin>>n;
	for(i=0;i<n;i++) {
		cin>>nu;
		if(i%2==0 && nu&1) c++;
	}
	cout<<c;
	
	
}

Measured memory_bytes: 3648
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int h, w, k;
    scan(h, w, k);

    auto c = new int[][](w, w);

    foreach (s ; 0 .. (1 << (w - 1))) {
        if (s & (s >> 1)) continue;
        auto p = iota(0, w).array;

        foreach (i ; 0 .. w - 1) {
            if (s & (1 << i)) {
                swap(p[i], p[i + 1]);
            }
        }

        foreach (i ; 0 .. w) {
            c[i][p[i]]++;
        }
    }

    debug {
        writefln("%(%s\n%)", c);
    }

    auto dp = new long[][](h + 1, w);
    dp[0][0] = 1;

    foreach (i ; 1 .. h + 1) {
        foreach (j ; 0 .. w) {
            foreach (s ; 0 .. w) {
                dp[i][j] += dp[i - 1][s] * c[s][j] % mod;
                dp[i][j] %= mod;
            }
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    auto ans = dp[h][k - 1];
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * http://abc069.contest.atcoder.jp/tasks/arc080_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		long[] a = new long[N];
		for(int i=0; i<N; i++) a[i] = sc.nextLong();
		sc.close();
		
		int four = 0;
		int odds = 0;
		int evens = 0;
		for(int i=0; i<N; i++){
			if(a[i]%4==0){
				four++;
			}else if(a[i]%2==0){
				evens++;
			}else{
				odds++;
			}
		}
		
		boolean ans = (evens==0 && four+1>=odds) || (evens>0 && four>=odds);
		
		System.out.println(ans ? "Yes" : "No");

	}

}

Measured memory_bytes: 49920
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int H, W;
    cin >> H >> W;
    
    vector<string> field(H);
    REP(i, H) cin >> field[i];

    int cnt = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if (field[i][j] == '#') cnt++;
        }
    }

    cout << ((cnt == H+W-1) ? "Possible" : "Impossible") << endl;

    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, s; cin >> n >> k >> s;
	int t = s + 1;
	if (s == 1000000000) t = s - 1;
	for (int i = 0; i < k; i++) cout << s << " ";
	for (int i = 0; i < n - k; i++) cout << t << " ";
	cout << '\n';
	return 0;
}	

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int A, B; cin >> A >> B;
    string ans = "Yay!";
    if (A > 8 || B > 8) {
        ans = ":(";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	int sum=a+b;
	if (sum%2==0) cout<<sum/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

ll n, m, k;

ll f[maxn];
ll power(ll a, ll x)
{
    ll res = 1;
    while (x)
    {
        if (x & 1)
            res = res * a % mod;
        a = a * a % mod;
        x /= 2;
    }
    return res;
}
ll inv(ll x)
{
    return power(x, mod - 2);
}

ll C(ll x, ll y)
{
    ll ans = f[x] * inv(f[y]) % mod * inv(f[x - y]) % mod;
    return ans;
}

int main()
{
    cin >> n >> m >> k;
    f[0] = 1;
    for (int i = 1; i <= n; i++)
        f[i] = f[i - 1] * i % mod;
    ll ans = 0;
    for (int i = 0; i <= k; i++)
    {
        ll now = m * power(m - 1, n - 1 - i) % mod * C(n - 1, i) % mod;
        //printf("%d\n", now);
        ans = (ans + now) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 5216
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String S = sc.next();
        String T = sc.next();
    
        String regaxT = String.format("%s.", S);

        if(T.matches(regaxT)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35684
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    vector<int> list(N);
    int count = 0;
    rep (i,N){
        cin >> list[i];
    }
    int a,b,c;
    for (int i = 0;i < N;i++){
        for (int j = i+1;j < N;j++){
            for (int k = j+1;k < N;k++){
                if ((list[i] != list[j]) && (list[j] != list[k]) && (list[i] != list[k])){
                   a = list[i];
                   b = list[j];
                   c = list[k];
                   if (((a + b) > c) && ((b + c) > a) && ((a + c) > b)){
                       count++;
                   }  
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

const vector<vector<int>> dir2 = {{0, 1}, {1, 0}};
const vector<vector<int>> dir8 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
const int INF = 1e9;


int main()
{
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++)cin >> s[i];
    vector<vector<int>> dp(h, vector<int>(w, INF)); //dp[i][j] := [i][j]に行く時に通る最小の黒集団
    dp[0][0] = s[0][0] == '#';

    queue<pair<int,int>> que;
    que.push({0, 0});
    dp[0][0] = s[0][0] == '#';

    while(que.size()) {
        auto cur = que.front();                 
        que.pop();
        for(auto d : dir2) {
            int ny = d[0] + cur.first;
            int nx = d[1] + cur.second;
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(dp[ny][nx] > dp[cur.first][cur.second] + (s[ny][nx] == '#' && s[cur.first][cur.second] == '.')) {
                dp[ny][nx] = dp[cur.first][cur.second] + (s[ny][nx] == '#' && s[cur.first][cur.second] == '.' );
                que.emplace(ny, nx);
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
n,w=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(n):
  a,b=map(int,input().split())
  for j in range(w+1):
    if j>=b:dp[i+1][j]=max(dp[i][j],dp[i][j-b]+a)
    else:dp[i+1][j]=dp[i][j]
print(dp[n][w])


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

int op(int l, int r) {
	return max(l, r);
}
int e() {
	return 0;
}

int main() {
	int n, k; cin >> n >> k;
	segtree<int, op, e> seg(300010);
	int ans = 0;
	while(n--) {
		int a; cin >> a;
		int tmp = seg.prod(max(a - k, 0), min(a + k + 1, 300010));
		ans = max(ans, tmp + 1);
		seg.set(a, tmp + 1);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 8572
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll L(2);
  L[0] = 2;
  L[1] = 1;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  REP(i, 2, N+1) {
    L.emplace_back(L[i-1] + L[i-2]);
  }
  cout << L[N] << endl;

  return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;

  vll a(n);
  ll sum = 0;
  REP(i, n){
    cin >> a[i];
    sum += a[i];
  }

  ll topSum = 0;
  ll ans = LLINF;
  REP(i, n-1){
    topSum += a[i];
    sum -= a[i];
    ans = min(ans, abs(sum-topSum));
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 1792