akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int line[2001], raw[2001], m[2001][2001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char matrix[h][w];
    int cnt;
    for(int i = 0; i < h; i++){
        cnt = 0;
        for(int j = 0; j < w; j++){
            cin >> matrix[i][j];
            if(matrix[i][j] == '#'){
                cnt = 0;
                line[j] = 0;
            }
            else{
                line[j] = ++cnt;
            }
        }
        for(int j = w-1; j >= 0; j--){
            if(line[j] == 0) cnt = 0;
            else{
                cnt = max(cnt, line[j]);
                m[i][j] = cnt;
            }
        }
    }
    int ans = 0;
    for(int j = 0; j < w; j++){
        cnt = 0;
        for(int i = 0; i < h; i++){
            if(matrix[i][j] == '#'){
                cnt = 0;
                raw[i] = 0;
            }
            else{
                raw[i] = ++cnt;
            }
        }
        for(int i = h-1; i >= 0; i--){
            if(raw[i] == 0) cnt = 0;
            else{
                cnt = max(cnt, raw[i]);
                m[i][j] += cnt;
            }
            ans = max(ans, m[i][j]-1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,k;
  cin >> n >> k;
  vector<bool>vec(n,false);
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      a--;
      vec[a]=true;
    }
  }
  int cnt=0;
  rep(i,n){
    if(!vec[i])cnt++;
  }
  cout << cnt << endl;
  return 0;     
}


Measured memory_bytes: 3660
def main():
    N = int(input())

    memo = set()
    prev = ''
    for _ in range(N):
        s = input()
        if prev and ((prev[-1] != s[0]) or (s in memo)):
            print('No')
            return
        memo.add(s)
        prev = s

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
H, W = [int(i) for i in input().split()]
S = [list(input()) for _ in range(H)]

move = [(1, 0), (0, 1), (-1, 0), (0, -1), (1, -1), (-1, 1), (-1, -1), (1, 1)]

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            continue
        count = 0
        for nh, nw in ((h + dh, w + dw) for dh, dw in move):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "#":
                count += 1
        S[h][w] = str(count)

for h in range(H):
    print("".join(S[h]))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
# define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  faster;
  ld a,b;
  cin >> a >> b;
  cout << setprecision(0)<< fixed <<floor(a*b) ;
  
}

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

