akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              (double)3.14159265358979323844
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=min(k,a);
    if (k>a+b){
    	ans-=(k-a-b);
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x2000 = sc.nextInt();
    int[] x = new int[10];
    System.out.println(r * x2000 -D);
    for (int i=1; i<10; i++) {
      x[0] = r * x2000 - D;
      x[i] = r * x[i-1] -D;
      System.out.println(x[i]);
    }
  }
}

Measured memory_bytes: 20820
/*WA70;
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n, s, x[100010];
ll p[100010];
ll ans,l,r;
int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>s;
	l=1,r=n;
    for (int i=1;i<=n;i++)cin>>x[i]>>p[i];
    t=(p[1]>=p[n])?x[n]:x[1];
    while(1){
        if(s<x[l]||s>x[r]) break;
        if (p[l]>=p[r]) p[l] += p[r], --r, ans += abs(x[l] - t), t = x[l];
        else p[r] += p[l], ++l, ans += abs(x[r] - t), t = x[r];
    }
    ans += max(s-t,t-s);
	cout<<ans;
	return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,s;
ll seq[100010],cnt[100010];
int main(){
	cin>>n>>s;
	for(int i = 1;i <= n; ++ i) cin>>seq[i]>>cnt[i];
	int l = 1,r = n;
	long long ans = 0;
	while(seq[l] <= s && seq[r] > s){
		if(cnt[l] >= cnt[r]){
			ans += seq[r] - seq[l];
			while(cnt[l] >= cnt[r] && seq[r] > s){
				cnt[l] += cnt[r];
				r --;
			}
		}
		else{
			ans += seq[r] - seq[l];
			while(cnt[r] > cnt[l] && seq[l] <= s){
				cnt[r] += cnt[l];
				l ++;
			}
		}
	}
	if(seq[l] <= s) ans += s - seq[l];
	else ans += seq[r] - s;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=4e5+5;
ll i,j;

/*


*/

void solve(){
    in4(a,b,c,d);
    vi ans;
    ans.pb(a*c);
    ans.pb(a*d);
    ans.pb(b*d);
    ans.pb(b*c);
    sort(call(ans));
    ce(ans.back());
}

int32_t main(){
    // jaldi
    ll t; 
    // cin>>t;
    t=1;     
    while(t--){
        solve();
    }
}

/*


*/



