akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main() {
    long H,W,N,i,j,k,a=0,*A;

    scanf("%ld %ld %ld",&H,&W,&N);
    A=(long *)malloc((H+1)*sizeof(long));
    for(i=1;i<=H;i++) {
        A[i]=0;
    }

    for(k=0;k<N;k++) {
        scanf("%ld %ld",&i,&j);
        if(i<j) continue;
        if(A[i]==0 || A[i]>j) A[i]=j;
    }

    for(i=1;i<=H;i++) {
        if(A[i]==0) continue;

        if(A[i]==i-a) {
            a++;
            continue;
        }

        if(A[i]<i-a) {
            k=1;
            break;
        }
    }

    printf("%ld\n",i-1);
    return 0;
}

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

using namespace std;

int main(void){
    int n, m, sum = 0;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int temp;
        cin >> temp;
        sum += temp;
    }
    if(sum <= n){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<int>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=200009;
vector<vector<int> > v(N);
int n,S[N],arr[N],id,siz[N];
void dfs(int no,int p)
{
    S[no]=id;
    id++;
    siz[no]=1;
    for(int i=0;i<sz(v[no]);i++)
    {
        int nw=v[no][i];
        if(nw==p)
            continue;
        dfs(nw,no);
        siz[no]+=siz[nw];
    }
}
int main()
{
    int q;
    cin>>n>>q;

    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    id=1;
    dfs(1,0);

    while(q--)
    {
        int val,node;
        cin>>node>>val;
        arr[S[node]]+=val;
        arr[S[node]+siz[node]]-=val;
    }
    for(int i=1;i<=n;i++)
    {
        arr[i]+=arr[i-1];
    }
    for(int i=1;i<=n;i++)
        cout<<arr[S[i]]<<" ";
}










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

int main() {
    int h, w;
    cin >> h >> w;
    string a[h];
    long long dp[h][w];
    for (int i=0; i<h; i++) {
        cin >> a[i];
        for (int j=0; j<w; j++)
            dp[i][j]=0;
    }

    dp[0][0]=1;
    for (int i=1; i<h; i++)
        if (a[i][0]=='.')
            dp[i][0]=dp[i-1][0];

    for (int i=1; i<w; i++)
        if (a[0][i]=='.')
            dp[0][i]=dp[0][i-1];

    for (int i=1; i<h; i++)
        for (int j=1; j<w; j++)
            if (a[i][j]=='.')
                dp[i][j]=(dp[i-1][j] + dp[i][j-1])%(1000000000 + 7);

    cout << dp[h-1][w-1];
}



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

int main() {
  long n, a, b, p=1000000007;
  cin >> n >> a >> b;
  
  long ans=1;
  rep (i, n/30) {
    ans *= 73741817;
    if(ans>=p) ans %= p;
  } 
  rep (i, n%30) {
    ans *= 2;
  }
  ans %= p;
  
  long N = max(a,b);
  vector<long> inv(N+1);
  inv[1] = 1;
  for (int i=2; i<=N; i++) {
    inv[i] = -((p/i)*inv[p%i])%p+p;
  }
  
  long d0=1, da=1, db=1;
  
  rep(i, a) {
    da *= (n-i);
    if(da >= p) da %= p;
    da *= inv[i+1];
    if(da >= p) da %= p;
  }
  rep(i, b) {
    db *= (n-i);
    if(db >= p) db %= p;
    db *= inv[i+1];
    if(db >= p) db %= p;
  }

  ans = (ans-(d0+da+db)%p+p)%p;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1792
require 'complex'
require 'prime'
n, m = gets.split.map(&:to_i)
ans = 1
(1..Math.sqrt(m)).each do |v|
    if m % v == 0 then
        u = m / v
        ans = v if n <= m / v && ans < v
        ans = u if n <= m / u && ans < u
    end
end
puts ans


Measured memory_bytes: 1916
n, m = map(int, raw_input().split())


def algorithm(k):
    result = 1
    division = 1
    num = n + k - 1
    num2 = 1
    for i in range(min(k, n - 1)):
        result *= num
        num -= 1
        division *= num2
        num2 += 1
    return result / division

if m == 1:
    print 1
else:
    divs = []
    while m != 0:
        flag = 0
        for i in range(2, int(m**0.5)+1):
            if m % i == 0:
                flag = 1
                divs.append(i)
                break
        if flag == 1:
            m = m / i
        else:
            divs.append(m)
            break
    divs.sort()
    divs_num = []
    num = 0
    first = divs[0]
    divs.append(0)
    for i in range(len(divs)):
        if divs[i] == first:
            num += 1
        else:
            divs_num.append(num)
            num = 1
            first = divs[i]

    divs_num = map(algorithm, divs_num)

    result = 1
    for i in divs_num:
        result *= i
    print result % (10**9+7)


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c;
  cin >>a>>b>>c;
  string ans ="No";
 if(a==b&&a!=c){
ans="Yes";
 }
   if(a==c&&a!=b){
ans="Yes";
 }
   if(c==b&&a!=c){
ans="Yes";
 }
  cout<<ans<<endl;
 
}

Measured memory_bytes: 256
# ABC149 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def isPrime(p):
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            return False
    return True

x=ni()

for i in range(x,10**6+1):
    if isPrime(i):
        print(i)
        exit()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define maxn 5005
#define mod 998244353
#define ll long long
using namespace std;

typedef pair<int, int> P;

int n, k;
int power[maxn];
double ans = 0;
vector<int> v;

int main()
{
    power[0] = 1;
    for (int i = 1; i <= 30; i++)
        power[i] = power[i - 1] * 2;
    cin >> n >> k;

    int q = 0;
    for (int i = 0;; i++)
    {
        if (n * power[i] >= k)
        {
            q = i;
            break;
        }
    }
    v.push_back(q);
    for (int i = n - 1; i >= 1; i--)
    {
        while (i * power[q] < k)
            q++;
        v.push_back(q);
    }
    for (int i = 0; i < v.size(); i++)
    {
        ans += pow(0.5, v[i]);
        //printf("v%d ", v[i]);
    }
    ans /= n;
    printf("%.20lf", ans);

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <algorithm>

int get_ndigits(long long int n)
{
  int n_digits = 1;
  while (true) {
    n /= 10;
    if (n > 0) n_digits++;
    else return n_digits; 
  }
  return n_digits;
}

int main()
{
  long long int N;
  int ans = 10000;
  std::cin >> N;
  int limit = std::sqrt(N);
  for (long long int a = 1; a <= limit; a++) {
    if ( N % a != 0 ) continue;
    long long int b = N / a;
    int m = std::max(get_ndigits(a), get_ndigits(b));
    if (m < ans) ans = m;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> x(5);
    int k;
    REP(i, 5) {
        cin >> x[i];
    }
    cin >> k;
    SORT(x);
    if (x[4] - x[0] <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


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

typedef long long ll;

int main() {

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

    ll k = 0, n = 0;
    cin >> k >> n;
    vector<int> v(n , 0);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }

    vector<ll> dist;
    ll prev = v[0];
    for(int i = 1; i < n; i++) {
        dist.push_back(v[i] - prev);
        prev = v[i];
    }
    // cout << dist.size() << endl;
    dist.push_back(k - v[n - 1] + v[0]);
    // cout << dist.size() << endl;

    ll mx = -1e9 + 5;
    ll sum = 0;
    for(int i = 0; i < n + 1; i++) {
        mx = max(mx, dist[i]);
        sum += dist[i];
    }   

    cout << sum - mx << endl;

    return 0;
}

Measured memory_bytes: 3188
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int apple = sc.nextInt();
      	int L     = sc.nextInt();
      	int min = 1000;
      	int cnt = 0;
      
      for(int i = 1;i <= apple;i++){
      	int nam = L + i -1;
      	min = Math.min(min,Math.abs(nam));
      	cnt += nam;
      }
 	
     if(cnt<0){
		System.out.print(cnt+min);
     }else{
     	System.out.print(cnt-min);
     }

    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;



int main(){

        int N;
        cin >> N;
        vector<ll> x(N), y(N);
        for(int i = 0; i < N; i++){
                cin >> x[i] >> y[i];
        }

        map<P,ll> mp;

        for(int i = 0; i < N; i++){
                for(int j = 0; j < N; j++){
                        if(i != j){
                                ll tmpx = x[i] - x[j];
                                ll tmpy = y[i] - y[j];
                                mp[make_pair(tmpx,tmpy)] += 1;
                        }
                }
        }

        ll max_val = 0;
        for(auto &i : mp){
                max_val = max(max_val, i.second);
        }

        ll ans = N - 1;

        ans = ans - max_val + 1;

        cout << ans << endl;
        return 0;







}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n,t[100005];
int x[100005],y[100005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d%d%d",&t[i],&x[i],&y[i]);
	}
	x[0]=y[0]=0;
	for(int i=1;i<=n;i++){
		if(((t[i]-t[i-1])-(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])))<0||((t[i]-t[i-1])-(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])))%2==1){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes");
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

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

    ll mx = 0;
    for (ll i = 1; i * i < 1e9; i++)
    {
        if (i * i <= N){ 
            mx = i * i;
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int x,y;
    cin>>x>>y;
    if((x==1||x==3||x==5||x==7||x==8||x==10)&&(y==3||y==5||y==7||y==8||y==10||y==12)){
    cout<<"Yes";
    }else if((x==4||x==6||x==9||x==11)&&(y==6||y==9||y==11)){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int C = 6;

int sl[] = {60, 80, 100, 120, 140, 160};
int wl[] = {2, 5, 10, 15, 20, 25};
int cost[] = {600, 800, 1000, 1200, 1400, 1600};

int main()
{
    int n;
    int x, y, h , w, c;
    while(cin >> n && n)
    {
        long long ans = 0;
        REP(n)
        {
            cin >> x >> y >> h >> w;
            c = 0;
            h = h + x + y;
            rep(j,C)if( h <= sl[j] && w <= wl[j]){ c = cost[j]; break;}

            ans += c;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
f = [False]*N
l = 0
r = N+1
for i in range(M):
    l += 1
    r -= 1
    while True:
        if N % 2 == 0:
            if r-l == N//2:
                r -= 1
                continue
        if f[min(r-l, N-(r-l))]:
            r -= 1
            continue
        break
            
    f[min(r-l, N-(r-l))] = True
    print(l, r)

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

int main()
{
  ll n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(),a.end());

  ll ai = a[n-1];
  ll aj = 0;
  auto f = [](ll n, ll x, ll y) {
    ll l = n/2;
    if (n%2 == 1) {
      if (min(abs(x-l), abs(x-l-1)) > min(abs(y-l), abs(y-l-1))) return y;
      else return x;
    } else {
      if (abs(x-l) > abs(y-l)) return y;
      else return x;
    }
  };
  rep(i, n) {
    aj = f(ai, aj, a[i]);
  }
  printf("%lld %lld\n", ai, aj);

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0) {
            printf(" %d", i);
        } else {
            int tmp_i = i;
            while (tmp_i) {
                if (tmp_i % 10 == 3) {
                    printf(" %d", i);
                    break;
                }
                tmp_i /= 10;
            }
        }
    }
    printf("\n");
}


Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    bool ans=true,ccheck=false;
    for(int i=0;i<s.size();i++){
        if(i==0){
            if(s[i]!='A'){
                ans=false;
                break;
            }
        }else if(i>=2 && i<=s.size()-2 && s[i]=='C'){
            if(ccheck){
                ans = false;
                break;
            }else{
                ccheck=true;
            }
        }else{
            if(isupper(s[i])){
                ans=false;
                break;
            }
        }
    }

    if(ans && ccheck)cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}


Measured memory_bytes: 3580
def main(n, a, b):
    target_list = []

    for i in range(1, n+1):
        nums = list(map(int, list(str(i))))
        total = sum(nums)
        if total >= a and total <= b:
            target_list.append(i)

    return sum(target_list)


if __name__ == "__main__":
    n, a, b = list(map(int, input().split()))
    print(main(n, a, b))


Measured memory_bytes: 43756
import java.util.Scanner;

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

        double r;
        r = stdIn.nextDouble();

        double a, b;
        a = r * r * Math.PI;
        b = r * 2 * Math.PI;

        System.out.printf("%.6f %.6f\n", a, b);

    }
}




Measured memory_bytes: 28264
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll k;
vector<ll> a;

ll f(ll x) {
    rep(i, k) x -= x % a[i];
    return x;
}

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

    cin >> k;
    a.resize(k);
    rep(i, k) cin >> a[i];

    ll mn, mx;
    ll ng = 0, ok = 1e15;
    while(ng + 1 < ok)
        (f(ng + ok >> 1) >= 2 ? ok : ng) = ng + ok >> 1;
    mn = ok;
    ok = 0;
    ng = 1e15;
    while(ok + 1 < ng)
        (f(ok + ng >> 1) <= 2 ? ok : ng) = ok + ng >> 1;
    mx = ok;

    if(mx < mn)
        cout << -1 << endl;
    else
        cout << mn << " " << mx << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    // p_sum: 1, 3,  7, 15, ...
    // b_sum: 1, 5, 13, 29, ...
    // 1: BPPPB
    // 2: BBPPPBPBPPPBB
    // 3: BBBPPPBPBPPPBBPBBPPPBPBPPPBBB

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();

        long p = 1;
        long b = 1;
        for (int i = 1; i <= n; i++) {
            p = p * 2 + 1;
            b = b * 2 + 3;
        }

        System.out.println(solve(n, b, p, x));
    }

    long solve(int n, long b, long p, long x) {
//        System.err.println(n + " " + b + " " + p + " " + x);
        if (x <= 0) return 0;
        if (n == 0) return 1;
        if ((b + 1) / 2 > x) {
            return solve(n - 1, (b + 1) / 2 - 2, (p + 1) / 2 - 1, x - 1);
        } else if ((b + 1) / 2 == x) {
            return solve(n - 1, (b + 1) / 2 - 2, (p + 1) / 2 - 1, x - 1) + 1;
        } else {
            return solve(n - 1, (b + 1) / 2 - 2, (p + 1) / 2 - 1, x - (b + 1) / 2) + (p + 1) / 2;
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 23380
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define N 200
int A[N],n=0;
void Push(int data);
int Pop();

int main(){
    int data,data_a,tmp;

    while((data=getchar())!='\n'){
        if(isdigit(data)!=0){
            ungetc(data,stdin);
            scanf("%d",&data_a);
            Push(data_a);
        }
        else{
            if(data=='+'){
                Push(Pop()+Pop());
            }
            if(data=='-'){
                tmp = Pop();
                Push(Pop()-tmp);
            }
            if(data == '*'){
                Push(Pop()*Pop());
            }
            if(data == '/'){
                tmp = Pop();
                Push(Pop()/tmp);
            }
        }
    }
    printf("%d\n",A[0]);   
    return 0; 
}

void Push(int a){
    int i;
    A[n] = a;
    n++;
}
int Pop(){
    int value;
    value = A[n-1];
    n--;
    return value;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int lr[n][2];
  
  for(int i = 0; i < n; i++)
    cin >> lr[i][0] >> lr[i][1];
  
  int tmp;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    tmp = lr[i][1] - lr[i][0] + 1;
    ans += tmp;
  }
  
  cout << ans;
}

Measured memory_bytes: 3584
n = gets.to_i

r = Array.new(2 ** n)
(2 ** n).times do |i|
  r[i] = gets.to_i
end

(n - 1).downto(0) do |i|
  s = Array.new(2 ** i)
  (2 ** i).times do |j|
    diff = (r[2 * j] - r[2 * j + 1]).abs
    s[j] = (diff == 0) ? r[2 * j] : diff
  end
  r = s
end

puts r[0]


Measured memory_bytes: 6140
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool f = true;
  for(ll i=0; i<S.size()/2; i++) {
    //std::cout << S[i] << " " << S[S.size()-(i+1)] << std::endl;
    f = f and S[i]==S[S.size()-(i+1)];
  }
  //std::cout << "!" << std::endl;
  for(ll i=0; i<(S.size()-i)/2; i++) {
    f = f and S[i]==S[S.size()/2-(i+1)];
    //std::cout << S[i] << " " << S[S.size()/2-(i+1)] << std::endl;
  }

  if(f)
    std::cout << YES << std::endl;
  else
    std::cout << NO << std::endl;
      
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#include<set>
#define ll long long
#define inf 0x7fffffff;
#define maxn 600005
using namespace std;
set<ll>s;
ll a[maxn],n,k,cnt[maxn],vis[maxn],sum[maxn],num,b[maxn],ans;
vector<int> pp;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll read()
{
    int l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
} 
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(!sum[a[i]]) pp.push_back(a[i]);
		sum[a[i]]++;
		cnt[i]=a[i];
	}
	for(int i=0;i<pp.size();i++)
	{
		ans+=sum[pp[i]]*(sum[pp[i]]-1)/2;
	} 
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",ans-sum[cnt[i]]+1);
	}
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n-k) {
        int l = i;
        int r = l + k;
        string ans = "No";
        if (a[l]<a[r]) ans = "Yes";
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
 
using namespace std;
   
#define debug cout<<"???"<<endl
#define sync std::ios::sync_with_stdio(false)
#define ll long long
#define pb push_back
#define mp make_pair
#define maxn 100005
#define INF 0x3f3f3f3f
#define frein freopen("input.txt", "r", stdin)
#define freout freopen("output.txt", "w", stdout)
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%lld", (x))
int main()
{
     //sync 
	 //frein
     //freout
     int r;
     sc(r);
     if (r >=2800) printf("AGC\n");
     else if (r >=1200) printf("ARC\n");
     else printf("ABC\n");
     return 0;
}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int h,w;
string s;
char table[23][23];
const int dxy[5] = {0,1,0,-1,0};
int dist[550][550];

signed main(){
    cin >> h >> w;
    REP(i,h){
        cin >> s;
        REP(j,w) table[i+1][j+1] = s[j];
    }
    REP(xi,h+1) REP(yi,w+1){
        int indi = xi * (w+1) + yi;
        REP(xj, h+1) REP(yj, w+1){
            int indj = xj * (w+1) + yj;
            dist[indi][indj] = (table[xi][yi] == '.' && table[xj][yj] == '.' && abs(xi-xj) + abs(yi-yj) <= 1);
            if (!dist[indi][indj] && (xi != xj || yi != yj)) dist[indi][indj] = INT32_MAX;
        }
    }
    int indmax = (h+1) * (w+1);
    REP(k,indmax) REP(i, indmax) REP(j, indmax) if (dist[i][j] > dist[i][k] + dist[k][j])
        dist[i][j] = dist[i][k] + dist[k][j];
    
    int ans = 0;
    REP(i, indmax) REP(j,indmax) {
        if (dist[i][j] == INT32_MAX) continue;
        ans = max(ans, dist[i][j]);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 2176
S = input()

# if len(S) % 2 == 0:
itelist = []
slen = int(len(S))
for j in range(int(slen/2),slen):
    itelist.append(j)
revitelist = []
for i in (reversed(itelist)):
    revitelist.append(i)
count = 0
for i in range(0,int(slen/2)):
    if S[i] == S[revitelist[i]]:
        pass
    elif S[i] != S[revitelist[i]]:
        # print("count:" + S[i] + ":" + S[itelist[i]])
        count += 1
print(count)




Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0, cnt = 0;
    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }
    vector<int> b(n, 0);
    for(int i = n-1; i >= 0; i--){
        if(b[i] > a[i]){
            cout << -1 << endl;
            return 0;
        }
        if(i > 0) b[i-1] = max(0, a[i] - 1);
        if(a[i] == b[i]) continue;
        ans += a[i];
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<map>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	ll s = 0;
	map<ll, ll>res;
	res[0]++;
	ll ans = 0;
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		s += a;
		ans += res[s];
		res[s]++;
	}
	cout << ans << endl;
}

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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<lli, lli>
#define ps pair<double, string>
#define pib pair<pi, bool>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 100002
#define MAXL 100002
#define mod 1000000007

int n, m;
vector<int> adj[MAXN];
bool visited[MAXN];
int dist[MAXN];
int parent[MAXN];

void dijkstra(int s)
{
  dist[s] = 0;
  priority_queue<pi, vector<pi>, greater<pi>> q;
  q.push(pi(dist[s], s));
  while (1)
  {
    int davez = -1;
    while (!q.empty())
    {
      int atual = q.top().second;
      q.pop();
      if (!visited[atual])
      {
        davez = atual;
        break;
      }
    }
    if (davez == -1)
      break;
    visited[davez] = true;
    for (int i = 0; i < adj[davez].size(); i++)
    {
      if (dist[adj[davez][i]] > dist[davez] + 1)
      {
        parent[adj[davez][i]] = davez;
        dist[adj[davez][i]] = dist[davez] + 1;
        q.push(pi(dist[adj[davez][i]], adj[davez][i]));
      }
    }
  }
}
signed main()
{
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  for (int i = 1; i <= n; i++)
    dist[i] = INT_MAX, parent[i] = -1;
  dijkstra(1);
  bool can = true;
  for (int i = 2; i <= n; i++)
    if (dist[i] == INT_MAX)
      can = false;
  if (!can)
    cout << "No\n";
  else
  {
    cout << "Yes\n";
    for (int i = 2; i <= n; i++)
      cout << parent[i] << endl;
  }
  return 0;
}

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

int N;
vector<string> V; // stringを入れる
set<char> S; // 使われている文字の集合
map<char, int> M; // 文字を番号付けする
int L; // 使われている文字の数
vector<int> K; // 係数
vector<bool> istop; // 先頭文字ならtrue。0を代入しない。
vector<pair<int, int> > X, Y; // 半分ずつ入れる。

void init() {
  V.clear();
  S.clear();
  M.clear();
  L = 0;
  K.clear();
  istop.clear();
  X.clear();
  Y.clear();
}

void keisu(string str, bool b) {
  int mp = ( b ? 1 : -1 );
  int tens = 1;
  // // cerr << str << endl;
  for (int i=(int)str.size()-1; i>=0; i--) {
    K[M[str[i]]] += tens * mp;
    // cerr << "K[" << M[str[i]] << "] = " << K[M[str[i]]] << endl;
    tens *= 10;
  }
}

void ipt() {
  for (auto i=0; i<N; i++) {
    string str;
    cin >> str;
    V.push_back(str);
  }
  for (auto i=0; i<N; i++) {
    for (unsigned int j=0; j<V[i].size(); j++) {
      S.insert(V[i][j]);
    }
  }
  L = S.size();
  K = vector<int>(L, 0);
  istop = vector<bool>(L, false);
  int k = 0;
  for (auto itt=S.begin(); itt!=S.end(); itt++) {
    M[*itt] = k++;
  }
  for (auto i=0; i<N; i++) {
    if (V[i].size() > 1) {
      istop[M[V[i][0]]] = true;
      // cerr << "top " << V[i][0] << endl;
    }
  }
  for (auto i=0; i<N; i++) {
    keisu(V[i], (i != N-1));
  }
}

void dfs(int start, int end, int used, int temp, bool kiroku) {
  if (start == end) {
    pair<int, int> P = make_pair(temp, used);
    if (kiroku) {
      X.push_back(P);
      // cerr << "X temp = " << temp << ", used = " << used << endl;
    } else {
      Y.push_back(P);
      // cerr << "Y temp = " << temp << ", used = " << used << endl;
    }
  } else {
    for (auto i=0; i<10; i++) {
      if ((((used >> i) & 1) != 1) && (i != 0 || !istop[start])) {
	dfs(start+1, end, (used | (1 << i)), temp + K[start]*i, kiroku);
      }
    }
  }
}

int solve() {
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  reverse(Y.begin(), Y.end());
  unsigned int xi = 0;
  unsigned int yi = 0;
  int ans = 0;
  while(xi < X.size() && yi < Y.size()) {
    int xv = X[xi].first;
    int yv = Y[yi].first;
    int sum = xv + yv;
    if (sum > 0) {
      yi++;
    } else if (sum < 0) {
      xi++;
    } else {
      // // cerr << "xi = " << xi << endl;
      for (unsigned int i=xi; i < X.size() && X[i].first == xv; i++) {
	for (unsigned int j=yi; j < Y.size() && Y[j].first == yv; j++) {
	  if ((X[i].second & Y[j].second) == 0) { 
	    ans++;
	    // cerr << X[i].second << " " << Y[j].second << endl;
	  }
	}
      }
      while (X[xi].first == xv) xi++;
      while (Y[yi].first == yv) yi++;
    }
  }
  return ans;
}

int main() {
  // cerr << (3 & 1) << endl;
  while (cin >> N && N) {
    init();
    ipt();
    dfs(0, L/2, 0, 0, true);
    dfs(L/2, L, 0, 0, false);
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DLine {
public:

    vector<int> graph[3000];

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, x, y; cin >> n >> x >> y;

      rep(i, n-1) {
        graph[i].push_back(i+1);
        graph[i+1].push_back(i);
      }
      x--; y--;
      graph[x].push_back(y);
      graph[y].push_back(x);

      vector<vector<int>> dp(n, vector<int>(n, INT_MAX/2));
      rep(i, n) {
        dp[i][i] = 0;
        deque<P> que;
        que.emplace_back(0, i);
        while(!que.empty()) {
          auto p = que.front(); que.pop_front();
          if (p.first > dp[i][p.second]) continue;
          for(auto e: graph[p.second]) {
            if (dp[i][e] > p.first+1) {
              dp[i][e] = p.first+1;
              que.emplace_back(dp[i][e], e);
            }
          }
        }
      }
      vector<int> ans(n);
      rep(i, n) {
        for(int j=i+1; j<n; j++) {
          ans[dp[i][j]]++;
        }
      }
      for(int i=1; i<n; i++){
        cout << ans[i] << '\n';
      }


    }
};

signed main() {
  DLine solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 16128
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, A = mi()
print(N-A+1)

Measured memory_bytes: 3064
#if 0
date

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
int a[maxn];

inline bool check(int n, int m) {
	return 1 <= m and m <= n / 2;
}

int main() {
	int n = read, max = 0;

	for(int i = 1; i <= n; i ++)
		max = std::max(max, a[i] = read);

	int tot = 0;
	for(int i = 1; i <= n; i ++)
		if(a[i] == max - 1)
			++ tot;
		else if(a[i] < max - 1)
			return puts("No"), 0;

	if(tot == 0 and max == n - 1)
		return puts("Yes"), 0;

	if(check(n - tot, max - tot)) puts("Yes");
	else puts("No");
}


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

int main(void){
  int card[4][13] = {0};
  int N;
  cin >> N;
  char k;
  int number;
  for(int i = 0; i < N; i++ ){
    cin >> k >> number;
    if( k == 'S') card[0][number-1] = 1;
    if( k == 'H') card[1][number-1] = 1;
    if( k == 'C') card[2][number-1] = 1;
    if( k == 'D') card[3][number-1] = 1;
  }
  for(int j = 0; j < 4; j++ ){
    for(int k = 0; k < 13; k++ ){
      if( card[j][k] == 0 ){
        if( j == 0 ) cout << "S" << " " << (k+1) << endl;
        if( j == 1 ) cout << "H" << " " << (k+1) << endl;
        if( j == 2 ) cout << "C" << " " << (k+1) << endl;
        if( j == 3 ) cout << "D" << " " << (k+1) << endl;
      }
    }
  }


  return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;



public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] array = new long[N], sorted = new long[N];
			for(int i = 0; i < N; i++){ 
				array[i] = sc.nextLong();
				sorted[i] = array[i];
			}
			
			Arrays.sort(sorted);
			
			final long fst = sorted[N / 2 - 1];
			final long snd = sorted[N / 2 - 0];
			//System.out.println(fst + " " + snd);
			
			for(int i = 0; i < N; i++){
				if(array[i] <= fst){
					System.out.println(snd);
				}else if(array[i] >= snd){
					System.out.println(fst);
				}
			}
			
			/*
			try(final PrintWriter pw = new PrintWriter(System.out)){
				
			}
			//*/
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 94480
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define REP(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define rrep(i, m)		for(ll i = m; i >= 0; i--)
#define rerep(i, b, e)	for(ll i = b; i >= e; i--)

#define MOD 1000000007
#define COMBINATION 2010

#ifdef MOD

class mint
{
public:
	mint() : v(0) {}
	mint(ll x) : v((x + MOD) % MOD) {}

	mint operator =(ll r) { this->v = (r + MOD) % MOD; return *this; }

	ll v = 0;
};

ostream &operator<<(ostream &os, mint m) {
	return os << m.v;
}

#endif

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

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b) cout << True.c_str();
	else cout << False.c_str();
}

#ifdef COMBINATION
ll c[COMBINATION][COMBINATION];
#endif

void init()
{
#ifdef COMBINATION
	c[0][0] = 1;
	for (int i = 1; i < COMBINATION; i++)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; j++)
		{
			mint mc = c[i - 1][j - 1] + c[i - 1][j];
			c[i][j] = mc.v;
		}
	}
#endif
}

