akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std;

const int N=610;
struct point{ int x,y; }p[90010];
int h,w,m=300,cnt,a[N][N],r[N][N],c[N][N];
long long ans;

int main(){
	scanf("%d%d",&h,&w);
	rep(i,1,h){
		char str[310]; scanf("%s",str+1);
		rep(j,1,w){
			if (str[j]=='#'){
				int x=i+j-1,y=i-j+m;
				p[cnt++]=(point){x,y}; a[x][y]=1;
			}
		}
	}
	m*=2;
	rep(i,1,m) rep(j,1,m) r[i][j]=r[i][j-1]+a[i][j],c[i][j]=c[i-1][j]+a[i][j];
	for (int i=0;i<cnt;i++){
		int x=p[i].x,y=p[i].y;
		for (int d=2;d<=m;d+=2){
			if (y+d<=m && a[x][y+d]){
				if (x+d<=m) ans+=r[x+d][y+d]-r[x+d][y-1];
				if (x-d>0) ans+=r[x-d][y+d]-r[x-d][y-1];
			}
			if (x+d<=m && a[x+d][y]){
				if (y+d<=m) ans+=c[x+d-1][y+d]-c[x][y+d];
				if (y-d>0) ans+=c[x+d-1][y-d]-c[x][y-d];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 
const double PI=3.14159265358979323846;



ll kaijo[2000010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i < 2000010;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}
 
ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}
 
ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd,N-2)) % N) % N;
}

int main(void){
    ll x,y,z,k;
	cin>>x>>y>>z>>k;
	vector<ll>a(x),b(y),c(z),d,ans;
	for(int i=0;i<x;i++)cin>>a[i];
	for(int i=0;i<y;i++)cin>>b[i];
	for(int i=0;i<z;i++)cin>>c[i];
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			d.push_back(a[i]+b[j]);
		}
	}
	sort(d.begin(),d.end(),greater<ll>());
	sort(c.begin(),c.end(),greater<ll>());
	ll L = min(10000LL,(ll)d.size());
	for(int i=0;i<L;i++){
		for(int j=0;j<z;j++){
			ans.push_back(d[i]+c[j]);
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());
	for(int i=0;i<k;i++)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 142336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll a,b,tmp;
    cin>>a>>b;
    ll x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

    cout<<x/b<<endl;
}

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

double to_f(const string &s) {
    istringstream is(s);
    double d;
    is >> d;
    return d;
}

string binary(int n, int p) {
    string s;
    int r = 1<<(p-1);
    while (r != 0) {
        if (n / r) {
            s.push_back('1');
        } else {
            s.push_back('0');
        }
        n %= r;
        r >>= 1;
    }
    return s;
}