Measured memory_bytes: 3628
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut ans = 1;
    for i in 1..m {
        if m % i == 0 && n * i <= m {
            ans = std::cmp::max(ans, i);
        }
        let v = m / i;
        if m % v == 0 && n * v <= m {
            ans = std::cmp::max(ans, v);
        }
        if i * i > m {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int H, W;
char a[510][510];
char red[510][510];
char blue[510][510];

signed main()
{
    cin >> H >> W;

    REP(i,H) REP(j,W) {
        red[i][j] = '.';
        blue[i][j] = '.';
    }
    REP(i,H) {
        red[i][0] = blue[i][W-1] = '#';
    }
    REP(i,H) {
        for (int j=1; j<W-1; j++) {
            if (i % 2 == 0) red[i][j] = '#';
            else blue[i][j] = '#';
        }
    }

    REP(i,H) REP(j,W) {
        cin >> a[i][j];
        if (a[i][j] == '#') {
            red[i][j] = blue[i][j] = '#';
        }
    }

    REP(i,H) {
        REP(j,W) {
            cout << red[i][j];
        }
        cout << endl;
    }
    cout << endl;
    REP(i,H) {
        REP(j,W) {
            cout << blue[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
a.sort()
dp = [[0] * (X + 1) for _ in range(N + 1)]
for j in range(X + 1): dp[0][j] = j
for i in range(N):
  for j in range(X + 1):
    dp[i + 1][j] = dp[i][j % a[i]] + dp[i][j] * i
    dp[i + 1][j] %= mod
print(dp[-1][X])

Measured memory_bytes: 192024
h,w = map(int, input().split())
l = [list(list(input())) for i in range(h)]
W = []
for j in range(w):
    for k in range(h-1):
        if l[k][j] == l[k+1][j] == '.':
            continue
        else:
            break
    else:
        W.append(j)
W = sorted(W, reverse=True)
#print(W) #後で消す列

H = []
for m in range(h):
    if set(l[m]) == {'.'}:
        H.append(m)
H = sorted(H, reverse=True)
#print(H)

if l == [['#']]:
    print('#')
else:
    for p in range(len(W)):
        for q in range(h):
            del l[q][W[p]]
    #print(l)
    
    for r in H:
        del l[r]
    #print(l)
    
    for s in l:
        print(''.join(s))


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

ll num = 1000000000;

int main(void)
{
  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> cs(n);
  vector<vector<ll>> ass(n, vector<ll>(m));
  rep(i, n) {
    cin >> cs[i];
    rep(j, m) {
      cin >> ass[i][j];
    }
  }

  ll ans = num;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<20> s(tmp);
    // ビット列を出力
    ll sum = 0;
    vector<ll> rikais(m);
    rep(i, n) {
      if (s.test(i)) {
        sum += cs[i];
        rep(j, m) {
          rikais[j] += ass[i][j];
        }
      }
    }
    bool ok = true;
    rep(i, m) {
      if (rikais[i] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, sum);
    }
  }

  if (ans == num) ans = -1;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a * b % 2 == 1 ? "Yes" : "No") << endl;
}


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

Measured memory_bytes: 12496
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      int n = sc.nextInt();
      int d = sc.nextInt();
      int p = d * 2 + 1;
      if(n % p == 0)
        out.println(n / p);
      else
        out.println(n / p + 1);
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21076
K=int(input())

def NS(N):
  NS=0
  while(N>0):
    NS+=N%10
    N//=10
  return NS

answer,diff=0,1
for i in range(K):
  answer+=diff
  print(answer)
  
  if diff<(answer+diff)/NS(answer+diff):
    diff*=10

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    char ch, f, s;
    bool cup[3];

    cup[0] = true;
    cup[1] = cup[2] = false;
    while (cin >> f >> ch >> s) {
        swap(cup[f - 'A'], cup[s - 'A']);
    }
    for (int i = 0; i < 3; i++)
        if (cup[i])
            cout << char(i + 'A') << endl;

    return 0;
}

Measured memory_bytes: 1132
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    if(a > b) 
		    {
		    	System.out.println("a > b");
		    }
		    else if(a == b)
		    {
		    	System.out.println("a == b");
		    }
		    else 
		    {
		    	System.out.println("a < b");
		    }
        	scanner.close();}
		  }



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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    int sx, sy;
    cin >> sx >> sy;
    --sx; --sy;
    int gx, gy;
    cin >> gx >> gy;
    --gx; --gy;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    vector<vector<int>> d(h, vector<int> (w, (int) (1e6)));
    deque<pair<int, int>> q;
    q.push_front({sx, sy});
    d[sx][sy] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int dist = d[p.first][p.second];
        for (int dx = -2; dx <= 2; ++dx) {
            for (int dy = -2; dy <= 2; ++dy) {
                int nx = p.first + dx;
                int ny = p.second + dy;
                if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#') continue;
                if (abs(dx) + abs(dy) == 1) {
                    if (d[nx][ny] > dist) {
                        d[nx][ny] = dist;
                        q.push_front({nx, ny});
                    }
                } else {
                    if (d[nx][ny] > dist + 1) {
                        d[nx][ny] = dist + 1;
                        q.push_back({nx, ny});
                    }
                }
            }
        }
    }
    int ans = d[gx][gy];
    cout << (ans == (int) (1e6) ? -1 : ans) << '\n';
    return 0;
}

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

using namespace std;

typedef long long int64;

