akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100005;
LL mod = 1e9 + 7;
char s[N];
LL pre[N][3];
LL three[N] = {1};
int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        pre[i][0] = pre[i - 1][0] + (s[i] == 'A');
        pre[i][1] = pre[i - 1][1] + (s[i] == 'C');
        pre[i][2] = pre[i - 1][2] + (s[i] == '?');
    }
    int cnt = pre[n][2];
    for (int i = 1; i <= cnt; i++) {
        three[i] = three[i - 1] * 3 % mod;
    }
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'B' || s[i] == '?') {
            int tnt = cnt - (s[i] == '?');
            ans += pre[i - 1][0] * (pre[n][1] - pre[i][1]) % mod * three[tnt] %
                   mod;
            if (tnt >= 1)
                ans += pre[i - 1][2] * (pre[n][1] - pre[i][1]) % mod *
                       three[tnt - 1] % mod;
            if (tnt >= 1)
                ans += pre[i - 1][0] * (pre[n][2] - pre[i][2]) % mod *
                       three[tnt - 1] % mod;
            if (tnt >= 2) {
                ans += pre[i - 1][2] * (pre[n][2] - pre[i][2]) % mod *
                       three[tnt - 2] % mod;
            }
            ans %= mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3456
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#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++)

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	int n;
	cin>>n;
	vector<pair<double,double>> arr(n);
	REP(i,0,n-1)cin>>arr[i].F>>arr[i].S;
	sort(arr.begin(),arr.end());
	double cnt=0;
	double sum = 0;
	do{
		cnt++;
		REP(i,1,n-1) {
			sum+=sqrt(pow(arr[i].F-arr[i-1].F,2)+pow(arr[i].S-arr[i-1].S,2));
		}
		//cerr<<sum<<endl;
	}while(next_permutation(arr.begin(),arr.end()));
	sum/=cnt;
	printf("%.6lf",sum);
}

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


Measured memory_bytes: 3784
fun main(args:Array<String>) {
    val b = readLine()!!.toString()
    var list = mutableSetOf<Int>()
    var cnt=0

    for (i in 0 until b.length){
        cnt=0
        while (b[i+cnt]=='A'||b[i+cnt]=='T'||b[i+cnt]=='C'||b[i+cnt]=='G'){
            cnt++
            list.add(cnt)
            if (i+cnt>=b.length) break
        }
    }
    println(list?.max()?:0)
}


Measured memory_bytes: 37872
import Data.Functor ((<$>))

digits :: Int -> [Int]
digits n = go (abs n) []
  where go n' ds
          | n' < 10   = n' : ds
          | otherwise = go (n' `div` 10) ((abs n' `mod` 10) : ds)

main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  putStrLn . (" " ++) . unwords . map show $ filter p [1..n]
    where p x = x `mod` 3 == 0 || 3 `elem` digits x