int main() {
    string s;
    while (cin >> s) {
        if (s[0] == '-') break;
        int n; double d;
        n = (int)to_f(s);
        d = to_f(s) - n;
//        cout << n << ' ' << d << endl;

        if (0 <= n && n < (1<<8) && d*16 == (int)(d*16)) {
            cout << binary(n, 8) << '.' << binary(d*16, 4) << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#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 REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define sd(n) scanf("%d",&n)
#define dsd(n) int n; scanf("%d",&n)
#define sd2(a,b) scanf("%d%d",&a,&b)
#define dsd2(a,b) int a,b; scanf("%d%d",&a,&b)
#define pd(n) printf("%d\n",n)
#define pds(n) printf("%d ",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define pll(n) printf("%lld\n",n)	
#define plls(n) printf("%lld ",n)	
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 1000010;
//int arr[MAX_N];

int main(){
    dsd2(N,K);
    if(2*K-1<=N) printf("YES\n");
    else printf("NO\n");
	return 0;
}


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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  if(n % 2 == 1){
    for(int i=0; i<m; ++i){
      a[i] = i + 1;
      b[i] = 2*m - i;
    }
  }
  else{
    for(int i=0; i<(m+1)/2; ++i){
      a[i] = i + 1;
      b[i] = ((m+1)/2)*2 - i;
    }
    for(int i= (m+1)/2 ; i<m; ++i){
      a[i] = ((m+1)/2) * 2 + (i - (m+1)/2) +1;
      b[i] = 2 * m + 1 - (i-(m+1)/2);
    }
  }
  for(int i=0; i<m; ++i){
    cout << a[i] << " " << b[i]<< endl;
  }
  
 }


Measured memory_bytes: 4248
x1, y1, x2, y2 = map(int, input().split())

x_diff = x2 - x1
y_diff = y2 - y1

x3 = x2 - y_diff
y3 = y2 + x_diff

x4 = x1 - y_diff
y4 = y1 + x_diff

print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    rep(i, n){
        int count = 0;
        for(char c='a'; c<='z'; c++){
            bool left = false;
            bool right = false;
            for(int j=0; j<=i; j++){
                if(c == s[j]){
                    left = true;
                    break;
                }
            }
            for(int k=i+1; k<n; k++){
                if(c == s[k]){
                    right = true;
                    break;
                }
            }
            if(right && left)
                count++;
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

const int ddx[] = {1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1};
const int ddy[] = {0, 1, 0, 1, -1, 0, 0, 1, 1, 1, 1, -1, -1};
const int ddz[] = {0, 0, 1, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1};

int n, m, p;
int board[10][10][10];
vector<pair<int, int>> play;

bool check(int c) {
  int cnt = 0;
  int ren = 0;

  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int z = 0; z < n; z++) {
        for (int k = 0; k < 13; k++) {
          cnt = 0;
          int nx = x;
          int ny = y;
          int nz = z;
          while (0 <= nx && 0 <= ny && 0 <= nz && nx < n && ny < n && nz < n &&
                 c == board[nx][ny][nz]) {
            nx += ddx[k];
            ny += ddy[k];
            nz += ddz[k];
            cnt++;
          }
          ren = max(ren, cnt);
        }
      }
    }
  }

  return m <= ren;
}

int main() {
  while (true) {
    cin >> n >> m >> p;
    if (n == 0) break;
    play.clear();
    for (int i = 0; i < p; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      play.emplace_back(x, y);
    }

    for (int x = 0; x < n; x++) {
      for (int y = 0; y < n; y++) {
        for (int z = 0; z < n; z++) {
          board[x][y][z] = -1;
        }
      }
    }
    int color = 0;  // 0 : black, 1 : white
    bool isDraw = true;
    for (int i = 0; i < p; i++) {
      color = i % 2;
      int a, b;
      tie(a, b) = play[i];
      for (int i = 0; i < n; i++) {
        if (board[a][b][i] != -1) continue;
        board[a][b][i] = color;
        break;
      }

      if (check(color)) {
        cout << (color == 0 ? "Black " : "White ") << i + 1 << endl;
        isDraw = false;
        break;
      }
    }
    if (isDraw) cout << "Draw" << endl;
  }

  return 0;
}


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

const int MAX=200005;
const ll MOD=1000000007;
vector<int> conn[MAX],dcnt[MAX],toff[MAX];
queue<int> active,active2;
int par[MAX],depth[MAX],tpar[MAX],chk[MAX],n;
pll dp[MAX];
ll ans;
ll power(ll x,ll y){
    if(y==0) return 1;
    ll t=power(x,y/2);
    t=t*t%MOD;
    if(y%2) return t*x%MOD;
    return t;
}
void dfs(int x,int d){
    depth[x]=d,dcnt[d].push_back(x);
    for(int i=0;i<conn[x].size();i++) dfs(conn[x][i],d+1);
}
void build(int x){
    if(x==0) {
        active.push(0);
        return;
    }
    if(toff[x].size()!=0) return;
    build(tpar[x]); toff[tpar[x]].push_back(x), active.push(x);
}
void dest(int x){
    if(x==0){
        for(int i=0;i<toff[0].size();i++) dest(toff[0][i]);
        return;
    }
    if(toff[x].size()==0) return;
    else{
        int t=x;
        while(toff[t].size()==1) t=toff[t][0];
        tpar[t]=tpar[x];
        for(int i=0;i<toff[t].size();i++) dest(toff[t][i]);
    }
}
pll cal(int x){
    if(chk[x]) return dp[x];
    chk[x]=1;
    if(toff[x].size()==0){
        return dp[x]=make_pair(1,1);
    }
    pll t=make_pair(0,1);
    ll u=1;
    for(int i=0;i<toff[x].size();i++){
        pll tmp=cal(toff[x][i]);
        t.second*=tmp.first+tmp.second, u*=tmp.second;
        t.second%=MOD, u%=MOD;
    }
    for(int i=0;i<toff[x].size();i++){
        pll tmp=cal(toff[x][i]);
        t.first+=u*tmp.first%MOD*power(tmp.second,MOD-2)%MOD;
        t.first%=MOD;
    }
    t.second-=t.first-MOD; t.second%=MOD;
    return dp[x]=t;
}
int main(){
    scanf(" %d",&n);
    for(int i=1;i<=n;i++) {
        scanf(" %d",&par[i]);
        conn[par[i]].push_back(i);
    }
    dfs(0,0);
    for(int i=0;i<=n;i++) if(dcnt[i].size()>0){
        for(int j=0;j<dcnt[i].size();j++){
            tpar[dcnt[i][j]]=par[dcnt[i][j]];
            build(dcnt[i][j]);
        }
        dest(0);
        while(!active.empty()){int t=active.front();active.pop(),toff[t].clear();}
        for(int j=0;j<dcnt[i].size();j++) build(dcnt[i][j]);
        ans+=cal(0).first*power(2,n+1-dcnt[i].size())%MOD; ans%=MOD;
        //printf("%d : %lld\n",i,ans);
        while(!active.empty()){int t=active.front();active.pop(),toff[t].clear(),chk[t]=0;}
    }
    printf("%lld\n",ans);
}


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

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

  if (S.size() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << ((S.substr(0, N / 2) == S.substr(N / 2, N / 2)) ? "Yes" : "No") << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int a_MAX = 0;
  int a_MIN = 1111;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a_MAX = max(a_MAX, a[i]);
    a_MIN = min(a_MIN, a[i]);
  }
  cout << a_MAX - a_MIN << endl;
}

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