int main(){
  int n, x, i;
  scanf("%d%d", &n, &x);
  int m[n];
  for (i = 0; i < n; i++){
    scanf("%d", &m[i]);
  }

  sort(m, m + n);
  int add = 0;
  for (i = 0; i < n; i++){
    add += m[i];
  }
  int ans = n;
  int flag = 0;
  while (add < x){
    add += m[0];
    ans++;
    if (add == x){
      flag = 0;
      break;
    }
    flag = 1;
  }
  if (flag == 1){
    ans -= 1;
  }

  printf("%d", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

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

int main(){
    string s; cin >> s;
    int n = s.size();
    int count_start_0 = 0;
    int count_start_1 = 0;

    rep(i, n){
        if(i % 2 == 0){
            if(s[i] == '1'){
                count_start_0++;
            }
        }else{
            if(s[i] == '0'){
                count_start_0++;
            }
        }
    }
    rep(i, n){
        if(i % 2 == 0){
            if(s[i] == '0'){
                count_start_1++;
            }
        }else{
            if(s[i] == '1'){
                count_start_1++;
            }
        }
    }

    cout << min(count_start_1, count_start_0);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M,K;
    cin >> N >> M >> K;
    combination c(N);
    mint ans = 0;
    for(ll i=0; i<=K; i++){
        mint temp = M;
        mint suzu = M-1;
        temp *= suzu.pow(N-i-1);
        temp *= c(N-1,i);
        ans += temp;
    }
    cout << ans.x << enld;
    return 0;
}


Measured memory_bytes: 6336
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  double a[11],ans;
  while(cin>>a[1]){
   
    ans=a[1];
    for(int i=2;i<11;i++){
      if(i%2){
	a[i]=a[i-1]/3.0;
      }else{
	a[i]=a[i-1]*2.0;
      }
      ans+=a[i];
    }
    printf("%.8f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[100010][3];

ll calc(ll a,ll b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b%2==0){
        ll tmp = calc(a,b/2);
        return tmp*tmp%mod;
    }else{
        ll tmp = calc(a,b/2);
        tmp = tmp*tmp%mod;
        return tmp*a%mod;
    }
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    ll tmp = 1;
    for(int i=0;i<n;i++){
        if(s[i]=='A'){
            dp[i+1][0] = (dp[i][0]+tmp)%mod;
            dp[i+1][1] = dp[i][1];
            dp[i+1][2] = dp[i][2];
        }else if(s[i]=='B'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = (dp[i][1]+dp[i][0])%mod;
            dp[i+1][2] = dp[i][2];
        
        }else if(s[i]=='C'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
            dp[i+1][2] = (dp[i][2]+dp[i][1])%mod;
        
        }else{
            dp[i+1][0] = (3*dp[i][0]+tmp)%mod;
            dp[i+1][1] = (3*dp[i][1]+dp[i][0])%mod;
            dp[i+1][2] = (3*dp[i][2]+dp[i][1])%mod;
            tmp*=3;
            tmp%=mod;
        }
    }
    // for(int i=0;i<=n;i++){
    //     cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    // }
    cout << dp[n][2] << endl;
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 998244353  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 1000000000000000


int32_t main()
{   
    io

    int a, b;

    cin>>a>>b;

    cout<<ceil(1.0*(b-1)/(a-1));

    
return 0;
}   

Measured memory_bytes: 256
using System;

class Program {
    private static int Main() {
        var input = Console.ReadLine();
        var values = input.Split( ' ' );

        int W = int.Parse( values[ 0 ] );
        int H = int.Parse( values[ 1 ] );
        int x = int.Parse( values[ 2 ] );
        int y = int.Parse( values[ 3 ] );
        int r = int.Parse( values[ 4 ] );

        bool isYes = true;
        if( x - r < 0 ) { isYes = false; }
        if( x + r > W ) { isYes = false; }
        if( y - r < 0 ) { isYes = false; }
        if( y + r > H ) { isYes = false; }

        var output = isYes ? "Yes" : "No";
        Console.WriteLine( output );

        return 0;
    }

}

Measured memory_bytes: 19580
K, N = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

max = 0

N.times do |n|
  break if n == N - 1
  distance = A[n + 1] - A[n]
  max = distance if distance > max
end

a0_an = A[0] + (K - A[N - 1])
max = a0_an if a0_an > max

puts K - max

Measured memory_bytes: 15364
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ull_t = unsigned long long;

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

    vector<int> A(N, 0);
    for (auto &a : A)
        cin >> a;

    unordered_map<int, unordered_set<int>> M; // Ai -> i
    for (int i = 0; i < N; ++i)
        M[A[i]].insert(i);

    size_t sum = 0;
    for (const auto &p : M)
    {
        auto n = p.second.size();
        sum += n * (n - 1) / 2;
    }

    for (int i = 0; i < N; ++i)
    {
        auto n = M[A[i]].size();
        cout << (sum - (n - 1)) << endl;
    }
}


Measured memory_bytes: 25288
n = int(input())
t,a = map(int,input().split())
lis = list(map(int,input().split()))

li = abs((t-lis[0]*0.006)-a)
l = 0
for i in range(1,n):
    if abs((t-lis[i]*0.006)-a) < li:
        li=abs((t-lis[i]*0.006)-a)
        l=i
print(l+1)

Measured memory_bytes: 3064
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.random;
import std.range;
import std.functional;
import std.container;
struct Puzzle
{
    int[9] panel;
    size_t toHash() const @safe pure nothrow
    {
        size_t hash = 0;
        foreach (i; panel)
        {
            hash *= 10;
            hash += i;
        }
        return hash;
    }
    bool opEquals(ref const Puzzle s) const @safe pure nothrow
    {
        return equal(panel[0..$], s.panel[0..$]);
    }
    int c;
}
int[] dx = [-1, 0, 1, 0];
int[] dy = [0, -1, 0, 1];
void main()
{
    bool[Puzzle] set;
    auto queue = DList!Puzzle();
    Puzzle initial;
    foreach (i; 0..9)
    {
        scanf("%d", &initial.panel[i]);
    }
    set[initial] = true;
    queue.insertBack(initial);
    while (!queue.empty)
    {
        auto u = queue.front;
        queue.removeFront;
        if (u.panel[0..$].equal([1, 2, 3, 4, 5, 6, 7, 8, 0]))
        {
            writeln(u.c);
            break;
        }
        auto sp = u.panel[0..$].countUntil(0);
        auto sx = sp % 3;
        auto sy = sp / 3;
        foreach (r; 0..4)
        {
            auto tx = sx + dx[r];
            auto ty = sy + dy[r];
            if (tx < 0 || tx >= 3 || ty < 0 || ty >= 3)
                continue;
            auto temp = u;
            temp.panel[sp].swap(temp.panel[tx + ty * 3]);
            if (temp !in set)
            {
                set[temp] = true;
                temp.c++;
                queue.insertBack(temp);
            }
        }
    }
}


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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    cout << (abs(a - x) > abs(b - x) ? "B" : "A") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int p = 0;
    bool ans = false;
    cin >> str;
    for(; p < str.length(); p++)
        if(str[p] == 'C')
            for(; p < str.length(); p++)
                if(str[p] == 'F')
                    ans = true;
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
from sys import exit

N,M = map(int, input().split())

S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().split())

k = [-1]*N
for i in range(M):
    s,c = S[i],C[i]
    if k[s-1]==-1:
        k[s-1] = c
    else:
        if k[s-1]!=c:
            print(-1)
            exit()

ans = [0]*N
for i in range(N):
    if k[i]==-1:
        ans[i] = 0
    else:
        ans[i] = k[i]


if N==1:
    print(ans[0])
    exit()

if ans[0]==0:
    f=True
    for i,j in zip(S,C):
        if i==1 and j==0:
            f = False
            break
    if f:
        ans[0] = 1
    else:
        print(-1)
        exit()

print(*ans,sep='')

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

int main()
{
    int a, b, c, x, y, z;

    while( cin >> a >> b )
    {
        if( a + b == 0 )
            break;
        
        c = b - a;
        z = c / 1000;
        y = ( c % 1000 ) / 500;
        x = ( c % 1000 % 500 ) / 100;

        cout << x << " " << y << " " << z << endl;
    }
    return 0;
}


Measured memory_bytes: 2996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


int main() {
    int n,m;
    cin >> n >> m;
    
    if(n == m)print("Yes");
    else print("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXX=100000+5;
const int INF=INT_MAX;

int a[MAXX],dp[MAXX]; // a数组为数据，dp[i]表示以a[i]结尾的最长递增子序列长度

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

        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            dp[i]=0;
        }
        int ans=0;
        for(int i=1; i<n; i++)
        {
                if(a[i]<=a[i-1])
                {
                    dp[i]=max(dp[i],dp[i-1]+1);
                }

            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

ll optimal(int n, vector<vector<ll>> vec) {
	int sz = vec.size();
	for(int i=n+1; i<sz; ++i) {
		for(int j: vec[i]) {
			vec[n].pb(j);
		}
	}

	int taken = 0;
	priority_queue<ll> Q;
	
	ll res = 0;
	for(int i=1; i<=n; ++i) {
		if(vec[i].empty()) continue;
		sort(vec[i].rbegin(), vec[i].rend());
		int j = 1;

		while(j < (int)vec[i].size() && taken < i-1) {
			taken++;
			res += vec[i][j];
			Q.push(-vec[i][j]);
			j++;
		}
		
		while(j < (int)vec[i].size() && Q.size() && -Q.top() < vec[i][j]) {
			res += Q.top() + vec[i][j];
			Q.pop();
			Q.push(-vec[i][j]);
			j++;
		}

		taken++;
		res += vec[i][0];
		Q.push(-vec[i][0]);
	}
	return res;
}

ll solve() {
	int n;
	cin>>n;
	vector<int> k(n);
	vector<ll> l(n), r(n);
	vector<vector<ll>> vec(n+1), rev(n+1);
	int cnt=0, cntr=0;
	ll ans = 0;
	for(int i=0; i<n; ++i) {
		cin>>k[i]>>l[i]>>r[i];
		if(l[i] >= r[i]) {
			ans += r[i];
			vec[k[i]].pb(l[i]-r[i]);
			cnt++;
		}
		else {
			ans += l[i];
			if(k[i] < n) {
				rev[n - k[i]].pb(r[i]-l[i]);
				cntr++;
			}
		}
	}
	
	return ans + optimal(cnt, vec) + optimal(cntr, rev); 
}


int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;

	while(t--) {
		cout<<solve()<<'\n';
	}

}


Measured memory_bytes: 37772
n, m = map(int, input().split())
ds = []
for _ in range(n):
    a, b = map(int, input().split())
    ds.append((a,b))

ds.sort(key=lambda x: x[0])
ans = 0
for a, b in ds:
    if m < b:
        ans += a * m
        break
    else:
        ans += a * b
        m -= b
print(ans)

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using pib = pair<int, int>;


 
int main (){
    
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++)A[i]=i;
    
    vector<pib> xy(N);
    for(pib &i:xy)cin >> i.first >> i.second;
    
    ld dis0=0,count=0;
    do {
        for(int i=0;i<N-1;i++)dis0+=sqrt(pow(xy[A[i]].first-xy[A[i+1]].first,2)+pow(xy[A[i]].second-xy[A[i+1]].second,2));
        count++;
    } while (next_permutation(A.begin(), A.end()));

    printf("%.10Lf",dis0/count);
}


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


int main(){
    int n;
    cin >>n;
    if(n==0){cout<<1;return 0;}
    vector<int> fib(n+1);
    fib[0]=1;
    fib[1]=1;
    for(int i=2;i <= n;i++){
        fib[i]=fib[i-1]+fib[i-2];
    }
    cout <<fib[n]<<endl;
    return 0;
}


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

using namespace std;
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 100010
ll n,k,f[N],a[N];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<=k;i++)f[i]=0;
    for(int i=0;i<=k;i++){
        if(f[i]==1)continue;
     for(int j=0;j<n;j++){
      ll p=i+a[j];
      if(p<=k)f[p]=1;
     }
    }
    cout<<(f[k]?"First":"Second")<<endl;
 return 0;   
}

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