int main()
{
	ll k, n;
	in(n);
	in(k);

	init();

	for (int i = 1; i <= k; i++)
	{
		mint ans = c[n - k + 1][i] * c[k - 1][i - 1];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 30336
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int N;

int mod(int i){
  if(i < 0) return N + i;
  else if(0 <= i && i < N) return i;
  else  return i % N;
}

int main(){
  cin >> N;
  ll a[N], b[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  for(int i = 0; i < N; i++) cin >> b[i];

  //b > a + cをみたすbのインデックスを入れるキュー
  queue<int> que;
  for(int i = 0; i < N; i++){
    if(b[i] > b[mod(i-1)] + b[mod(i+1)]){
      //cout << i << endl;
      que.push(i);
    }
  }


  ll cnt = 0;
  while(!que.empty()){
    int i = que.front();
    que.pop();

    //cout << i << endl;

    ll x = b[mod(i-1)];
    ll y = b[mod(i)];
    ll z = b[mod(i+1)];
    ll m = max(x, z);

    if(y == a[i]){
      //何もしない
      continue;
    }
    else if(y < a[i]){
      cout << -1 << endl;
      return 0;
    }
    else if(m <= a[i] && a[i] < y){
      //適度に引く
      if((y - a[i]) % (x + z) != 0){
        cout << -1 << endl;
        return 0;
      } else {
        cnt += (y - a[i]) / (x + z);
        y = a[i];
        b[i] = y;
      }
    }
    else if(a[i] < m){
      //できるだけ引く
      cnt += ((y - m) / (x + z) + 1);
      y -= ((y - m) / (x + z) + 1) * (x + z);
      b[i] = y;
      if(b[mod(i-1)] > b[mod(i-2)] + b[mod(i)]) que.push(mod(i-1));
      if(b[mod(i+1)] > b[mod(i)] + b[mod(i+2)]) que.push(mod(i+1));
    }

    /*for(int i = 0; i < N; i++){
      cout << b[i] << " ";
    }
    cout << endl;*/
  }

  //cout << "hoge" << endl;
  for(int i = 0; i < N; i++){
    if(a[i] != b[i]){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;

public class Main
{
	public static int Search(String S)
	{
		int result = 0;
		for(int i = 0; i < S.length() - 1; i++)
			if(S.charAt(i) == S.charAt(i+1))
				result++;
		return result;				

	}

	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		in.nextLine();
		String S = in.nextLine();
		
		System.out.println(Math.min((Search(S) + 2 * K), (N - 1)));

	}

}

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

#define NUM_LIMIT 1001
#define ARR_LIMIT 200

void SumString(char number[][NUM_LIMIT], int *result, int size);

int main(void) {
	int idx;
	char input[NUM_LIMIT];
	char arr[ARR_LIMIT][NUM_LIMIT];
	int* result;
	int size;

	for (size = 0; size < ARR_LIMIT; size++) {
		scanf("%s", input);
		if (*input == '0') {
			break;
		}

		int i = 0;
		do {
			arr[size][i] = *(input + i);
			i++;
		} while (*(input + i) != '\0');
	}

	result = (int*)malloc(sizeof(int) * size);
	SumString(arr, result, size);

	for (idx = 0; idx < size; idx++) {
		printf("%d\n", *(result + idx));
	}

	free(result);
}

void SumString(char number[][NUM_LIMIT], int *result, int size) {
	int idx;
	for (idx = 0; idx < size; idx++) {
		char* tmpC = number[idx];
		int tmpSum = 0;
		do {
			tmpSum += (int)(*tmpC - 48);
		} while (*++tmpC != '\0');
		*result++ = tmpSum;
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  for (int i = 1; i < N; ++i)
    A[i] += A[i - 1];
  long long ans = 1000000000000000001;
  for (int i = 0; i < N - 1; ++i)
    ans = min(abs(A[i] - (A[N - 1] - A[i])), ans);
  cout << ans << endl;
}


Measured memory_bytes: 1792
N,M,K = list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))

a,b=[0],[0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])

ans,j=0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j] > K-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)

Measured memory_bytes: 47540
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cout << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi pair     <int,int>
#define vss vector  <string>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define PI  3.141592654
#define OO (ll)1e18
#define mod(x,m) (x%m + m )%m
using namespace std;
void ONLINE__JUDGE();

pii swapii( pii pr ){ return { pr.S , pr.F }; }
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 2e7 + 9;

ll x; vii vec , res;

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x; vec.resize(x);
    for ( ll& i : vec ) cin >> i , i *= 2;

    ll cnt = 0;
    for ( int i = 0; i < x; ++i )
        cnt += vec[i] * ( i%2 == 0 ? 1 : -1 );
    res.pb( cnt/2 );

    for ( int i = 0; i < x-1; ++i )
        res.pb( vec[i]-res[i] );

    for ( ll i : res ) cout << i <<" ";
    return 0;
}


void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}



Measured memory_bytes: 3060