int main()
{
  int N, A[100000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64 ret = 0;
  int small = 1;

  for(int i = 0; i < N; i++) {
    int get = max(0, (A[i] - 1) / small);
    ret += get;
    if(i == 0 || small == A[i]) ++small;
    A[i] -= get * small;
  }
  cout << ret << endl;
}


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

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

    int cnt = 1;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] != s[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	string str;
	cin >> str;
	
	vector<bool> dp1(10),dp2(100),dp3(1000);
	for(int i=0;i<n;i++){
		int ch=(int)(str[i]-'0');
		for(int j=0;j<100;j++){
			if(!dp2[j]) continue;
			dp3[100*ch+j]=true;
		}
		for(int j=0;j<10;j++){
			if(!dp1[j]) continue;
			dp2[10*ch+j]=true;
		}
		dp1[ch]=true;
	}
	int res=0;
	for(int i=0;i<1000;i++){
		if(dp3[i]) res++;
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int wf[20][20];
	int n,m,a,b,c,d;
	cin >> n >> m;
	
	rep(i,n)rep(j,n)wf[i][j]=(1<<21);
	
	rep(i,m){
		scanf("%d,%d,%d,%d\n",&a,&b,&c,&d);
		a--;b--;
		wf[a][b] = c;
		wf[b][a] = d;
	}
	scanf("%d,%d,%d,%d\n",&a,&b,&c,&d);
	a--;b--;
	
	rep(k,n)rep(i,n)rep(j,n)wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);
	
	cout << c-d-wf[a][b]-wf[b][a] << endl;

}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

bool cal(int n) {
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if ( (n % i) == 0 ) {
			cnt++;
		}
	}
	if (cnt == 8) {
		return true;
	}
	return false;
}

void solve() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> asd(N + 2, vector<int>(N + 2, 0));

	for (int i = 0; i < M; ++i) {
		int L, R;
		cin >> L >> R;
		asd[L][R]++;
	}
	
	for (int i = 0; i < N + 2 -1; ++i) {
		for (int j = 0; j < N + 2; ++j) {
			asd[i + 1][j] += asd[i][j];
		}
	}

	for (int i = 0; i < N + 2 - 1; ++i) {
		for (int j = 0; j < N + 2; ++j) {
			asd[j][i+1] += asd[j][i];
		}
	}

	for (int i = 0; i < Q; ++i) {
		int L, R;
		cin >> L >> R;
		int res = asd[R][R] - asd[R][L - 1] - asd[L - 1][R] + asd[L - 1][L - 1];
		cout << res << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1920
// code.begin();
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back 
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define my_time ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define endl "\n"
#define MOD 1000000007
const long long int INF=1e18;
#define mod 1000000007
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
//find_by_order(x)
//order_of_key(x)  


int power(int x,unsigned int y)
{
    int res=1;
    
    while(y>0)
    {
        // if y is odd multiply with result
        if(y&1)
        res=res*x;
        
        y=y>>1; // y=y/2;
        x=x*x;
        
    }
    return res;
}

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

ll  max3(ll  a, ll  b, ll c)
{
    return max(c, max(a, b));
}
int min3(int a, int  b, int  c)
{
    return min(a, min(b, c));
}

int  powermod(int  x, int  y, int p )
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int logg(int  a)
{
    int  x = 0;
    while (a > 1)
    {
        x++;
        a /= 2;
    }
    return x;
}


int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}
int n,m;  char arr[1001][1001];
ll dp[1003][1003];


int solve(int i,int j)
{
    
    if(i==n-1 && j==m-1)
    {
        return 1;
    }
    if(i>=n || j>=m)
    return 0;
    
    if(dp[i][j]!=0)
    {
        return dp[i][j];
    }
    
    
    int r=0;int d=0;
    if(i<n && arr[i+1][j]=='.')
    {
      dp[i+1][j]=solve(i+1,j)%mod;
    }
    
    if(j<m && arr[i][j+1]=='.')
    {
    dp[i][j+1]=solve(i,j+1)%mod;
    }
    
    return dp[i][j]=(dp[i+1][j]+dp[i][j+1])%mod;
    
    
    
}



int  main(){
	my_time;

int t;
t=1;
//cin>>t;int test=0;
while(t--)
{
   
  cin>>n>>m;
  

  
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          cin>>arr[i][j];
      }
  }
  memset(dp,0,sizeof dp);
 // cout<<(solve(0,0))%mod;
  
  dp[0][0]=1;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          if(arr[i][j]=='#')
          {
              continue;
          }
          if(i-1>=0){
              dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
          }
          if(j-1>=0)
          {
              dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
              }
      }
  }
  
  cout<<dp[n-1][m-1]<<endl;
  
  
  
}
    return 0;
}