Measured memory_bytes: 4060
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
	char n[5],l[5],h[5],*k;
	int cnt,t;
	k = "6174";
	while(~scanf("%s",n)){
		cnt=0;
		strcpy(l,n);
		strcpy(h,n);
		sort(l,l+4);
		sort(h,h+4,greater<char>());
		if(*h=='0')break;
		if(!strcmp(h,l)){
			puts("NA");
			continue;
		}
		while(strcmp(n,k)){
			strcpy(l,n);
			strcpy(h,n);
			sort(l,l+4);
			sort(h,h+4,greater<char>());
			for(int i=3;i>=0;i--){
				n[i]=h[i]-l[i]+'0';
				if(n[i]<'0'){
					n[i]+=10;
					h[i-1]--;
				}
			}
			cnt++;
			if(cnt>10)return 0;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1168
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i in range(self.n) if self.parents[i] < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


n,m = map(int,input().split())
tree = UnionFind(n)
for _ in range(m):
    a,b = map(int,input().split())
    tree.union(a,b)

q = int(input())
for i in range(q):
    a,b = map(int,input().split())
    if tree.same(a,b):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 7172
N, M = list(map(int,input().split()))
e = True
c = [-1 for i in range(N)]
for i in range(M):
    si, ci = list(map(int,input().split()))
    if c[si-1]>-1 and c[si-1]!=ci:
        e = False
    c[si-1] = ci
if e and (N==1 or c[0]!=0):
    print(max(0 if N==1 else 1, c[0]),end="")
    for i in range(1,N):
        print(max(0,c[i]),end="")
    print()
else:
    print(-1)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    
    int n;
    scanf("%d", &n);
    vector<int> p(n);
    rep(i, n){
        int x;
        scanf("%d", &x);
        p[x-1] = i+1;
    }
    
    vector<int> a(n), b(n);
    rep(i, n){
        a[i] = 30000*(i+1);
        b[i] = 30000*(n-i-1)+p[i];
    }
    
    rep(i, n){
        char c = (i==n-1) ? '\n' : ' ';
        printf("%d%c", a[i], c);
    }
    rep(i, n){
        char c = (i==n-1) ? '\n' : ' ';
        printf("%d%c", b[i], c);
    }
    return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int[][]A = new int[N][2];
		
		for(int i=0; i<N; i++) {
			A[i][1] = keyboard.nextInt();
		}
		
		int count =0;
		int[] ans = new int[N];
		for(int j=N; j>=1; j--) {
			if(A[j-1][0]%2 != A[j-1][1]) {
				for(int k=1; k*k<=j; k++) {
					if(j%k == 0) {
						A[k-1][0] ++;
						if(k != j/k) {
							A[j/k-1][0] ++;
						}
					}
				}
				count++;
				ans[j-1]++;
			}
		}
		
		System.out.println(count);
		for(int l=0; l<N; l++) {
			if(ans[l] == 1) {
				System.out.print((l+1)+ " ");
			}
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 96672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
    int n, tmp, sm=0, mn=101;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        sm += tmp;
        if (tmp % 10 != 0) {
            mn = min(mn, tmp);
        }
    }

    if (sm % 10 == 0) {
        if (mn == 101) {
            cout << 0 << endl;
        } else {
            cout << sm - mn << endl;
        }
    } else {
        cout << sm << endl;
    }

    return 0;
}

Measured memory_bytes: 256
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter


def ispalindrome(str): return 1 if str == str[::-1] else 0


n = float(stdin.readline().rstrip())


print((n/3)**3)


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

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

int main(){
    int R;
    cin >> R;
    if (R < 1200)
        cout << "ABC" << endl;
    else if (R < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

int main(){
	int n,ans=0,i;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		if(i!=n-i){
			ans++;
		}
	}

	printf("%d\n",ans/2 );
	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
sum = 0

for i in range(1, N + 1) :
    bufSum = 0
    buf = i
    while buf // 10 != 0:
        bufSum += (buf % 10)
        buf = buf //10
    bufSum += buf
    if bufSum >= A and bufSum <= B :
        sum += i

print(sum)

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline

N, K = map(int, readline().split())
p = list(map(int, readline().split()))

t = sum(p[:K])
m = (t + K) / 2
for i in range(1, N - K + 1):
    t = t - p[i - 1] + p[i + K - 1]
    m = max(m, (t + K)/2)

print(m)

Measured memory_bytes: 67824
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    xs.sort()
    val x1 = xs[n / 2 - 1]
    val x2 = xs[n / 2]
    println(x2 - x1)
}

Measured memory_bytes: 51808
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

string s;

bool is_p(string s)
{
	int m = s.size();
	rep(i,0,m) {
		if(s[i] != s[m - 1 - i]) return false;
	}
	return true;
}

int main()
{
	fastIO;
	cin >> s;
	int n = s.size();
	string t1 = s.substr(0,(n - 1) / 2);
	string t2 = s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);
	//cout << t1 << " " << t2 << endl;
	if(is_p(s) && is_p(t1) && is_p(t2)) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
    int N, Q;
    cin >> N >> Q;
 
    vector<int> a(N + 1), b(N + 1);
    for (int i = 1; i <= N; ++i) a[i] = b[i] = N;
 
    ll black = ll(N - 2) * (N - 2);
 
    int H = N, W = N;
 
    while (Q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            if (x < W) {
                for (int i = x; i < W; ++i) {
                    b[i] = H;
                }
                W = x;
            }
            black -= b[x] - 2;
 
        } else {
            if (x < H) {
                for (int i = x; i < H; ++i) {
                    a[i] = W;
                }
                H = x;
            }
            black -= a[x] - 2;
        }
    }
    cout << black << endl;
 
    return 0;
}

Measured memory_bytes: 4808
N = int(input())
A = list(map(int, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]

for i in range(1, N+1):
    for j in range(N-i+1):
        dp[i][j] = max(-dp[i-1][j] + A[j+i-1], -dp[i-1][j+1] + A[j])
print(dp[-1][0])

Measured memory_bytes: 112092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int A,B,C,X,Y,count=INT_MAX,a,b;
  scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
  for(int i=0;i<=max(X,Y);i++){
    if(X-i<0)a=0;
    else a=X-i;
    if(Y-i<0)b=0;
    else b=Y-i;
    count = min(count,C*i*2 + A*a + B*b);
  }
  printf("%d",count);
}


Measured memory_bytes: 128
# frozen_string_literal: true

# Generated by AtcoderGreedy on 2018-04-22
# ABC095 B
# Your code here

$N, $X = gets.chomp.split(' ').map(&:to_i)