int main(void){
    int N,Alice=0,Bob=0,cnt=0;
    cin>>N;
    vector<int> a;
    for(int i=0;i<N;i++){
        int num;
        cin>>num;
        a.push_back(num);
    }

    sort(a.begin(),a.end());

    reverse(a.begin(),a.end());

    for(int i=0;i<N;i++){
        if(cnt%2==0){
            Alice+=a[i];
        }
        else if(cnt%2==1){
            Bob+=a[i];
        }
        cnt++;
    }
    cout<<Alice-Bob<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 610000
ll n,m,k;
double dp[400][400][400];
ll a[N];
ll b[N];
int mp[2000][2000];
int main(){
    n=in();
    rep(i,n){
        a[i]=in();
    }
    dp[0][0][0]=0.0;
    rep(i,n+1)rep(j,n+1)rep(k,n+1){
        if(k>0){
            dp[k][j][i]+=(1+dp[k-1][j][i])*((double)k/(double)n);
        }
        if(j){
            dp[k][j][i]+=(1+dp[k+1][j-1][i])*((double)j/(double)n);

        }
        if(i){
            dp[k][j][i]+=(1+dp[k][j+1][i-1])*((double)i/(double)n);
        }
        if(i+j+k)
        dp[k][j][i]+=(double)(n-i-j-k)/(double)n;
        if(i+j+k)
        dp[k][j][i]*=(double)n/(double)(i+j+k);
    }
    int c[4]={};
    rep(i,n){
        c[a[i]]++;
    }
    printf("%.10f",dp[c[1]][c[2]][c[3]]);
    return 0;
}

Measured memory_bytes: 379136
#include<stdio.h>
int main(void){
int n,m;
  scanf("%d%d",&n,&m);
  int h[n];
  for(int i=0;i<n;i++){
	scanf("%d",&h[i]);
  }
  int ab[m][2];
  for(int i=0;i<m;i++){
	scanf("%d%d",&ab[i][0],&ab[i][1]);
  }
  int flag[n];
  for(int i=0;i<n;i++){
	flag[i]=0;
  }
  for(int i=0;i<m;i++){
    	if(h[ab[i][0]-1]==h[ab[i][1]-1]){
          flag[ab[i][0]-1]=1;
          flag[ab[i][1]-1]=1;
        }
    	else if(h[ab[i][0]-1]>h[ab[i][1]-1])flag[ab[i][1]-1]=1;
    	else flag[ab[i][0]-1]=1;
  }
  int count=0;
  for(int i=0;i<n;i++){
    	if(flag[i]==0)count++;
  }
  printf("%d",count);
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,m,k;cin>>n>>m>>k;
  vector<ll> a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  rep(i, n-1)a[i+1]+=a[i];
  rep(i, m-1)b[i+1]+=b[i];

  ll result=0;
  auto ait = upper_bound(a.begin(), a.end(), k);
  result = max<ll>( result, (ll)(ait-a.begin()) );
  
  auto bit = upper_bound(b.begin(), b.end(), k);
  result = max<ll>( result, (ll)(bit-b.begin()) );

  rep(i, n){
    ll ac = i+1;
    ll lim = k-a[i];
    if(lim<0)continue;

    result = max<ll>(result, ac);

    auto it = upper_bound(b.begin(), b.end(), lim);

    ll bc = it-b.begin();
    result = max<ll>(result, ac+bc);
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 6316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<utility>//swapでaとbの値を入れ替える
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whie(a) vector<vector<int>>

int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}


int main() {
	ll n,t;
	ll ans = 0;
	cin >> n>>t;
	hei(ll)a(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 1) {
		ll s = a[i + 1] - a[i];
		if (t > s)ans += t - s;
	}
	ans = n * t - ans;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 2147483647
#define Max 500000
#define NTL -1
#define min(a,b) ((a>b)?b:a)
#define max(a,b) ((a<b)?b:a)

int main(){
  int a,b,c,k,tmp,ans,i;
  scanf("%d%d%d",&a,&b,&c);
  scanf("%d",&k);
  if(a>b){
    tmp=a;a=b;b=tmp;
  }
  if(b>c){
    tmp=b;b=c;c=tmp;
  }
  for(i=0;i<k;i++){
    c*=2;
  }
  ans=a+b+c;
  printf("%d",ans);
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll A,B,N; cin >> A>>B>>N;
    ll tmp = 0;
    ll ans = 0;

    ll a = (A*N/B) - A*(N/B);
    ll b = (A*(B-1)/B) - A*((B-1)/B);

    if (B <= N){
      if(a>=b){
        cout << a << endl;
      } else {
        cout << b << endl;
      }
    } else {
      cout << (A * N / B) - A * (N / B) << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3624
s=input()
if len(s)<26:
    num=list(range(97,123))
    for i in range(len(s)):
        num.remove(ord(s[i]))
    print(s+chr(num[0]))
else:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(25):
            if ord(s[-1-i])>ord(s[-2-i]):
                str1=s[-2-i]
                num1=26-(2+i)
                break
        ans=123
        num3=ord(str1)
        for i in range(num1+1,26):
            num4=ord(s[i])
            if num3<num4:
                ans=min(ans,num4)
        print(s[:num1]+chr(ans))


Measured memory_bytes: 9072
S=gets.chomp
T=gets.chomp

S2T=Hash.new
T2S=Hash.new

S.size.times do |i|
  si,ti=S[i],T[i]
  if S2T[si]==nil
    S2T[si]=ti
  elsif S2T[si]!=ti
    puts "No"
    exit
  end
  if T2S[ti]==nil
    T2S[ti]=si
  elsif T2S[ti]!=si
    puts "No"
    exit
  end
end

puts "Yes"

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

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a, b;
  cin >> a >> b;

  if (a >= 13)
  {
    cout << b << endl;
  }
  else if (6 <= a)
  {
    cout << b / 2 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  ll A,C;
  double B;
  cin >> A >> B;
  C = A*B;
    cout << C << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    int maxi = (n - 2) * (n - 1) / 2;
    if (k > maxi)
    {
        cout << "-1";
        return 0;
    }
    int dod = maxi - k;
    cout << n - 1 + dod << endl;
    for (int i = 2; i <= n; ++i)
        cout << "1 " << i << endl;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            if (dod > 0)
            {
                cout << i << " " << j << endl;
                --dod;
            }
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n; cin >> n;
  VI c(n);
  REP(i, n) cin >> c[i];
  int q; cin >> q;
  VI t(q), x(q), d(q);
  REP(i, q) cin >> t[i] >> x[i] >> d[i], x[i]--;

  VI box(n);
  REP(i, q) {
    if(t[i]==1) {
      box[x[i]] += d[i];
      if(box[x[i]] > c[x[i]]) {
        cout << x[i]+1 << endl;
        return 0;
      }
    } else {
      box[x[i]] -= d[i];
      if(box[x[i]] < 0) {
        cout << x[i]+1 << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;

  return 0;
}



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

if N==1:
    print(1)
    exit()
else:
        
    
    L=[0 for i in range((10**5)+1)]
    for i in range(2,10**5):
        while M%i==0:
            L[i]+=1
            M//=i
        if M==1:
            break
    if M>1:
        L.append(1)
    
    mod=(10**9+7)
    
    def cmb(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod
    
    mod = 10**9+7 #出力の制限
    N1 = (10**5)*2
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    
    for i in range( 2, N1 + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    ans=1
    for i in range(len(L)):
        if L[i]!=0:
            ans*=cmb(L[i]+N-1,min(L[i],N),mod)
            ans%=mod
            
    print(ans)

Measured memory_bytes: 28020
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;

int in() {
	int res = 0;
	for(int i = 0; i < 4; ++i) {
		int in;
		cin >> in;
		res += in;
	}

	return res;
}

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

	cout << max(in(), in()) << endl;

	return EXIT_SUCCESS;
}

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

int main()
{
    ll X;
    cin >> X;
    for(int i = -2000; i <= 2000; i++){
        for(int j = -2000; j <= i; j++){
            ll x = (ll)i*i*i*i*i, y = (ll)j*j*j*j*j;
            if(x - y == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 2e5 + 4;
ll i,j,n;
ll a[N], g[N];
vi v;
vi d[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    for(i = 1;i < N;i += 1) for(j = i + i;j < N;j += i)
        d[j].pb(i);
    cin>>n;
    rep(i,1,n + 1) cin>>a[i];
    revrep(i,n,1){
        if(g[i] != a[i]){
            v.pb(i);
            for(auto w: d[i]) g[w] = 1 - g[w];
        }
    }
    cout<<v.size()<<endl;
    for(auto e: v) cout<<e<<" ";
    return 0;
}

Measured memory_bytes: 38008
#include <bits/stdc++.h>
using namespace std;
int n,ans;
char c[110];
int main () {
	scanf("%s",c+1);
	n=strlen(c+1);
	for (int i=1;i<=n/2;i++) {ans+=(c[i]!=c[n-i+1]);}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll a, b;
    cin>>a>>b;
    if(a > 0) {
        cout<<"Positive\n";
        return 0;
    }
    if(a <= 0 && b >= 0) {
        cout<<"Zero\n";
        return 0;
    }
    if(b < 0) {
        if((b-a+1)%2 == 0) {
            cout<<"Positive\n";
        }
        else {
            cout<<"Negative\n";
        }
        return 0;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n){
    if(n==1||n==1){
        return false;
    }
    for(int i=2;i<n;++i){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
int fact(int n){
    int ans = 1;
    for(int i = 1; i<= n; ++i){
        ans *= i;
    }
    return ans;
}


int main()
{
    int t, a1, a2, c;
    cin>>t>>c;
    if(c >= t){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
}

Measured memory_bytes: 3528
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define LI long int
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
using namespace std;
//
const int INF=1e9+7;
const int LINF=1e18;
const int MOD=1e9+7;
//

int main(){
    int n,m; cin>>n>>m;
    long int x2=0,y2=0;
    FOR(i,0,n){
        long int x; cin>>x;
        x2+=(2*i-n+1)*x;
    }
    FOR(i,0,m){
        long int y; cin>>y;
        y2+=(2*i-m+1)*y;
    }    
    cout<<((x2%MOD)*(y2%MOD))%MOD<<endl;
}

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);

int main() {
    fastio;

    int x, a, b;
    cin >> x >> a >> b;

    if (b - a <= 0) {
        cout << "delicious\n";
    } else if (b - a <= x) {
        cout << "safe\n";
    } else {
        cout << "dangerous\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
	if (a < b) return gcd(b, a);
	long long int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
long long int prime_check(long long int p) {
	for (size_t i = 2; i <= sqrt(p); i++)
	{
		if ((p%i)==0)
		{
			return 0;
		}
	}
	return 1;
}
int main() {
	long long int A, B, C;

	cin >> A >> B;
	C = gcd(A, B);
	queue<long long int> cnd;
	int ans = 0;
	for (size_t i = 1; i <= sqrt(C); i++)
	{
		if (C % i == 0)
		{
			//cout << i<<endl;
			cnd.push(i);
			if (C != 1)cnd.push(C / i);
		}
	}
	//cout << "break";
	while (!cnd.empty())
	{
		//cout << cnd.front()<<endl;
		if (prime_check(cnd.front()) == 1) {
			//cout << cnd.front();
			ans++;
		}
		cnd.pop();
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define MAX 100000007
#define INF (1<<29)
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  double K;
  cin >> K;
  double l= ceil(K/2.0);
  double r= floor(K/2.0);
  double ans;
  ans=r*l;
  cout << ans << endl;
  return 0;
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int h,n;cin>>h>>n;

  vi a(n), b(n);
  vector<pii> ab;
  rep(i, n){
    cin>>a[i]>>b[i];
    ab.pb(mp(a[i], b[i]));
  }
  // sort(all(ab));
  dump(ab);

  const int H = 10000;
  // const int H = 30;
  vvi dp(n+1, vi(h+H+1, INF));
  dp[0][h+H] = 0;

  rep(i, 1, n+1){
    // dp[i][r]
    // not use
    rep(r, 0, h+H+1) chmin(dp[i][r], dp[i-1][r]);

    // use [i-1]
    rrep(r, 0, h+H+1){
      // dump(r);
      if (r+a[i-1]<=h+H) chmin(dp[i][r], dp[i-1][r+a[i-1]]+b[i-1]);
      if (r+a[i-1]<=h+H) chmin(dp[i][r], dp[i][r+a[i-1]]+b[i-1]);
    }
  }
  // dump(dp, n+1, h+H+1);

  int ans = INF;
  rep(r, 0, H+1) {
    if (dp[n][r]<INF) chmin(ans, dp[n][r]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 162560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];
int ans=INF;
signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		int sum=0,sum2=0;
		for(int j=0;j<=i;j++){
			sum+=A[j];
		}
		for(int j=i+1;j<N;j++){
			sum2+=A[j];
		}
		ans=min(ans,abs(sum2-sum));
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  double s = 0;
  for (int i = 0; i < n; i++) {
    double a; cin >> a;
    s += 1.0 / a;
  }
  cout << setprecision(20) << (1.0 / s) << endl;
}

Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;

int aa[N];

bool check(long long p, long long q, long long r, long long s) {
	return abs(p - q) > abs(r - s);
}

int main() {
	int n; cin >> n;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += aa[i] = a;
	}
	long long b = aa[0], c = aa[1], d = aa[2], e = sum - b - c - d;
	long long ans = INF;
	for (int h = 1, i = 2, j = 3, a; i + 1 < n; i++) {
		while (h >= 2 && (a = aa[h - 1]) && check(b, c, b - a, c + a)) {
			b -= a, c += a;
			h--;
		}
		while (i - h >= 2 && (a = aa[h]) && check(b, c, b + a, c - a)) {
			b += a, c -= a;
			h++;
		}
		while (j - i >= 2 && (a = aa[j - 1]) && check(d, e, d - a, e + a)) {
			d -= a, e += a;
			j--;
		}
		while (n - j >= 2 && (a = aa[j]) && check(d, e, d + a, e - a)) {
			d += a, e -= a;
			j++;
		}
		long long x = min(min(b, c), min(d, e));
		long long y = max(max(b, c), max(d, e));
		ans = min(ans, y - x);
		a = aa[i];
		c += a, d -= a;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4372
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
L = len(S)
a = -1
for i in range(L):
    if S[i] == 'A':
        a = i
        break

z = -1
for i in range(L):
    if S[-(i + 1)] == 'Z':
        z = i
        break

print(L - z - a)

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

int main() {
    int H, W;
    string pic;
    cin >> H >> W;

    cout << '#';
    for (int i = 0; i < W; i++) {
        cout << '#';
    }
    cout << '#' << endl;

    for (int i = 0; i < H; i++) {
        cin >> pic;
        cout << '#' << pic << '#' << endl;
    }

    cout << '#';
        for (int i = 0; i < W; i++) {
        cout << '#';
    }
    cout << '#' << endl;

    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String moji;
		moji = sc.next();

		char[] c = moji.toCharArray();
		int x = 0;
		for (int i = 0; i <= n - 1; i++) {
			if (c[i] == 'R') {
				x++;
			}

		}

		if (x > n / 2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
  ll N, M, sum;
  vector<int> A(20000);
  cin >> N >> M;
  rep(i, M) cin >> A.at(i);
  rep(i, M) sum += A.at(i);
  if(N < sum) cout << -1 << endl;
  else cout << N - sum << endl;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

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

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int main(void) {
    int n, k;
    cin >> n >> k;
    VI a(n, 0);
    REP(i, n) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }
    sort(ALL(a), greater<int>());
    int ans = n;
    REP(i, k) ans -= a[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
s,t = input(), input()
len_s = len(s)
len_t = len(t)

match = []
for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:
        for s_j, t_j in zip(s[i:i+len_t], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            temp = s[:i] + t + s[i + len_t:]
            match += [temp.replace("?", "a")]

print(min(match) if match != [] else "UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)cin >> arr[i];
    sort(arr, arr+n);
    double r = arr[0];
    for(int i = 1; i < n; i++){
       r = (r + arr[i])/2; 
    }
    cout << r << '\n';
}


Measured memory_bytes: 256
//2019.5.15 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-10
#define RG register
inline int read() {
    res s=0,ch=getchar(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e5+10;
namespace MAIN {
    int n,m;
    struct E{
        int next,to;
        E() {}
        E(res next,res to):next(next),to(to) {}
    }edge[N<<1];
    int head[N],cnt,du[N];
    inline void addedge(const res &u,const res &v){
        edge[++cnt]=E(head[u],v),head[u]=cnt,du[u]++;
        edge[++cnt]=E(head[v],u),head[v]=cnt,du[v]++;
    }
    bool vis[N];
    void dfs(res x){
        vis[x]=1;
        for(res i=head[x];~i;i=edge[i].next){
            res tox=edge[i].to;
            if(vis[tox])continue;
            dfs(tox);
        }
    }
    inline void MAIN(){
        n=read(),m=read();
        for(res i=1;i<=n;i++)head[i]=-1;
        for(res i=1;i<=m;i++){
            res u=read(),v=read();
            addedge(u,v);
        }
        for(res i=1;i<=n;i++)if(du[i]&1){puts("No");return;}
        res t=0,p=0,q=0;
        for(res i=1;i<=n;i++){
            if(du[i]>=6){puts("Yes");return;}
            if(du[i]>=4){
                t++;
                if(!p)p=i;
                else if(!q)q=i;
            }
        }
        if(t>2){puts("Yes");return;}
        if(t==2){
            vis[p]=1,dfs(q);
            for(res i=1;i<=n;i++)if(!vis[i]){puts("Yes");return;}
        }
        puts("No");
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("graph.in","r",stdin);
//    freopen("graph.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<set>
using namespace std;
int main()
{
    set<int> a, b;
    int n, m, c, d;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> c >> d;
        if(c == 1) a.insert(d);
        if(d == n) b.insert(c);
    }
    auto itr = a.begin();
    for(unsigned int i = 0; i < a.size(); i++){
        if(b.count(*itr) == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        ++itr;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 9600
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    XYH = [tuple(map(int, input().split())) for _ in range(N)]
    XYH = sorted(XYH, key=lambda x: x[2], reverse=True)

    H = -1
    for x in range(0, 101):
        for y in range(0, 101):
            for xi, yi, hi in XYH:
                abs_xy = abs(x - xi) + abs(y - yi)
                if H < 0 and hi > 0:
                    H = hi + abs_xy
                elif hi != max(H - abs_xy, 0):
                    H = -1
                    break
            else:
                if H > 0:
                    print(x, y, H)
                    exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstring>
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,b;
  cin>>N;
  long long counter=0;
  queue<long long>a;
  for(int i=0;i<9;i++){
  a.push(i+1);}
  for(int i=1;i<=N;i++){
  if(i==N){
  counter=a.front();
  cout<<counter<<endl;
  break;
  }
  else{
  b=a.front();
  a.pop();
  if(b%10!=0){
  a.push(10*b+b%10-1);}
  a.push(10*b+b%10);
  if(b%10!=9){
  a.push(10*b+b%10+1);}

  }}}


Measured memory_bytes: 1792
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

ll expo(ll a,ll b,ll m){
    if(b<0)return expo(expo(a,m-2,m),-b,m);
    ll res=1;
    while(b>0){
        if(b&1)res=mul(res,a,m);
        a=mul(a,a,m);
        b=b/2;
    }
    return res;
}

bool tr(ll a, ll b, ll c){
    if( a+b <=c )return false;
    if( b+c <=a )return false;
    if( a+c <=b)return false;
    return true;
}

int main()
{
    int n;cin>>n;
    ll a[n];bool vis[n];mem(vis,0);
    rep(i,0,n)cin>>a[i];

    sort(a,a+n);
    ll ans = 0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,j+1,n){
                if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] && tr(a[i], a[j], a[k]))
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    ll a;
    cin >> a;
    ll res=a + a*a + a*a*a;
    cout << res <<"\n";
}


Measured memory_bytes: 3620