#define endl '\n'
int32_t main()
{

    int t;
    cin>>t;
    int f=0,se=0,th=0,l=0;
    while(t--)
    {
    	string s;
    	cin>>s;
    	
    	if(s=="AC")
    		f++;
    	else if(s=="WA")
    		se++;
    	else if(s=="TLE")
    		th++;
    	else
    		l++;
    }
    cout<<"AC x "<<f<<endl;
     cout<<"WA x "<<se<<endl;
     cout<<"TLE x "<<th<<endl;
     cout<<"RE x "<<l<<endl;
    return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

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

struct BIT {
  
  vector<int> bit;

  BIT() {}
  
  int n;
   
  BIT(int n) {
    this->n = n;
    bit.resize(n+1);
  }

  void update(int idx, int val){
    for(int i = idx; i <= n; i += i&-i){
      bit[i]+=val;
    }
  }

  int prefix_query(int idx){
    int ans = 0;
    for(int i=idx; i>0; i -= i&-i){
      ans += bit[i];
    }
    return ans;
  }
  
  int query(int l, int r){
    return prefix_query(r) - prefix_query(l-1);
  }
  
  //int bit 0-1 it finds the index of k-th element active
  int kth(int k) {
    int cur = 0;
    int acc = 0;
    for(int i = 19; i >= 0; i--) {
      if(cur + (1<<i) > n) continue;
      if(acc + bit[cur + (1<<i)] < k) {
        cur += (1<<i);
        acc += bit[cur];
      }
    }
    return ++cur;
  }
  
};



int32_t main(){
  int n;
  cin >> n;
  int v[n+1];
  for(int i=1; i<=n; i++){
    int x;
    cin >> x;
    v[x] = i;
  }
  BIT bit(n);
  int ans = 0;
  for(int i=n; i>=1; i--){
    
    int l = 1, r = v[i];
    int ansl1 = -1;
    while(l <= r){
      int m = (l+r)>>1;
      if(bit.query(m, v[i]) <= 1){
        if(bit.query(m, v[i]) == 1) ansl1 = m;
        r = m-1;
      }
      else l = m+1;
    }
    
    int ansl0 = 1;
    l = 1, r = v[i];
    while(l <= r){
      int m = (l+r)>>1;
      if(bit.query(m, v[i]) <= 0){
        ansl0 = m;
        r = m-1;
      }
      else l = m+1;
    }
    
    int ansr1 = -1;
    l = v[i], r = n;
    while(l <= r){
      int m = (l+r)>>1;
      if(bit.query(v[i], m) <= 1){
        if(bit.query(v[i], m) == 1) ansr1 = m;
        l = m+1;
      }
      else r = m-1;
    }   
    
    int ansr0 = n;
    l = v[i], r = n;
    while(l <= r){
      int m = (l+r)>>1;
      if(bit.query(v[i], m) <= 0){
        ansr0 = m;
        l = m+1;
      }
      else r = m-1;
    }
    //cout << "ansl0 " << ansl0 << " ansl1 " << ansl1 << " ansr0 " << ansr0 << " ansr1 " << ansr1 << endl;
    //cout << "update at " << v[i] << " " << i << endl;
    bit.update(v[i], 1);
    if(ansr1 != -1) ans += (ansr1 - ansr0)*(v[i] - ansl0+1)*i;
    if(ansl1 != -1) ans += (ansl0 - ansl1)*(ansr0 - v[i] + 1)*i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 1792
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=1e18,MOD=1e9+7,MAX=2e5+2;

vector<int>Size(MAX),parent(MAX);

void make_set(int v){
    parent[v]=v;
    Size[v]=1;
}

int find_set(int v){
    if(parent[v]==v)
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_set(int u,int v){
    int a=find_set(u);
    int b=find_set(v);
    if(a==b)
        return;
    if(Size[a]<Size[b])
        swap(a,b);
    parent[b]=a;
    Size[a]+=Size[b];
}


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n,m;
    cin>>n>>m;
    lp(i,1,n+1)
        make_set(i);
    lp(i,0,m){
        int a,b;
        cin>>a>>b;
        union_set(a,b);
    }
    map<ll,ll>mp;
    lp(i,1,n+1)
        mp[find_set(i)]++;
    ll res=0;
    for(auto i:mp)
        res=max(res,i.S);
    cout<<res;
}

Measured memory_bytes: 17168
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

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

	if ((n - 1) % (k - 1) == 0) {
		cout << (n - 1) / (k - 1) << endl;
	}
	else {
		cout << (n - 1) / (k - 1) +1<< endl;
	}

}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()
a=sorted([a[i]-b[i] for i in range(n)])
cnt=0
a.append(0)
k=n
for i in range(n):
    if a[i]<0:
        cnt+=1
        while True:
            if a[k]+a[i]<0:
                a[i]+=a[k]
                k-=1
                cnt+=1
            else:
                a[k]+=a[i]
                break
    else:
        break
print(cnt)

Measured memory_bytes: 19188
import sys
import math

min_, max_ = [int(_) for _ in sys.stdin.readlines()[0].strip().split(' ')]

res = []
for i in range(min_, max_+1):
  target = str(i)
  flag = True
  for n in range(len(target)):
    #print('target:{}, target[n]:{}, target[-(n+1)]: {}'.format(target, target[n], target[-(n+1)]))
    if not target[n] == target[-(n+1)]:
      flag = False
  if flag:
    res.append(i)
#print(res)
print(len(res))

Measured memory_bytes: 3064
import java.util.*;

public class Main {

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

		String a = sc.next();
		String b = sc.next();
		sc.close();
		System.out.println(b + a);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int w,h,n;
	cin>>w>>h>>n;
	int x1=0,x2=w,y1=0,y2=h;
	while(n--) {
		int x,y,a;
		cin>>x>>y>>a;
		switch(a) {
			case 1: x1=max(x,x1);break;
			case 2: x2=min(x,x2);break;
			case 3: y1=max(y,y1);break;
			case 4: y2=min(y,y2);break;
		}
	}
	if(x2<=x1||y2<=y1)cout<<0;
	else
	cout<<(x2-x1)*(y2-y1);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3664
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int alice = scan.nextInt();
		int bob = scan.nextInt();
		if(alice == 1){
			alice = 14;
		}
		if(bob == 1){
			bob = 14;
		}
		
		String str;
		if(alice > bob){
			str = "Alice";
		} else if (bob > alice){
			str = "Bob";
		} else {
			str = "Draw";
		}
		
		
		System.out.println(str);
		
	}
}

Measured memory_bytes: 22864
#include<bits/stdc++.h>
const int N = 1e5 + 5;
const int inf = 1e9 + 7;
using namespace std;

vector <int> adj[N];
int n, k, l[N], r[N], ans[N];

void Merge(int& l, int& r, int L, int R){
    if (l == -inf) l = L, r = R;
    else{
        if ((l + L) % 2 != 0) {cout << "No"; exit(0);}
        l = max(l, L);
        r = min(r, R);
        if (l > r) {cout << "No"; exit(0);}
    }
}

void dfs(int u, int p){
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        if (v == p) continue;
        dfs(v, u);
        if (l[v] != -inf) Merge(l[u], r[u], l[v]-1, r[v]+1);
    }
}