$m = []
$N.times do
  $m << gets.chomp.to_i
end

$m = $m.sort

total = $m.reduce(:+)

puts $N + ($X - total) / $m[0]


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<0 && c<0){
    	ll ans1=a*c;
    	ll ans2=b*d;
    	cout<<max(ans1,ans2);
	}
	else if(a>=0 && c>=0){
		ll ans=b*d;
		cout<<ans;
	}
	else if(a<0 && c>=0){
		ll ans1=b*c;
		ll ans2=b*d;
		cout<<max(ans1,ans2);
	}
	else{
		ll ans1=d*a;
		ll ans2=d*b;
		cout<<max(ans1,ans2);
	}
	return 0;
	
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
long long int n,b;
int main()
{
	cin>>n;
	long long a=sqrt(n);
	while(1)
	{
		if(n%a==0){b=n/a;break;}
		a--;
	}
	cout<<to_string(b).length()<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	while(A>=1&&C>=1){
		C-=B;
		if(C<=0){cout<<"Yes";break;}
		A-=D;
		if(A<=0){cout<<"No";break;}
	}
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
string s,t;
string ans="~";
bool check(string a,string b){
	for(int i=0;i<sz(a);i++) if(b[i]!='?'&&b[i]!=a[i]) re 0;
	re 1;
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>s>>t;
	for(int i=0;i+sz(t)<=sz(s);i++){
		string u=s.substr(i,sz(t));
		//cout<<u<<"\n";
		if(check(t,u)){
			string now=s;
			for(int j=0;j<sz(t);j++) now[i+j]=t[j];
			for(int j=0;j<sz(s);j++) if(now[j]=='?') now[j]='a';
			ans=min(ans,now);
		}
	}
	if(ans=="~") cout<<"UNRESTORABLE";
	else cout<<ans;
	re 0;
}

Measured memory_bytes: 3656
A = list(map(int, input().split()))
sugar = []
water = []
if A[2] == 1:
    sugar = [i for i in range(A[5]+1)]
else:
    for i in range(10 + (1 + A[5])//A[2]):
        for j in range(10 + (A[5]-A[2]*i+1)//A[3]):
            if A[2] * i + A[3] * j not in sugar and A[2] * i + A[3] * j <= 3000:
                sugar.append(A[2] * i + A[3] * j)
for i in range(2 + 31//A[0]):
    for j in range(2 + (31 - i)//A[1]):
        if A[0] * i + A[1] * j <= 30 and A[0] * i + A[1] * j not in water:
            water.append(A[0] * i + A[1] * j)
ans = 0
anssugar = 0
answater = min(A[0], A[1]) * 100
for i in sugar:
    for j in water:
        if i + j != 0:
            if ans < 100.0 * i / (i + j) and (i + 100 * j) <= A[5] and i  <= j * A[4]:
                ans = 100.0 * i / (i + j)
                anssugar = i
                answater = 100 * j

print(str(anssugar + answater)+" "+str(anssugar))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[112345];

int main(){
	int n, k; scanf("%d%d%s", &n, &k, s);
	s[k-1]+='a'-'A';
	printf("%s\n", s);
}


Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
   int i,l,k=0,num;
   char data[10];

   scanf("%s",data);
   l=strlen(data);

   for(i=0;i<l;i++)
      k+=data[i]-'0';

   num=atoi(data);

   if(num%k==0) printf("Yes\n");
   else printf("No\n");
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
typedef long long ll;

int ar[maxn];
int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    ll x;
    cin >> x;
    ll cnt = 0;
    ll base = 100;
    while(base < x){
        base = base * 1.01;
        cnt++;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    map<ll, int> mp;
    ll ans = 0ll;
    for(ll i=0; i<n; i++) {
        ll x; cin >> x;
        ans += mp[i-x];
        mp[i+x]++;
    }

    cout << ans << endl;
}

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

signed main () {
    int n, m;
    cin >> n >> m;
    vector < vector < int > > open(n + 1);
    vector < set < int > > close(n + 1); // sort of scanline
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        open[a].push_back(b);
        close[b].insert(a);
    }
    int ans = 0;
    vector < pair < int, int > > cur;
    for (int i = 0; i <= n; ++i) {
        if (!close[i].empty()) {
            for (auto ab: cur) {
                int a = ab.first, b = ab.second;
                close[b].erase(a);
            }
            cur.clear();
            ++ans;
        }
        for (int b: open[i]) 
            cur.push_back(make_pair(i, b));
    }
    cout << ans << '\n';
}


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

int main(){
  int n;
  vector<int> p(21);

  cin >> n;
  for(int i=0; i<n; i++) cin >> p[i];
  
  int cnt = 0;
  for(int i=0; i<n-2; i++){
    if(p[i] < p[i+1] && p[i+1] < p[i+2]){
      cnt++;
    } else if (p[i] > p[i+1] && p[i+1] > p[i+2]){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int H, W;
            string[] s = Console.ReadLine().Split(' ');
            H = int.Parse(s[0]);
            W = int.Parse(s[1]);

            string[] str = new string[H];

            for(int i = 0; i < H; i++)
            {
                str[i] = Console.ReadLine();
            }

            for(int i = 0; i < W+2; i++)
            {
                Console.Write("#");
            }
            Console.WriteLine();
            
            for(int i = 0; i < H; i++)
            {
                Console.WriteLine("#" + str[i] + "#");
            }

            for (int i = 0; i < W+2; i++)
            {
                Console.Write("#");
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
class Msort
  attr_reader :arr, :count

  def initialize(arr)
    @arr = arr
    @count = 0
  end

  def exec(l=0, r=arr.length-1)
    if l < r
      mid = (r - l) / 2 + l
      exec(l, mid)
      exec(mid+1, r)
      merge(l, mid, r)
    end
  end

  def merge(left, mid, right)
    l = @arr[left..mid]
    r = @arr[mid+1..right]
    tl = l.shift
    tr = r.shift
    result = []
    loop do
      break if [tl, tr].all?(&:nil?)
      @count += 1
      if tl.nil?
        result << tr
        tr = r.shift
        next
      end
      if tr.nil?
        result << tl
        tl = l.shift
        next
      end
      if tl.number <= tr.number
        result << tl
        tl = l.shift
      else
        result << tr
        tr = r.shift
      end
    end
    (left..right).each.with_index(0) do |i, idx|
      @arr[i] = result[idx]
    end
  end

  def out
    arr.map do |c|
      "#{c.type} #{c.number}"
    end
  end
end

class Qsort
  attr_reader :arr

  def initialize(arr)
    @arr = arr
  end

  def exec(l=0, r=arr.length-1)
    if l < r
      q = partition(l, r)
      exec(l, q-1)
      exec(q+1, r)
    end
  end

  def partition(l, r)
    q = @arr[r].number
    i = l - 1
    (l..r-1).each do |j|
      if @arr[j].number <= q
        i += 1
        @arr[i], @arr[j] = @arr[j], @arr[i]
      end
    end
    @arr[i+1], @arr[r] = @arr[r], @arr[i+1]
    i+1
  end

  def out
    arr.map do |c|
      "#{c.type} #{c.number}"
    end
  end
end

class Card
  attr_reader :number, :type
  def initialize(number, type)
    @number = number
    @type = type
  end
end

n = gets.to_i
arr = []
n.times do
  t, n = gets.split
  arr << Card.new(n.to_i, t)
end
q = Qsort.new(arr.dup)
m = Msort.new(arr.dup)
q.exec
m.exec
qresult = q.out
mresult = m.out
puts qresult.join(' ') == mresult.join(' ') ? 'Stable' : 'Not stable'
qresult.each(&method(:puts))



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

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int z = (S-x-y);
            if(z < 0 || z > K)continue;
            if(x+y+z == S){
                ans++;
                //printf("x=%d,y=%d,x=%d\n", x,y,z);
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    int A,B,C;
    A = a+b;
    B = a-b;
    C = a*b;
    vector<int> ans{A,B,C};
    sort(ans.begin(),ans.end());
    cout << ans.at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
char arr[1005][1005];
int dist[1005][1005], dr[] = {1,-1,0,0}, dc[] = {0,0,1,-1};
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int R, C;
	cin >> R >> C;
	int ri, ci, re, de;
	cin >> ri >> ci >> re >> de;
	for(int i=1; i<=R; i++) {
		cin >> (arr[i]+1);
	}
	auto ok = [&](int r, int c) {
		return 1 <= r && r <= R && 1 <= c && c <= C && arr[r][c] == '.';
	};
	memset(dist, 0x3f, sizeof dist);
	dist[ri][ci] = 0;
	deque<pair<int, int>> dq;
	dq.push_front({ri, ci});
	while(dq.size()) {
		auto [r, c] = dq.front();
		dq.pop_front();
		for(int i=0; i<4; i++) {
			int tr = r + dr[i], tc = c + dc[i];
			if(ok(tr, tc) && dist[tr][tc] > dist[r][c]) {
				dist[tr][tc] = dist[r][c];
				//printf("move from %d, %d to %d %d with no cost\n", r, c, tr, tc);
				dq.push_front({tr, tc});
			}
		}
		for(int i=-2; i<=2; i++) {
			for(int j=-2; j<=2; j++) {
				if(!i && !j) continue;
				int tr = r + i, tc = c + j;
				if(ok(tr, tc) && dist[tr][tc] > dist[r][c] + 1) {
					dist[tr][tc] = dist[r][c] + 1;
					dq.push_back({tr, tc});
				}
			}
		}
	}
	cout << ((dist[re][de] < 0x3f3f3f3f) ? dist[re][de] : -1);
}

Measured memory_bytes: 12684
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector< vector<int> > g(n);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int> komp(n, -1);
	int kompKnt = 0;
	vector<int> mik(n, -1);
	
	function<void(int, int, int)> dfs = [&](int v, int p, int kol) {
		komp[v] = kol;
		if (mik[kol] < 0 || a[v] < a[mik[kol]]) {
			mik[kol] = v;
		}
		for (int to: g[v]) {
			if (to != p) {
				dfs(to, v, kol);
			}
		}
	};
	
	for (int i = 0; i < n; i++) {
		if (komp[i] < 0) {
			dfs(i, -1, kompKnt);
			kompKnt++;
		}
	}
	
	if (kompKnt == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	if (n - 2*kompKnt + 2 < 0) {
		cout << "Impossible" << endl;
		return 0;
	}
	
	int64_t soom = 0;
	
	vector<char> used(n, true);
	for (int i = 0; i < kompKnt; i++) {
		used[mik[i]] = false;
		soom += a[mik[i]];
	}
	
	vector<int> q;
	for (int i = 0; i < n; i++) {
		if (used[i]) {
			q.push_back(a[i]);
		}
	}
	sort(q.begin(), q.end());
	for (int i = 0; i < kompKnt - 2; i++) {
		soom += q[i];
	}
	
	cout << soom << endl;
	return 0;
}

Measured memory_bytes: 7676
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  double x, h;
  while (cin >> x >> h, x) {
    cout << prec(8) << x * x + x * hypot(h, x / 2) * 2 << endl;
  }
}

Measured memory_bytes: 3196
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

struct st {
    size_t a, b;
};

int main ()
{
    size_t n, m;
    cin >> n >> m;
    vector<size_t> h (n);
    for (size_t i = 0; i < n; i++) {
        cin >> h[i];
    }
    vector<st> st (m);
    for (size_t i = 0; i < m; i++) {
        cin >> st[i].a >> st[i].b;
    }
    // 良くないを見つけて逆を取る
    vector<bool> ng (n, false);
    for (size_t i = 0; i < m; i++) {
        auto a = st[i].a - 1;
        auto b = st[i].b - 1;
        if (h[a] < h[b]) {
            ng[a] = true;
        } else if (h[b] < h[a]) {
            ng[b] = true;
        } else {
            // 等しい場合は両方良くない
            ng[a] = ng[b] = true;
        }
    }
    cout << count_if (ng.begin (), ng.end (), [] (bool x) { return !x; });
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int main() {
    
    int x;
    int blood[4]={0};
    
    while(cin>>x){
        string abo;
        cin>>abo;
        if(abo==",A")blood[0]++;
        if(abo==",B")blood[1]++;
        if(abo==",AB")blood[2]++;
        if(abo==",O")blood[3]++;
    }
    for(int i=0; i<4; i++)cout<<blood[i]<<endl;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1001
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){

    fast;

    ll n,m,i;
    cin >> n >> m;

    ll sum = 0;
    for(i=0;i<m;i++){
        ll a1;
        cin >> a1;
        sum = sum + a1;
    }

    if(sum>n){
        cout << -1 << endl;
    }
    else{
        cout << n-sum << endl;
    }

}










Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=205, maxx=1e5+5;
const LL mo=1e9+7;

int n,x,a[maxn];

bool cmpA(int a,int b) {return a>b;}

LL f[maxn][maxx];
int main()
{
	scanf("%d %d",&n,&x);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmpA);
	
	f[0][x]=1;
	fo(i,0,n-1)
	{
		fo(j,0,x)
		{
			(f[i+1][j]+=f[i][j]*(n-i-1))%=mo;
			(f[i+1][j%a[i+1]]+=f[i][j])%=mo;
		}
	}
	
	LL ans=0;
	fo(j,0,x) (ans+=f[n][j]*j)%=mo;
	
	printf("%lld\n",ans);
}

Measured memory_bytes: 157184
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
using namespace std;
long long n,ans,a,b,sum,mi;
#define inf 1e18
int main()
{
	scanf("%lld",&n);
	mi=inf;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a,&b);
		sum+=a;
		if(a>b)
			mi=min(mi,b);
	}
	printf("%lld\n",mi==inf?0:sum-mi);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
	int t;
	// cin>>t;
	t=1;
	while(t--)
	{
		int n;
		cin>>n;
		int a[n];
		int res=0;
		int mod=1000000007;
		for(int i=0;i<n;i++)
			cin>>a[i];
		int pp[n];
		pp[0]=a[0];
	    for(int i=1;i<n;i++)
	    {
	    	pp[i]=(pp[i-1]+a[i])%mod;
	    }
	    for(int i=0;i<n;i++)
	    {
	    	res=res%mod+(a[i]%mod*(pp[n-1]-pp[i]+mod)%mod)%mod;
	    	res=res%mod;
	    }
	    cout<<res;
	}
}

Measured memory_bytes: 6760
def main
  n, m = gets.split(" ").map(&:to_i)
  arr = Array.new(n + 1, 0)
  coins = gets.split(" ").map(&:to_i)
  buf = [0]
  count = 0
  while arr.last == 0
    temp = []
    buf.each{|i|
      coins.each{|j|
        if i + j <= n and arr[i + j] == 0
          arr[i + j] = count + 1
          temp << i + j
        end
      }
    }
    buf = temp
    count += 1
  end
  puts arr.last
end
main

Measured memory_bytes: 6844
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
const int N=2e5+5;
int n,m,x,y,rd[N][2],cnt,head[N],vis[N],num; char s[N];
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y; e[cnt].nxt=head[x]; head[x]=cnt;}
int main(){
	scanf("%d%d%s",&n,&m,s+1);
	while (m--) scanf("%d%d",&x,&y),adde(x,y),adde(y,x),rd[x][s[y]-'A']++,rd[y][s[x]-'A']++;
	queue<int> q;
	rep (i,1,n) if (!rd[i][0]||!rd[i][1]) q.push(i),vis[i]=1;//只有连向B的边/A 
	while (!q.empty()){
		int u=q.front(); q.pop(); num++;
		for (int i=head[u],v;i;i=e[i].nxt){
			v=e[i].to;
			if (!--rd[v][s[u]-'A']&&!vis[v]) vis[v]=1,q.push(v);
		}
	}
	puts(num!=n?"Yes":"No");
	return 0;
}
//找形如AABB的环 
//用类似拓扑排序的方法做，对某个点记录A/B连向它的度 

Measured memory_bytes: 7040
#include <iostream>

using namespace std;

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	
	int a = (n - 1) / h + 1;
	int b = (n - 1) / w + 1;
	int min = (a < b) ? a : b;
	
	cout << min;
}

Measured memory_bytes: 384
# coding:utf-8

import math

def main():
    n = int(raw_input())
    cnt = n # TODO: edit here
    ps = []
    for i in range(cnt):
        a,b = map(int, raw_input().split())
        ps.append([b,a])
    ps.sort()
    total = None
    chk = True
    now = 0
    for i in ps:
        tmp = i[0] - i[1]
        if total == None:
            if tmp >= 0:
                total = tmp
                now = i[0]
            else:
                chk = False
                print "No"
                break
        else:
            total = total + i[0] - now - i[1]
            now = i[0]
            if total < 0:
                chk = False
                print "No"
                break
    if chk:
        print "Yes"

if __name__ == "__main__":
    main()



Measured memory_bytes: 39556
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 300;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int x, y;
    cin >> x >> y;
    y /= x;
    int ans = 0;
    while(y){
        y /= 2;
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	char ar[n+1];
	cin>>ar;
	if(n%2==0){
		i=0; j=(n/2);
		while(j<n){
			if(ar[i]!=ar[j]) break;
			i+=1; j++;
		}
		if(j<n){
			cout<<"No"<<endl;
		}
		else cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
// Ivan Zanov
// Template
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std :: chrono;
#define lowest_bit(x) ((x)&((x)^((x)-1)))
#define max(a,b) (a<b?b:a)
#define min(a,b) (a<b?a:b)
#define IOS ios_base::sync_with_stdio(0);
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define INF (int)1e9
#define EPS (int)1e-9
#define bit_count __builtin_popcount
#define gcd __gcd
#define max3(a, b, c) max(a, max(b,c))
#define min3(a, b, c) min(a, min(b,c))
#define abs(x) (x < 0 ? (-x) : x)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
inline void set_bit(int & n, int b) { n |= (1 << (int) b); }
inline void unset_bit(int & n, int b) { n &= ~(1 << (int) b); }
inline bool check_bit(int n, int pos) { return ( n & (1 << (pos))); }
inline ll lcm(ll a, ll b){ return (a * b / gcd(a,b));}
inline ll square(ll a){return (a * a);}
int main() {
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	str[k - 1] = tolower(str[k - 1]);
	cout<<str<<endl;
	//auto start = high_resolution_clock::now();
	/*auto end = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start);
	cout<<fixed<<setprecision(3)<<duration.count() * 1e-6<<endl;*/
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, k, n) for(ll i = k; i < n; i++)

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

  ll ans = 0;
  rep(i, 1, n+1){
    ans += i * (((n/i) * (n/i + 1))/2);
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 3636
# coding: utf-8
if __name__=='__main__':
    n = int(input())
    w = list(map(int,input().split()))
    a,b = 0,n-1
    # S1 = w[0] S2 = w[n-1]
    M = w[0]-w[n-1] # M:=S1-S2
    for i in range(n-2):
        if M < 0: # S1 <= S2:
            a +=1
            M += w[a] # S1 += w[a]
        else:
            b -=1
            M -= w[b] # S2 += w[b]
    print(abs(M))

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string aim[] = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) reverse(aim[i].begin(), aim[i].end());
    string S; cin >> S; reverse(S.begin(), S.end());
    for(int i = 0; i < S.length();){
        bool ok = false;
        rep(j, 4){
            bool same = true;
            rep(k, aim[j].length()){
                if(i+k >= S.length() || S[i+k] != aim[j][k]) same = false; 
            }
            if(same){
                ok = true;
                i += aim[j].length();
            }
        }
        if(!ok){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int m;
  short dice;
  short west;
  short east;
  short north;
  short south;
  short back;
  short dice2;
  int a;
  char b[5];
  char n = 'n';
  char s = 's';
  char w = 'w';
  char e = 'e';

  while(1){
    dice = 1;
    west = 3;
    east = 4;
    north = 2;
    south = 5;
    back = 6;
    scanf("%d",&m);
    if(m == 0){
      break;
    }

    while(m-- > 0){
      scanf("%s",b);

      if(b[0] == n){
        dice2 = south;
        south = back;
        back = north;
        north = dice;
        dice = dice2;
      }
      else if(b[0] == s){
        dice2 = north;
        north = back;
        back = south;
        south = dice;
        dice = dice2;
      }
      else if(b[0] == w){
        dice2 = east;
        east = back;
        back = west;
        west = dice;
        dice = dice2;
      }
      else if(b[0] == e){
	dice2 = west;
        west = back;
        back = east;
	east = dice;
        dice = dice2;
      }

    }
    printf("%d\n",dice);
  }
  return 0;
}

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

int main(void)
{
    int a, b;
    char op;
    while(true){
        cin >> a >> op >> b;
        if(op == '?'){
            break;
        }
        if(op == '+'){
            cout << (a + b) << endl;
        }
        if(op == '-'){
            cout << (a - b) << endl;
        }
        if(op == '*'){
            cout << (a * b) << endl;
        }
        if(op == '/'){
            cout << (a / b) << endl;
        }
      } 
    }



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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

class Segtree {
public:
    int n;
    vector<int> nodes;
    Segtree(int _n) {
        n = 1 << (int)ceil(log2(_n));
        nodes.resize(n*2-1, -INT_MAX);
    }
    void set(int i, int v) {
        i += n - 1;
        nodes[i] = v;
        while (i > 0) {
            i = (i-1) / 2;
            nodes[i] = max(nodes[i*2+1], nodes[i*2+2]);
        }
    }
    int get_max(int l, int r) {
        return get_max(l, r, 0, 0, n);
    }
    int get_max(int l, int r, int i, int tl, int tr) {
        if (tr <= l || r <= tl) return -INT_MAX;
        if (l <= tl && tr <= r) return nodes[i];
        int t1 = get_max(l, r, i*2+1, tl, (tl+tr)/2);
        int t2 = get_max(l, r, i*2+2, (tl+tr)/2, tr);
        return max(t1, t2);
    }
};

int ps[100010][4];

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

    int N;
    cin >> N;
    vector<int> P(N);
    for (int i=0; i<N; ++i) {
        cin >> P[i];
    }

    Segtree tr1(N+1);
    for (int i=0; i<N; ++i) {
        int j = tr1.get_max(P[i]+1, N+1);
        if (j == -INT_MAX) {
            ps[i][0] = ps[i][1] = -1;
        } else {
            ps[i][1] = j;
            tr1.set(P[j], -INT_MAX);
            int k = tr1.get_max(P[i]+1, N+1);
            ps[i][0] = (k == -INT_MAX ? -1 : k);
            tr1.set(P[j], j);
        }
        tr1.set(P[i], i);
    }

    Segtree tr2(N+1);
    for (int i=N-1; i>=0; --i) {
        int j = tr2.get_max(P[i]+1, N+1);
        if (j == -INT_MAX) {
            ps[i][2] = ps[i][3] = N;
        } else {
            ps[i][2] = -j;
            tr2.set(P[-j], -INT_MAX);
            int k = tr2.get_max(P[i]+1, N+1);
            ps[i][3] = (k == -INT_MAX ? N : -k);
            tr2.set(P[-j], j);
        }
        tr2.set(P[i], -i);
    }

    long long res = 0;
    for (int i=0; i<N; ++i) {
        if (ps[i][1] == -1 && ps[i][2] == N) continue;
        if (ps[i][1] != -1) {
            long long l = (long long)(ps[i][2] - i) * (ps[i][1] - ps[i][0]);
            res += (long long)P[i] * l;
        }
        if (ps[i][2] != N) {
            long long r = (long long)(i - ps[i][1]) * (ps[i][3] - ps[i][2]);
            res += (long long)P[i] * r;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4224
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int L=sc.nextInt();
        int R=sc.nextInt();
            int d=sc.nextInt();
        if(L%d==0){
            System.out.println(R/d-L/d+1);
        }else{
            System.out.println(R/d-L/d);
        }
    }
}

Measured memory_bytes: 35668
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main{
	
	static int h,w;
	static Deque <Point> que;
	static char [][]map;
	static int d[][];
	static boolean [][]visit;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		h = Integer.parseInt(sc.next());
		w = Integer.parseInt(sc.next());
		
		map = new char [h][w];
		d = new int [h][w];
		visit = new boolean [h][w];
		
		for(int i = 0 ; i < h ;i++) {
			String s = sc.next();
			for(int j = 0 ; j < w ;j++) {
				map[i][j] = s.charAt(j);
				d[i][j] = 1000000000;
			}
		}
		
		
		que = new ArrayDeque<Point>();
		
		for(int i = 0 ; i < h ;i++) {
			for(int j = 0 ; j < w ;j++) {
				if(map[i][j] == '#') {
					que.addLast(new Point(i,j));
					d[i][j] = 0;
					visit[i][j] = true;
				}
			}
		}
		BFS(que.poll());
		int max = 0;
		
		for(int i = 0 ; i < h ;i++) {
			for(int j = 0 ; j < w ;j++) {
				max = Math.max(d[i][j], max);
			}
		}
		
		System.out.println(max);
	}
	
	static void BFS(Point e) {
		
		int x = e.getX();  int y = e.getY();
		
		int []dx = {1,0,-1,0};
		int []dy = {0,1,0,-1};
		
		for(int i = 0 ; i < 4 ;i++) {
			if(dy[i] + y < 0 || dy[i] + y >= h) {
				continue;
			}
			if(dx[i] + x < 0 || dx[i] + x >= w) {
				continue;
			}
			int py = dy[i] + y;
			int px = dx[i] + x;
			if(visit[py][px]) {
				continue;
			}
			d[py][px] = d[y][x] + 1;
			visit[py][px] = true;
			que.addLast(new Point(py,px));
		}
		
		if(que.size() == 0) {
			return;
		}
		
		BFS(que.poll());
		
	}
}
class Point {
	private int y;
	private int x;
	
	public Point(int y , int x) {
		this.y = y;
		this.x = x;
	}
	
	public int getY() {
		return y;
	}
	public int getX() {
		return x;
		}
	}



Measured memory_bytes: 181728
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (a, b) = parse_line!(u32, u32);
    let sub = a + b;
    if sub % 2 == 0 {
        println!("{}", sub / 2);
    } else {
        println!("IMPOSSIBLE",);
    }
}


Measured memory_bytes: 4352
N, M, X = map(int, input().split())
A_LIST = list(map(int, input().split()))

cost1 = 0
cost2 = 0
for i in A_LIST:
    if i > X:
        cost1 += 1
    elif i < X:
        cost2 += 1

print(min(cost1, cost2))

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <string>

using namespace std;

struct Process{
    string name;
    int time;
};

int main(void){
    queue<Process> que;
    int n, q;
    int i;
    Process tmp;
    int lapsed = 0;
    
    cin >> n >> q;
    for(i = 0; i < n; i++){
        cin >> tmp.name >> tmp.time;
        que.push(tmp);
    }
    
    while(!que.empty()){
        tmp = que.front(); que.pop();
        
        if(tmp.time <= q){
            lapsed += tmp.time;
            cout << tmp.name << " " << lapsed << endl;
        } else {
            tmp.time -= q;
            lapsed += q;
            que.push(tmp);
        }
    }
    
    return 0;
}

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

int main(){
  long long n,k;cin>>n>>k;
  map<long long, long long> mp;

  REP(i,n){
    long long a,b;cin>>a>>b;
    mp[a]+=(long long)b;
  }
  
  for(auto p:mp){
    //cout<<p.first<<" "<<p.second<<endl;
    if(p.second<k) k-=p.second;
    else{
      cout<<p.first;
      break;
    }
  }
  
}

Measured memory_bytes: 4224
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
#print(H)
H.sort()
#print(H)
Ans = 0
for x in range(0,min(K,N)):
#    print(x)
    H.pop()
#print(H)
for x in H:
    Ans = x+Ans
print(Ans)

Measured memory_bytes: 26764