//code.end();





Measured memory_bytes: 12392
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using i_i = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const ll mod = 1000000007LL;


int main() {
	ll cur, k;

	int count = 1;
	cur = 7;
	cin >> k;
	vector<bool> used(k, false);

	cur = cur % k;

	while(true) {
		if (cur == 0) {
			cout << count << endl;
			return 0;
		}
		if (used[cur]) {
			cout << -1 << endl;
			return 0;
		}
		used[cur] = true;

		cur = cur * 10 + 7;
		cur = cur % k;
		count++;
	}



	return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int a,b;
scanf("%d %d %d",&n,&a,&b);
for(int i=a;i<=b;i++){
    if(i%n==0){
        cout<<"OK";
        return 0;
    }
}
printf("NG");

}


Measured memory_bytes: 3748
//Author : Gaara

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define endl "\n"
#define fo(i,n) for(ll i=0;i<n;i++)
#define ro(i,n) for(ll j=n-1;i>=0;i--)
#define vll vector<long long>
#define mod 1000000007

int main(){
    int t=1;
    //cin>>t;
    while(t--){
	  ll n; cin>>n;
      ll a[n];
      fo(i,n) cin>>a[i];
      ll sum[n];
      sum[n-1] = a[n-1];
      for(int i=n-2;i>=0;i--){
        sum[i] = (sum[i+1] + a[i])%mod;
      }
      ll ans = 0;
      for(int i=0;i<n-1;i++){
        ans+= (a[i]*sum[i+1])%mod;
        ans %= mod;
      }
      cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6748
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll fact[10*MAX];
ll a,b,h,w;
int main(){FAST;
fact[0]=1;
for(ll i=1;i<=1e6;i++){
	fact[i]=fact[i-1]*i;
	fact[i]%=MOD;
}
cin>>h>>w>>a>>b;
ll del = 0;
for(ll i=1;i<=b;i++){
	ll r = h-a;
	ll c = i;
	ll tot = r+c-2;
	ll tott = a+(w-i+1)-2;
	// totCr-1
	ll ways=(fact[tot]*((minv(fact[c-1],MOD)*minv(fact[r-1],MOD))%MOD))%MOD;
	ways*=(fact[tott]*((minv(fact[a-1],MOD)*minv(fact[w-i],MOD))%MOD))%MOD;
	ways%=MOD;
	del+=ways;
	del%=MOD;
}
ll ans = (fact[h+w-2]*((minv(fact[h-1],MOD)*minv(fact[w-1],MOD))%MOD))%MOD;
ans+=MOD-del;
ans%=MOD;
cout<<ans;
return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int f[1001];
int main()
{
    int n,k,s=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) 
    {
    scanf("%d",&f[i]);
	}
    for(int i=1;i<=n-1;i++)
    for(int j=i+1;j<=n;j++)
    if(f[i]<f[j])
	{
	swap(f[i],f[j]);
	} 
    for(int i=1;i<=k;i++)
	s=s+f[i];
    printf("%d\n",s);
    return 0; 
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func dijkstra(E *[][]int, s int) (D []int) {
  N := len((*E))
  D = make([]int, N)
  for i := 0; i < N; i++ {
    if i != s {
      D[i] = -1
    }
  }
  Q := make([]int, N)
  Q[0] = s
  var v int
  pos := 1
  for i := 0; i < N; i++ {
    v = Q[i]
    for _, adj := range (*E)[v] {
      if D[adj] >= 0 {
        continue
      }
      D[adj] = D[v] + 1
      Q[pos] = adj
      pos += 1
    }
  }
  return
}

func max(A *[]int) (i, a int) {
  i = 0
  a = (*A)[0]
  for _i, _a := range (*A) {
    if _a > a {
      a = _a
      i = _i
    }
  }
  return
}

func main() {
  var N int
  fmt.Scan(&N)
  E := make([][]int, N)
  for i := range E {
    E[i] = make([]int, 0)
  }
  var a, b int
  for i := 0; i < N - 1; i++ {
    fmt.Scan(&a, &b)
    E[a - 1] = append(E[a - 1], b - 1)
    E[b - 1] = append(E[b - 1], a - 1)
  }
  D0 := dijkstra(&E, 0)
  s, _ := max(&D0)
  D1 := dijkstra(&E, s)
  _, L := max(&D1)
  if L % 3 != 1 {
    fmt.Println("First")
  } else {
    fmt.Println("Second")
  }
}

Measured memory_bytes: 23808
n = gets.to_i
bs = gets.split(' ').map(&:to_i)

sum = bs[0]
prev_b = bs[0]

bs.drop(1).each do |b|
  if b >= prev_b
    sum += prev_b
  else
    sum += b
  end
  prev_b = b
end

sum += bs.last

puts sum

Measured memory_bytes: 1788
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll MOD = 1000000007;

ll modpow(ll a, int n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return a * modpow(a, n-1) % MOD;
    ll h = modpow(a, n/2) % MOD;
    return h * h % MOD;
}

ll modinv(ll x) {
    return modpow(x, MOD-2);
}

ll perm[1010][1010], fact[1010], factinv[1010], factpowinv[1010][1010];

void init() {
    for (int j = 0; j <= 1000; ++j) {
        perm[j][0] = 1;
        for (int k = 1; k <= j; ++k)
            perm[j][k] = perm[j][k-1] * (j-k+1) % MOD;
    }

    fact[0] = 1;
    for (int j = 1; j <= 1000; ++j)
        fact[j] = fact[j-1] * j % MOD;

    for (int j = 0; j <= 1000; ++j)
        factinv[j] = modinv(fact[j]);

    ll inv1 = modinv(1);
    for (int j = 0; j <= 1000; ++j)
        factpowinv[j][0] = inv1;

    for (int j = 0; j <= 1000; ++j) {
        for (int k = 1; k <= 1000; ++k)
            factpowinv[j][k] = factpowinv[j][k-1] * factinv[j] % MOD;
    }
}

int N, A, B, C, D;

ll dp[1010][1010];

int main() {
    cin >> N >> A >> B >> C >> D;
    init();

    for (int j = A; j <= B; ++j) fill(dp[j], dp[j]+N+1, 0);
    dp[A-1][0] = 1;

    for (int j = A; j <= B; ++j) {
        for (int k = 0; k <= N; ++k) {
            dp[j][k] = dp[j-1][k];
            for (int m = C; m <= D && k - m * j >= 0; ++m) {
                ll inc = dp[j-1][k - m*j]
                    * perm[N - k + m*j][m*j] % MOD
                    * factpowinv[j][m] % MOD
                    * factinv[m] % MOD;
                dp[j][k] = (dp[j][k] + inc) % MOD;
            }
        }
    }

    cout << dp[B][N] << endl;
    return 0;
}


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

int main(){
    int E, Y;
    cin >> E >> Y;

    if(E == 0){
        if(Y >= 1868 && Y <= 1911){
            cout << "M" << 44-(1911-Y) << endl;
        }else if(Y >= 1912 && Y <= 1925){
            cout << "T" << 14-(1925-Y) << endl;
        }else if(Y >= 1926 && Y <= 1988){
            cout << "S" << 63-(1988-Y) << endl;
        }else if(Y >= 1989 && Y <= 2016){
            cout << "H" << 28-(2016-Y) << endl;
        }
    }else{
        if(E == 1){
            cout << 1868+(Y-1) << endl;
        }else if(E == 2){
            cout << 1912+(Y-1) << endl;
        }else if(E == 3){
            cout << 1926+(Y-1) << endl;
        }else if(E == 4){
            cout << 1989+(Y-1) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S;
  int ans = 0;
  cin >> S;
  for (int i=0; i<S.size() - 1; i++){
    switch(stoi(S.substr(i, 1))*2 + stoi(S.substr(i + 1, 1))){
      case 0:
        ans++;
        S[i + 1] = '1';
        break;
      case 1:
        break;
      case 2:
        break;
      case 3:
        ans++;
        S[i + 1] = '0';
        break;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	if((A+B)%2 == 0){

		printf("%d\n",(A+B)/2);
	}else{

		printf("%d\n",(A+B)/2+1);
	}

	return 0;
}


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


using namespace std;


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

  if(S[0] == S[1] && S[2] == S[3] && S[0] != S[2])  cout << "Yes" << endl;
  else if(S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) cout << "Yes" << endl;
  else if(S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) cout << "Yes" << endl;

  else  cout << "No" << endl;

  return 0;
}


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

int main(){
  int M[N][N]; //0オリジンの隣接行列
  int n,u,k,v;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--; //0オリジンへ変換
    for(int j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }


  return 0;
}



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

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

    int size = s.size();
    rep (i, size)
    {
        if (s[i] + n > 'Z')
            printf("%c", 'A' - 1 + (n - ('Z' - s[i])));
        else
            printf("%c", s[i] + n);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
A,B,C = map(int,input().split())

L = [A,B,C]
L.sort()

if ((L[0] != L[1]) and (L[1] == L[2])) or ((L[0] == L[1]) and (L[1] != L[2])):
    print('Yes')
else:
    print('No')


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

int main() {

  std::string W;
  std::string temp;

  int ans = 0;

  std::cin >> W;
  for(int i = 0; i < W.size(); ++i) {
    W[i] = (W[i] & 0x5f);
  }
  for(;;) {
    std::cin >> temp;
    if( temp == "END_OF_TEXT" ) {
      break;
    }

    for(int i = 0; i < temp.size(); ++i) {
      temp[i] = (temp[i] & 0x5f);
    }

    if( W == temp ) {
      ans += 1;
    }
  }

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

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << A[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int d;cin >> d;
    if(d==25) puts("Christmas");
    else if(d==24) puts("Christmas Eve");
    else if(d==23) puts("Christmas Eve Eve");
    else puts("Christmas Eve Eve Eve");
    return 0;
}



Measured memory_bytes: 256
import numpy as np
from itertools import combinations

def blk_counter(mat):
    cnt = np.count_nonzero(mat == '#')
    return cnt


def main():
    H, W, K = map(int,input().split(' '))
    r_index = [i for i in range(H)]
    c_index = [i for i in range(W)]
    mat = []
    for i in range(H):
        mat.append(list(input()))
    
    mat = np.array(mat)

    blk_cnt = 0
    cnt = 0

    dele_r_list = []
    dele_c_list = []

    for i in range(H+1):
        for j in combinations(r_index,i):
            dele_r_list.append(j)

    for i in range(W+1):
        for j in combinations(c_index,i):
            dele_c_list.append(j)

    for deler in dele_r_list:
        mat_d = np.delete(mat, deler, 0)
        for delec in dele_c_list:
            mat_dd = np.delete(mat_d, delec, 1)
            blk_cnt = blk_counter(mat_dd)
            if blk_cnt == K:
                cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27256
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 1e5 + 5;

int n;
int arr[N];
    
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>n;
    REP(i,1,n)cin>>arr[i];
    
    int ans = 0;
    int i=1, j=n;
    while(1){
    	while(i <= n && arr[i] != i)i++;
    	while(j >= 1 && arr[j] != j)j--;
    	
    	if(i > j)break;
    	swap(arr[i], arr[i+1]);
    	i += 2;
    	ans++;
	}
	
	cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c = map(int, input().split())
for i in range(10**5):
    if a*i % b == c:
        print('YES')
        exit()
print('NO')


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

int main (void) {
    int num[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;

    scanf("%d", &k);

    printf("%d\n", num[k-1]);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

bool isprime(int n){
	if(n<2)return true;
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}

void solve(){
	int x;
	cin>>x;
	while(!isprime(x))x++;
	cout<<x;

}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  string ans;
  int skip = 0;
  drep(i, s.size()) {
    if (s[i] == 'B') skip++;
    else if (skip) skip--;
    else ans += s[i];
  }
  reverse(rng(ans));
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
map<int,int>pos,cnt;
ll ans[MAXN];
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	int n;
	scanf("%d",&n);pos[0]=1;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
		if(!pos[x])
			pos[x]=i;
	}__typeof((pos).begin())it=(--pos.end());
	int res=0,now=INF;
	while(1){
		if(it->ff==0)
			break;
		__typeof((pos).begin())tt=it;tt--;	
		res+=cnt[it->ff];
		umin(now,it->ss);
		ans[now]+=res*1LL*(it->ff-(tt->ff));
		it--;
	}
	for(int i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 11264
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
 
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        String relation;
 
        if(a > b){
            relation = ">";
        }else if(a < b){
            relation = "<";
        }else{
            relation = "==";
        }
 
        System.out.printf("a %s b\n", relation);
    }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> row;
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for (int j = 0; j < H; j++) {
    row = vector<char>(W + 1, '#');
    for (int i = 0; i < W; i++) {
      cin >> row.at(i + 1);
    }
    row.push_back('#');
    for (int k = 0; k < row.size(); k++) {
      cout << row.at(k);
    }
    cout << endl;
  }
  
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n;
int a[100];

bool check()
{
    for (int i=0; i<n-1; ++i)
        if (a[i]>a[i+1]) return 0;
    return 1;
}

int main()
{
    int flag=0;
    cin>>n;
    for (int i=0; i<n; ++i)
        cin>>a[i];
    if (check()) flag=1;
    for (int i=0; i<n; ++i)
        for (int j=i+1; j<n; ++j)
        {
            swap(a[i],a[j]);
            if (check()) flag=1;
            swap(a[i],a[j]);
        }
    if (flag==0)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(ll, n, q);
  vector<vector<int>> g(n + 1);
  rep(i, n - 1) {
    in(int, a, b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<ll> xs(n + 1);
  rep(i, q) {
    in(ll, p, x);
    xs[p] += x;
  }
  vector<ll> result(n + 1);
  function<void(ll, int, int)> dfs = [&](ll x, int node, int parent) {
    x += xs[node];
    result[node] = x;
    for (int child : g[node]) {
      if (child == parent) continue;
      dfs(x, child, node);
    }
  };
  dfs(0, 1, -1);
  rep(i, n) {
    if (i) cout << " ";
    cout << result[i + 1];
  }
  cout << endl;
}


Measured memory_bytes: 39144
#include <stdio.h>
#include <math.h>
#define NUM 1000

int yes_no(int a, int b, int c);

int main(void)
{
	int n,i,a,b,c;

	for(scanf("%d",&n),i=0; i<n; i++){
		scanf("%d%d%d",&a,&b,&c);
		if(yes_no(a,b,c))
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}
		


int yes_no(int a, int b, int c)
{
	a*=a;
	b*=b;
	c*=c;

	if(a+b==c)
		return 1;
	else if(b+c==a)
		return 1;
	else if(c+a==b)
		return 1;

	return 0;
}

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

int selectionSort(int A[], int N) {

	int count = 0, j, i , minj=0;
		for(i = 0; i < N-1; i++){
			minj = i;
			
		for (j = i; j <N; j++) {
		
			if (A[j] < A[minj]) 
				
				minj = j;
		
			
		}
			swap(A[i], A[minj]);
			if (i != minj)
			count++;
			
	
	}
	return count;
}
int main() {

	int A[100];
	int N, i, count;

	cin >> N;
	for (i = 0; i < N; i++)
		cin >> A[i];
	count = selectionSort(A, N);

	cout << A[0];
	for (i = 1; i < N; i++) cout <<" "<< A[i];
	cout << endl;
	cout << count << endl;


}

Measured memory_bytes: 3100
<?php
fscanf(STDIN, "%s", $n);

$list = explode(" ", fgets(STDIN));

$answer = 0;

for($i = 0; $i < count($list); $i++){
    if($i === 0 || $list[$i] >= $list[$i-1]){
        continue;
    }
    else{
        $diff = $list[$i-1] - $list[$i];
        $list[$i] += $diff;
        $answer += $diff;
        
        // while($list[$i] < $list[$i-1]){
        //     $list[$i] ++;
        //     $answer ++;
        // }
    }
}

echo $answer;

?>


Measured memory_bytes: 31912