void redfs(int u, int p){
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        if (v == p) continue;
        if (ans[u]-1 >= l[v]) ans[v] = ans[u] - 1;
        else ans[v] = ans[u] + 1;
        redfs(v, u);
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) l[i] = -inf, r[i] = inf;
    for (int i = 2; i <= n; i++){
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> k;
    for (int i = 1; i <= k; i++){
        int a, b; cin >> a >> b;
        l[a] = r[a] = b;
    }
    dfs(1, 1); ans[1] = l[1]; redfs(1, 1);
    cout << "Yes\n"; for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
}

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

bool bo[100010];
int n,hd[100010],cnt,x,y,d[100010],p[100010],po[100010],ans[100010],q[100010],l,r;
struct node{int to,next;}e[200010];

void addedge(int x,int y)
{
	e[++cnt]=(node){y,hd[x]},hd[x]=cnt;
	e[++cnt]=(node){x,hd[y]},hd[y]=cnt;
	d[x]++,d[y]++;
}

int main()
{
	scanf("%d",&n);
	if (n==2) return puts("1 2"),0;
	for (int i=1; i<n; i++) scanf("%d%d",&x,&y),addedge(x,y);
	for (int i=1; i<=n; i++) if (d[i]>1) cnt++,q[l=r=1]=i;
	while (l<=r)
	{
		x=q[l++],bo[x]=1;
		for (int i=hd[x]; i; i=e[i].next)
			if (!bo[e[i].to]&&d[e[i].to]>1) q[++r]=e[i].to;
	}
	if (r!=(cnt-=(2*n-2))) return puts("-1"),0;
	q[1]=q[r],l=r=1,memset(bo,0,sizeof(bo));
	while (l<=r)
	{
		x=q[l++],bo[x]=1,cnt=0;
		for (int i=hd[x]; i; i=e[i].next)
			if (!bo[e[i].to]&&d[e[i].to]>1) cnt++,q[++r]=e[i].to;
		if (cnt>1) return puts("-1"),0;
	}
	p[cnt=1]=1;
	for (int i=1,nw=1; i<=r; i++)
	{
		p[cnt+1]=nw+d[q[i]]-1,cnt++;
		for (int j=nw+1; j<nw+d[q[i]]-1; j++) p[++cnt]=j;
		nw+=d[q[i]]-1;
	}
	p[++cnt]=n;
	for (int i=1; i<=n; i++) ans[p[i]]=i;
	reverse(q+1,q+1+r);
	p[cnt=1]=1;
	for (int i=1,nw=1; i<=r; i++)
	{
		p[cnt+1]=nw+d[q[i]]-1,cnt++;
		for (int j=nw+1; j<nw+d[q[i]]-1; j++) p[++cnt]=j;
		nw+=d[q[i]]-1;
	}
	p[++cnt]=n;
	for (int i=1; i<=n; i++) po[p[i]]=i;
	for (int i=1; i<=n; i++)
		if (po[i]!=ans[i])
		{
			if (po[i]<ans[i]) memcpy(ans,po,sizeof(ans));
			break;
		}
	for (int i=1; i<=n; i++) printf("%d ",ans[i]);
	return puts(""),0;
}

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

void SelectionSort(int *array, int N) {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (array[j] < array[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            int temp = array[i];
            array[i] = array[minj];
            array[minj] = temp;
            cnt++;
        }
    }

    for (int i = 0; i < N; i++) {
        cout << array[i];
        cout << ((i != N - 1) ? " " : "\n");
    }
    cout << cnt << endl;
}

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

    int *array = new int[n];
    rep(i, n) cin >> array[i];

    SelectionSort(array, n);
    delete array;
}




Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

const ll NMAX=1E12;
ll res=0,n;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    
    for(ll d=1;d*d<=n;d++){
		
		if(n%d==0){
			ll m=d-1;
			
			if(m>0 && n%m==n/m){
				res+=m;
			}
			
			if(n/d!=d){
				m=n/d-1; 
				
				if(m>0 && n%m==n/m){
					res+=m;
				}
			}
		}
	}
	
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 456
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c))	c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 998244353;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, A, B;
int a[N], b[N];
ll jie[N], jieni[N];
inline void init() {
	jie[0] = jieni[0] = 1;
	const int up = 405;
	for (int i = 1; i <= up; ++i)	jie[i] = jie[i - 1] * i % P;
	jieni[up] = quickpow(jie[up], P - 2);
	for (int i = up - 1; i; --i)	jieni[i] = jieni[i + 1] * (i + 1) % P;
}
ll f[N][N];
inline void work() {
	f[0][0] = -1;
	int sm = 0;
	for (int i = 1; i <= n; ++i) {
		sm += a[i];
		for (int s = A; ~s; --s) {
			for (int j = 0; j <= B; ++j) {
				if (s - a[i] < 0) continue;
				ll lstf = f[s][j]; f[s][j] = 0;
				ll tmp = 1;
				for (int k = 0; k < b[i] && k <= j; ++k, tmp = tmp * a[i] % P) {
					f[s][j] = (f[s][j] + f[s - a[i]][j - k] * tmp % P * jieni[k]) % P;
				}
				f[s][j] = (lstf - f[s][j] + P) % P;
			}
		}
	}
	ll ans = 0;
	for (int s = 0; s <= A; ++s) {
		ll sn = quickpow(s, P - 2);
		ll tmp = sn;
		for (int j = 0; j < B; ++j, tmp = tmp * sn % P) {
			ans = (ans + tmp * f[s][j] % P * jie[j]) % P;
		}
	}
	ans = ans * A % P;
	printf("%lld\n", (ans % P + P) % P);
}
int main() {
	read(n);
	for (int i= 1; i <= n; ++i)	read(a[i]), read(b[i]), A += a[i], B += b[i];
	init();
	work();
	return 0;
}

/*
3
1 3
2 2
3 1
//971...
*/

Measured memory_bytes: 4500
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;

int solve() {
    int n = s.size();
    int g = 0, p = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'g') g++;
        else p++;
    }
    return (g - p) / 2;
}

void input() {
    cin >> s;
}

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

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int a, b;
  cin >> a >> b;
  if ((a <= 0) && (b >= 0)) {
    cout << "Zero" << endl;
    return 0;
  }
  if (a > 0) {
    cout << "Positive" << endl;
    return 0;
  }
  if (b < 0) {
    cout << (((b - a) % 2 == 0) ? "Negative" : "Positive") << endl;
    return 0;
  }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {
  ll N; cin >> N;
  vi H(N);
  for (ll i = 0; i < N; i++) cin >> H[i];
  for (ll i = N - 2; i >= 0; i--) {
    if (H[i] > H[i + 1]) {
      H[i] -= 1;
      if (H[i] > H[i + 1]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
  
  int M, D, A = 0;
  cin >> M;
  cin >> D;
  
  for (int i = 1; i <= M; i++) {
   
    for (int s = 10; s <= D; s++) {
      if ((s / 10) >= 2) {
       if ((s % 10) >= 2) { 
        if(i == (s / 10) * (s % 10)) {
         A++; 
        }
       }
      }
    }
    
  }
  
  cout << A;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[105];
int main(){
	bool f=1;
	scanf("%s",s);
	if (s[0]!='A')f=0;bool p=1;
	for (int i=2;i<strlen(s)-1;i++)if (s[i]=='C'){
		s[i]='c';
		p=0;
		break;
	}
	if (p)f=0;
	for (int i=1;i<strlen(s);i++)if (s[i]>='A'&&s[i]<='Z')f=0;
	if (f){
		printf("AC\n");
	}
	else printf("WA\n");
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b,c,left;
    scanf("%d %d %d",&a,&b,&c);
    left=c;
    for(int i = 0; i < c; i++){
        if(b==a || left==0){
            break;
        }else{
            b++;
            left--;
        }
    }
    printf("%d",left);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
 
  int small[1000][1000]={};
  int a[1000],b[1000],n,m,i,j;
 
  cin>>n>>m;
  for(i=0;i<n;i++) cin>>a[i];
  for(i=0;i<m;i++) cin>>b[i];
  small[0][0]=a[0]*b[0];
  for(i=1;i<m;i++) small[0][i]=min(a[0]*b[i],small[0][i-1]);
  for(i=1;i<n;i++) for(j=i;j<m;j++){
      small[i][j]=small[i-1][j-1]+a[i]*b[j];
      if(i!=j) small[i][j]=min(small[i][j],small[i][j-1]);
    }
  cout<<small[n-1][m-1]<<endl;
  return 0;
}

Measured memory_bytes: 7008
#include <iostream>
using namespace std;
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int ans;
    if(B >= A){
        if(C <= B/A){
            ans = C;
        }
        else ans = B/A;
    }else{
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = []

N.times do
  s = gets.to_i
  S << s
end

sum = S.reduce(:+)

if sum % 10 == 0
  S.sort.each do |s|
    if s % 10 != 0
      sum -= s
      break
    end
  end

  if sum % 10 == 0
    puts 0
  else
    puts sum
  end
else
  puts sum
end


Measured memory_bytes: 1788
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {
	
	while (1) {
		string s; cin >> s;

		if (s == "-")break;

		int l = s.size();

		vector<char> a(l);

		int n; cin >> n;

		for (int i = 0; i < n; i++) {
			int buf; cin >> buf;

			for (int j = buf; j < buf + l; j++) {
				a[j - buf] = s[j%l];
			}

			for (int j = 0; j < l; j++) {
				s[j] = a[j];
			}

		}

		for (int i = 0; i < l; i++) {
			cout << a[i];
		}

		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3180
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int numA, numB;
        String op;

        while(true) {
            numA = Integer.parseInt(scan.next());
            op = scan.next();
            numB = Integer.parseInt(scan.next());

            if (op.equals("?")) break;

            if (op.equals("+")) {
                System.out.println(numA + numB);
            } else if (op.equals("-")) {
                System.out.println(numA - numB);
            }  else if (op.equals("*")) {
                System.out.println(numA * numB);
            } else {
                System.out.println(numA / numB);
            }
        }
    }
}



Measured memory_bytes: 26164
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL dp[101][101][260];
//dp[i][j][k] = i番目までからj個選んでkになる組み合わせ
int modFact[110];

inline void add(LL &a, LL b) {
    a = (a + b) % MOD;
}

inline LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

int main(void) {
    modFact[0] = 1;
    FOR(i, 1, 110) {
        modFact[i] = mul(modFact[i - 1], i);
    }
    int N, K; cin >> N >> K;
    VI a(N);
    for_each(ALL(a), [](int &e){cin >> e;});
    dp[0][0][0] = 1; dp[0][1][a[0]] = 1;
    FOR(i, 1, N) {
        REP(j, i + 1) {
            REP(k, 256) {
                LL buf = k ^ a[i];
                add(dp[i][j + 1][buf], dp[i - 1][j][k]);
                add(dp[i][j][k], dp[i - 1][j][k]);
            }
        }
    }
    LL ans = 0;
    REP(i, 101) {
        add(ans, mul(dp[N - 1][i][K], modFact[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
open System

let getTwoInts (_: 'unit): int*int =
    let [|fst; sec|] = Console.ReadLine().Split(' ') |> Array.map Int32.Parse
    fst, sec

[<EntryPoint>]
let main _ =
    let n, m = getTwoInts()
    let gates = List.init m getTwoInts
    let lMax = List.map fst gates |> List.max
    let rMin = List.map snd gates |> List.min
    
    max 0 ((min rMin n) - lMax + 1)
    |> printfn "%d"
    
    0


Measured memory_bytes: 32168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1LL<<60;
int main(){
	string s;cin>>s;
	reverse(s.begin(),s.end());
	int n=s.length();
	vector<vector<ll>> dp(n+10,vector<ll>(2,INF));
	dp[0][0]=0;
	for(int i=0;i<n;i++){
		int c=s[i]-'0';
		dp[i+1][0]=dp[i][0]+c;
		if(c<9){
			dp[i+1][0]=min(dp[i+1][0],dp[i][1]+c);
		}
		dp[i+1][1]=dp[i][1]+c-9+2*(9-c);
		dp[i+1][1]=min(dp[i+1][1],dp[i][0]+c-9+2*(10-c));
	}
	cout<<min(dp[n][0],dp[n][1])<<endl;
}


Measured memory_bytes: 55940
#include<stdio.h>
int main(){
  int n,ans=1e9,i,j,s,k=-1,c,d[100010];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=c=1;i<n;i++){//printf("%d ",d[i-1]);
    if(k==-1)k=d[i-1]<=d[i]?d[i-1]==d[i]?-1:0:1;
    if(k==0&&d[i-1]>d[i]||k&&d[i-1]<d[i]){
      k=-1;
      c++;//printf("/");
    }
  }//printf("%d\n",d[i-1]);
  printf("%d\n",c);
  return 0;
}

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

using namespace std;
long long n;
long long dp[100005];
long long a[100005];
int main()
{
   cin>>n;
   for(int i=1; i<=n; i++)
   {
       cin>>a[i];
   }
   dp[0]=0;
   dp[1]=0;
   dp[2]=abs(a[2]-a[1]);
   for(int i=3;i<=n; i++)
   {
       dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]));
   }
   cout<<dp[n];
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define P(x) cerr << #x << "=" << x << endl

const int MOD = 1000002013;
const double pi = atan(1.0)*4.0;
const double eps = 1e-8;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
int bc(int n) { return n ? bc((n-1)&n)+1 : 0; }

int i, j, k, m, n, l;
int a[200001], pos[200001];


int main() {
    //freopen("x.in", "r", stdin);

    while (cin >> n) {
        F1(i, n) { cin >> a[i]; }

        int bad = (a[1]>0);
        F1(i, n -1) if (a[i + 1] > a[i] + 1) bad = 1;
        if (bad) cout << -1 << endl; else {
            ll ans = 0;
            map<int, int> M;
            F1(i, n) {
                if (!a[i]) continue;
                ans += a[i] - M[a[i] - i];
               // cout << i << " " << ans << endl;
                M[a[i] - i] =  a[i];
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,k,i,j;
  cin>>n>>k;
  vector<int> a(n+1),b(n+1);
  for(i=1;i<=n;i++) cin>>a.at(i);
  for(i=1;i<=min(k,100);i++){
    vector<int> b(n+1);
    for(j=1;j<=n;j++){
      b.at(max(1,j-a.at(j)))++;
      if(j+a.at(j)<n) b.at(j+a.at(j)+1)--;
    }
    for(j=2;j<=n;j++) b.at(j)+=b.at(j-1);
    a=b;
    bool f=true;
    for(j=1;j<=n;j++){
      if(a.at(j)<n){
        f=false;
        break;
      }
    }
    if(f==true) break;
  }
  for(i=1;i<=n;i++){
    cout<<a.at(i);
    if(i==n) cout<<endl;
    else cout<<' ';
  }
}

Measured memory_bytes: 5632