akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<30;

int bit[MAX+1],N;

//1-indexed

int sum(int i){
    int s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

//sからtの和=sum(t)-sum(s-1)

void add(int i,int x){
    while(i<=N){
        bit[i]+=x;
        i+=i&-i;
    }
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    vector<pair<int,int>> A(N);
    for(int i=0;i<N;i++){
        A[i].first=i+1;
        cin>>A[i].second;
    }
    
    sort(all(A),[](pair<int,int> a,pair<int,int> b){
        return a.second>b.second;
    });
    
    int ans=0;
    
    for(int i=0;i<N;i++){
        add(A[i].first,1);
        if(sum(A[i].first)==A[i].first) ans++;
    }
    
    cout<<ans<<endl;
}




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

int main() {
	ll n;
	cin >> n;
	vector<ll> p(n);
	for (ll i = 0; i < n; ++i)cin >> p[i];
	ll  Min = n + 1;
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		if (p[i] <= Min) {
			++ans;
			Min = p[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long Int;

const int N = 1000000;
const int M = 1000;
const int K = 6000000;

vector<Int> iterativeSieve(){
    static int p[K], table[M];
    for(int i=2; i<M; i++) p[i] = i;
    for(int i=2; i*i<M; i++){
        if(p[i]){
            for(int j=i*i; j<M; j+=i){
                p[j] = 0;
            }
        }
    }
    p[0] = p[1] = 0;
    int num = remove(p, p+M, 0) - p;
    for(int m=M; m<N; m+=M){
        for(int x=m; x<m+M; x++){
            table[x-m] = x;
        }
        for(int i=0,j; p[i]*p[i]<m+M; i++){
            if(p[i] >= m)          j = p[i] * p[i];
            else if(m % p[i] == 0) j = m;
            else                   j = m - (m % p[i]) + p[i];
            for(; j<m+M; j+=p[i])  table[j-m] = 0;
        }
        num = remove_copy(table, table+M, p+num, 0) - p;
    }
    return vector<Int>(p, p+num);
}

int main(){
    vector<Int> prime = iterativeSieve();
    int n, cnt;

    while(cin >> n){
        cnt = 0;
        for(int i=0; prime[i] <= n && i < prime.size(); i++){
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 0
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    N,M = LI()
    XY = []
    for _ in range(M):
        XY.append(LI())

    possibility = [[False,1] for _ in range(N)]
    possibility[0] = [True,1]

    for x,y in XY:
        if possibility[x-1][0]:
            possibility[y-1][0] = True
        possibility[x-1][1] -= 1
        possibility[y-1][1] += 1

        if possibility[x-1][1] == 0:
            possibility[x-1][0] = False

    ans = 0
    for i in range(N):
        if possibility[i][0]:
            ans += 1
    return(ans)

if __name__ == "__main__":
    print(main())


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

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

    int f = (S[0] - '0') * 10 + S[1] - '0';
    int s = (S[2] - '0') * 10 + S[3] - '0';

    if(f < 13 && s < 13 && f != 0 && s != 0) {
        cout << "AMBIGUOUS" << endl;
    } else if((f >= 13 || f == 0) && s < 13 && s > 0) {
        cout << "YYMM" << endl;
    } else if(f < 13 && f > 0 && (s >= 13 || s == 0)) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
}

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


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

	double ans=0;
	rep(i,n){
		double point = i+1;
		double p=1.0/n;
		while(point <= k-1){
			point = point * 2;
			p = p * 1/2;
		}
		ans += p;
	}
	printf("%.10lf\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s,t;
    cin>>n>>s>>t;
    int cnt=0;
    rep(i,n){
      if(s.substr(i,n-i)==t.substr(0,n-i)){
        cnt=n-i;
        break;
      }
    }
    cout<<2*n-cnt<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());
		
		int ans = B*(T/A);
		System.out.println(ans);
		
		
		sc.close();
	}
	
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int x;
  cin >> x;
  ll n = 0;
  while(1){
    ll k = n * (n + 1) / 2;
    if(k >= x) break;
    n++;
  }
  cout << n << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
typedef long long int lli;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define JUGAD freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define N 100001
#define mod 1000000007
using namespace std;

vector<vector<int>> v(N);
bool vis[N];
int n,m,ans=0;

void dfs(int x){
    if(vis[x]==1){return;}
    vis[x]=1;
    for(int i=0;i<v[x].size();i++){
        int a=v[x][i];
        dfs(a);
    }
}

int main(){
    FAST;
    cin>>n>>m;
    while(m--){
        int a,b;cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1;i<=n;i++){
        if(vis[i]){continue;}
        ans++;
        dfs(i);
    }
    cout<<ans-1<<endl;
}


Measured memory_bytes: 9124
#include <iostream>
#include<math.h>
using namespace std;
typedef long long ll;

int main() {
	ll input_num,s;
	cin >> input_num;
	cout << input_num << ":";
	s = floor(sqrt(input_num));
	for (int i = 2; i <= s; i++) {
		if (input_num % i == 0) {
			cout << " " << i;
			input_num = input_num / i;
			while(input_num % i == 0){
				cout << " " << i;
				input_num = input_num / i;
			}
			if (input_num == 1) {
				break;
			}
		}
	}
	if (input_num != 1) {
		cout << " " << input_num;
	}
	cout << endl;
	return 0;
}

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

const int maxn=100005;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(a[j]!=a[i])
                {
                    for(int k=j+1;k<n;k++)
                    {
                        if(a[k]!=a[j])
                        {
                            if((a[i]+a[j])>a[k])
                            {
                                ans++;
                            }
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=4100;
int n;char s[maxn];
int main(){
    ll r=0,g=0,b=0;
    cin>>n>>s+1;
    ///cout<<s;
    for(int i=1;i<=n;i++){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }

    ll sum=r*g*b;
    int k=(n-3)/2;
    for(int i=0;i<=k;i++)
        for(int j=1;j+2*i+2<=n;j++)
            if(s[j]!=s[j+i+1]&&s[j+i+1]!=s[j+2*i+2]&&s[j]!=s[j+2*i+2])
                sum--;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3588
# dp[n][i][j]=(頂点iから頂点jへ行く長さnのパスの個数)
# dp[n][i][j]=sum(dp[n-1][i][k]*a[k][j])⇒DP[n]=DP[n-1]*A DP[0]=Eより DP[n]=A^n
n,k=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*n for i in range(n)]
mod=10**9+7
for i in range(n):
    for j in range(n):
        dp[i][i]=1
def dot(A,B):
    C=[[0]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                C[i][j]+=A[i][k]*B[k][j]
            C[i][j]%=mod
    return C
while k:
    if k&1:
        dp=dot(dp,a)
    a=dot(a,a)
    k>>=1
ans=0
for i in dp:
    ans+=sum(i)
print(ans%mod)


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

int main() {
	long int a,b;
	cin>>a>>b;
	if(a==b)
	cout<<a;
	else{
	    int s=(a+b)/2;
	    if(abs(a-s)==abs(b-s))
	     cout<<s;
	     else
	     cout<<"IMPOSSIBLE";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long

class UnionFind{
public:
	vector<int> Parent;
	UnionFind(int N){
		Parent = vector<int> (N,-1);
	}
	int root(int A){
		if(Parent[A]<0)return A;
		return Parent[A] = root(Parent[A]);
	}
	int size(int A){
		return Parent[root(A)];
	}
	bool connect(int A,int B){
		A = root(A);
		B = root(B);
		if(A==B)return false;
		if(size(A)<size(B))swap(A,B);
		Parent[A] += Parent[B];
		Parent[B] = A;
		return true;
	}
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	vector<int> p(N+1);
	UnionFind Uni(N+2);
	for(int i=1;i<=N;i++){
		int a;
		cin >> a;
		p[a] = i;
	}
	for(int i=0;i<M;i++){
		int x,y;
		cin >> x >> y;
		Uni.connect(x,y);
	}
	int ans = 0;
	for(int i=1;i<=N;i++){
		if(Uni.root(i)==Uni.root(p[i]))ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main()
{
	//freopen("in,txt", "r",stdin);
	//freopen("out.txt" ,"w", stdout);
	int n; cin >> n;
  	if(n > 999) cout << "ABD";
  else cout << "ABC";
	
	
	
}

Measured memory_bytes: 256
S = input()
N = len(S)
c = 0
ans = [0] * N
i = 0
while i < N:
  if S[i] == 'R':
    while S[i] == 'R':
      c += 1
      i += 1
    ans[i] += c // 2
    ans[i-1] += c // 2 + c % 2
    c = 0
  i += 1
i -= 1
while i >= 0:
  if S[i] == 'L':
    while S[i] == 'L':
      c += 1
      i -= 1
    ans[i] += c // 2
    ans[i+1] += c // 2 + c % 2
    c = 0
  i -= 1
for j in range(N):
  print(ans[j], end = ' ')

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll x,y;
  	ci(x>>y);
  ll ans=INF;
  ll z=0;
  FOR(i,0,M(x,y)+1){
	chmin(ans,i*2*c+a*max(z,x-i)+b*max(z,y-i));
  }
  co(ans)
}


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

	int main(){
	int a,b,k;
	cin >> a >> b >> k;
	for(int i = a; i <= min(b,a+k-1);i++){
		cout << i << endl;
	}
	for(int i = max(b-k+1,a+k); i <= b;i++){
		cout << i << endl;
	}
}


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


int main(){
  string s;
  cin >> s;
  int n,i;
  n=s.size();
  string ans;
  for(i=1;i<=n;++i){
    if(i%2==1){
      ans+=s[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	double t, v, h, f;
	while (cin >> v) {
		t = v / 9.8;
		h = 4.9 * t * t;
		f = ceil(h / 5 + 1);
		cout << f << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>

int main ()


{


int a=0;


int W,H,x,y,r=0;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(x-r>=0&&x+r<=W){


if(y-r>=0&&y+r<=H){


a=1;


}


}


else{


a=0;


}


if(a==1){


printf("Yes\n");


}


else if(a==0){


printf("No\n");


}


return 0;


}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 1000000), B(N - 1);
    ll ans = 0;
    rep(i, N - 1)
    {
        cin >> B.at(i);
        A.at(i + 1) = B.at(i);
        if (A.at(i) > B.at(i))
        {
            A.at(i) = B.at(i);
        }
        ans += A.at(i);
    }
    ans += A.at(N - 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
# a=int(input())
lmax=0
rmin=a
for i in range(b):
    l,r = map(int,input().split())
    if l >= lmax:
        lmax = l
    if r <= rmin:
        rmin = r
print(max(rmin-lmax+1,0))

Measured memory_bytes: 3060
L = list(map(int, list(input())))

def dfs(ans, index, cnt):
    if index == 0:
        return dfs(ans + str(L[index]), index + 1, cnt + L[index])
    if index == 4:
        if cnt == 7:
            return ans + '=7'
        else:
            return False
    ans1 = dfs(ans + '+' + str(L[index]), index+1, cnt + L[index])
    ans2 = dfs(ans + '-' + str(L[index]), index+1, cnt - L[index])
    if ans1:
        return ans1
    if ans2:
        return ans2
    return False

ans = dfs('', 0, 0)
print(ans)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N;
ll A[202020], B[202020];
vector<ll> xA,xB;
vector<ll> mk, mk2;
ll i, j, k, ans;

//Zアルゴリズム
template<class t>
void Zalgo(const vector<t>& S,const vector<t>& T,vector<ll>& ln1,const vector<ll>& ln2){
    ll i = 1;
    ll j = 0;
    ll k = 0;
    ll Sn = S.size();
    ll Tn = T.size();
    while(i<Sn){
        //printf("%lld %lld\n", i, j);
        if(i+ln2[i-j]<j+ln1[j]){
            ln1[i] = ln2[i - j];
        }else{
            k = max(j + ln1[j] - i, 0ll);
            while (k<Tn&&i + k < Sn && T[k] == S[i + k])
                k++;
            ln1[i] = k;
            j = i;
        }
        i++;
    }
    ll N = min(Sn, Tn);
    fornum(i,0,N){
        if(S[i]!=T[i])
            break;
    }
    ln1[0] = i;
}


int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        scanf("%lld", &B[i]);
    }
    xA.resize(N * 2);
    xB.resize(N * 2);
    mk.resize(N * 2);
    mk2.resize(N * 2);

    fornum(i,0,N){
        xA[i] = xA[i + N] = xA[i] = A[(i + 1) % N] ^ A[i];
        xB[i] = xB[i + N] = xB[i] = B[(i + 1) % N] ^ B[i];
    }
    
    Zalgo(xB, xB, mk, mk);
    Zalgo(xA, xB, mk2, mk);
    

    fornum(i,0,N){
        if(mk2[i]>=N){
            printf("%lld %lld\n", i, A[i] ^ B[0]);
        }
    }

    return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;

  if (A == B || B == C || C == A) {
    if (A == B && B == C && C == A)
     cout << "No" << endl;
    else
     cout << "Yes" <<endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int A[100];

int main()
{
    int N, i, M, total, counter;

    scanf("%d%d", &N, &M);
    total = 0;
    for(i = 0; i < N; ++i){
        scanf("%d", &A[i]);
        total += A[i];
    }
    counter = 0;
    for(i = 0; i < N; ++i)
        if(A[i] * (4 * M) >= total)
            ++counter;

    printf((counter >= M) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool is(string a){
    string b = a;
    reverse(b.begin(), b.end());
    return a == b;
}

string s;
int main(){
    cin>>s;
    int ln = s.size();

    if(is(s) && 
    is(s.substr(0, (ln-1)/2)) && 
    is(s.substr((ln+3)/2-1, ln))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int cmp_int(const void* v1, const void* v2)
{
  const int _v1 = *((const int*)v1);
  const int _v2 = *((const int*)v2);

  if ( _v1 > _v2 ) {
    return 1;
  } else if ( _v1 < _v2 ) {
    return -1;
  } else {
    return 0;
  }
}
 
int main(void){
    int n;
    scanf("%d",&n);
    int a[n],b[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
        b[i]=a[i]-(i+1);
    }
    qsort (b,n,sizeof(int),cmp_int);
    long long int ans1=0,ans2=0;
    if (n%2==0){
        for (int i=0; i<n; i++){
            ans1+=abs(b[i]-b[n/2-1]);
            ans2+=abs(b[i]-b[n/2]);
        }
        if (ans1<ans2){
            printf ("%lld\n",ans1);
        } else {
            printf ("%lld\n",ans2);
        }
    } else {
        for (int i=0; i<n; i++){
            ans1+=abs(b[i]-b[(n+1)/2-1]) ;
        }
        printf ("%lld\n",ans1) ;
    }
	return 0 ;
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

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

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int ans = H * W - h * W - w * (H - h);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

typedef pair<int, int> P;
typedef long long int ll;

int a,b;

int main() {
	cin >> a >> b;
	if (a >= 0 && a <= 5) {
		cout << 0 << endl;
	}
	else if (a >= 6 && a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << b << endl;
	}


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a;
	
	while (scanf("%d",&n) !=EOF){
		a = n % 39;
		if (a == 0){
			printf("3C39\n");
		}
		else if (a >= 1 && a <= 9){
			printf("3C0%d\n",a);
		}
		else {
			printf("3C%d\n",a);
		}
	}
	
	return 0;
}

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

int main(){
    long long n, k; cin >> n >> k;
    double res = 0.0;
    for(long long i=1; i<n+1; ++i){
        double tmp = 1.0;
        long long d = i;
        while(d<k){
            d *= 2; tmp /= 2.0;
        }
        res += tmp;
    }
    res /= n;
    cout << fixed << setprecision(15) << res << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
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 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);  
  
  double r;
  cin >> r;
  cout << 3*pow(r,2) << endl;
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next, *prev;
};

Node *null;

void init(){ //双方向リストの初期化
    null = (Node *)malloc(sizeof(Node));
    null->next = null;
    null->prev = null;
}

void insert(int key){ //要素の挿入
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    //番兵の直後に要素を追加
    x->next = null->next;
    null->next->prev = x;
    null->next = x;
    x->prev = null;
}

Node* listSearch(int key){ //探索
    Node *cur = null->next;
    while (cur != null && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){ //要素の削除
    if(t == null){
        return;
    }
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){ //最初のノードを消す
    deleteNode(null->next);
}

void deleteLast(){ //最後のノードを消す
    deleteNode(null->prev);
}

void deletakey(int key){ //検索したノードを消す
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = null->next;
        int isf = 1;
    while(1){
        if ( cur == null ){
        break;
        }
        if ( isf == 0){
        printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
  printf("\n");
}

int main(){
    int key, n, i;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){
            insert(key); np++;
        }
        else if (com[0] == 'd'){
            if(strlen(com) > 6){
                if (com[6] == 'F'){
                    deleteFirst();
                }
                else if (com[6] == 'L'){
                    deleteLast();
                }
            }else{
                deletakey(key); nd++;
            }
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 33832
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int x = sc.nextInt();
      int[][] arr = new int[n][m + 1];
      for(int i = 0; i < n; i++)
        for(int j = 0; j <= m; j++)
          arr[i][j] = sc.nextInt();

      long res = Long.MAX_VALUE;
      for(int i = 0; i < (2 << n); i++) {
        int[] sum = new int[m+1];
        int cost = 0;
        for(int j = n - 1; j >= 0; j--) {
            if( (1 & i >> j) == 1) {
                cost += arr[j][0];
                for(int k = 1; k <= m; k++)
                  sum[k] += arr[j][k];
            }
        }
        boolean flag = true;
        for(int k = 1; k <= m; k++)
          if(sum[k] < x) {
            flag = false;
            break;
          }
        if(flag) res = Math.min(res, cost);
      }
      System.out.println(res == Long.MAX_VALUE ? -1: res);
  }
}

Measured memory_bytes: 28704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=100005;
int n;
int h[maxn],dp[maxn];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) cin>>h[i];
        for(int i=1;i<=n;i++)
        {
            if(i==1) dp[i]=0;
            else if(i==2) dp[i]=abs(h[2]-h[1]);
            else
            {
                dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
            }
        }
        cout<<dp[n]<<"\n";
    }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

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

int main() {
	int N, T, E;
	cin >> N >> T >> E;
	int x[N];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	int ans = -1;
	for (int i = 0; i < N; i++) {
		int diff = T % x[i];
		if (T+diff-x[i] >= T-E || T+diff <= T+E) {
			ans = i+1;
			break;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

#define ldouble long double
#define llong long long int
#define print(x) cout << x << endl
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    llong n;
	cin >> n;
	vector<llong> a(n), t(n);
	for (int i = 0; i < n; i++) cin >> t[i];
	for (int i = 0; i < n; i++) cin >> a[i];

	if (a[0] != t[n-1]){
		cout << 0 << endl;
        return 0;
	} else {
		llong ans = 1;
		for (int i = 1; i < n-1; i++) {
			if (t[i] == t[i - 1] && a[i] == a[i + 1]){
				ans *= min(t[i], a[i]);
                ans %= MOD;
			} else if (t[i] > t[i - 1] && a[i] == a[i + 1] && a[i] < t[i]){
				cout << 0 << endl;
                return 0;
			} else if (t[i] == t[i - 1] && a[i] > a[i + 1] && a[i] > t[i]){
				cout << 0 << endl;
                return 0;
			} else if (t[i] > t[i - 1] && a[i] > a[i + 1] && a[i] != t[i]){
				cout << 0 << endl;
                return 0;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

from copy import copy, deepcopy

n=int(input())
sp=[]
for i in range(n):
    s,p=input().split()
    sp.append([s,int(p)])

cities=[]
for s in sp:
    cities.append(s[0])
cities=list(set(cities))
cities.sort()

sp_=copy(sp)
sp.sort(key=lambda x:x[1], reverse=True)

for c in cities:
    for i in range(n):
        if sp[i][0]==c:
            print(sp_.index(sp[i])+1)


Measured memory_bytes: 3956
#include <iostream>

using namespace std;

int main() {
    int N;
    int sum = 0;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    return 0;
}

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

string translateJ( string k );
string translateC( string k );
string translateE( string k );
string translateA( string k );
string translateM( string k );
string translateP( string k );

int main()
{
    int n;
    string order, key;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> order >> key;
        for( int j = order.size() - 1; j >= 0; j-- )
        {
            if( order[j] == 'J' )
                key = translateJ( key );
            else if( order[j] == 'C' )
                key = translateC( key );
            else if( order[j] == 'E' )
                key = translateE( key );
            else if( order[j] == 'A' )
                key = translateA( key );
            else if( order[j] == 'P' )
                key = translateP( key );
            else
                key = translateM( key );
        }
        cout << key << endl;
    }
    return 0;
}

string translateJ( string k )
{
    char c = k[k.size() - 1];
    for( int i = k.size() - 1; i > 0; i-- )
        k[i] = k[i-1];
    k[0] = c;
    return k;
}

string translateC( string k )
{
    char c = k[0];
    for( int i = 0; i < k.size() - 1; i++ )
        k[i] = k[i+1];
    k[k.size()-1] = c;
    return k;
}

string translateE( string k )
{
    string a = "", b = "";
    int c = k.size();
    if( c % 2 == 0 )
    {
        for( int i = 0; i < c; i++ )
            i < c / 2 ? a += k[i] : b += k[i];
        return b + a;
    }
    else
    {
        for( int i = 0; i < c / 2; i++ )
            a += k[i];
        for( int i = c / 2 + 1; i < c; i++ )
            b += k[i];
        return b + k[c/2] + a;
    }
}

string translateA( string k )
{
    string r = "";
    for( int i = k.size() - 1; i >= 0; i-- )
        r += k[i];
    return r;
}

string translateM( string k )
{
    for( int i = 0; i < k.size(); i++ )
        if( '0' <= k[i] && k[i] <= '9' )
        {
            k[i]++;
            if( k[i] == '9' + 1 )
                k[i] = '0';
        }
    return k;
}

string translateP( string k )
{
    for( int i = 0; i < k.size(); i++ )
        if( '0' <= k[i] && k[i] <= '9' )
        {
            k[i]--;
            if( k[i] == '0' - 1 )
                k[i] = '9';
        }
    return k;
}


Measured memory_bytes: 3016
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 vector<ll>a;
 ll c;
 map<ll,ll>cnt;
 rep(i,0,n){
  sc(c);
  cnt[c]++;
  if(cnt[c]%2==0)push(a,c);
 }
 sort(a);
 ll len=a.size();
 ans=a[len-1]*a[len-2];
 if(len==0)ans=0;
 pr(ans);
return 0;}

Measured memory_bytes: 9680
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define inf 1e18
#define ps(x,y)  fixed<<setprecision(y)<<x  // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
int arr[100001][4] ; 
int dp[100001][4]; 
 
int  fn(int k , int i , int n  )
{
	
	if(i==n)
	{
		return 0 ; 
	}
 
	if(dp[i][k] !=-1 )
	{
		return dp[i][k] ; 
	}
	
	int ans=0 ; 
	for(int j=0 ; j<3; j++)
	{
		if(j != k)
		ans=max(ans, arr[i][j]+fn(j, i+1, n)); 
 
	}
 
	return dp[i][k]= ans; 
 
}
 
 
 
int32_t main()
{
	int n, k ; 
	cin>>n  ; 
	 
 
	for(int i=0 ; i<n ; i++)
	{
		for(int j=0 ; j<3; j++)
		{
			cin>>arr[i][j] ; 
 
		}
	}
 
	// int ans=0 ; 
 //    for(int i=0 ; i<3 ; i++)
	// {
	// 	for(int a=0 ; a<n; a++)
	// 	{
	// 		for(int b=0 ; b<3; b++)
	// 		{
	// 			dp[a][b]=-1 ; 
	// 		}
	// 	}
	// 	int z=arr[0][i]+fn( i ,1, n ) ; 
	// 	ans=max(ans, z);  
	// }
 
 // 	cout<<ans;    
 
 
	dp[0][0]=arr[0][0]; 
	dp[0][1]=arr[0][1]; 
	dp[0][2]=arr[0][2] ; 
 
	for(int i=1 ; i<n; i++)
	{
		for(int j=0 ; j<3; j++)
		{
 
			int a=dp[i-1][(j+3-1)%3]; 
			int b=dp[i-1][(j+3+1)%3] ; 
			int z=max(a, b); 
			dp[i][j]=arr[i][j]+z; 
 
		}
	}
 
	// for(int i=0 ; i<n; i++)
	// {
	// 	for(int j=0 ; j<3; j++)
	// 	{
 
	// 		cout<<dp[i][j]<<" "; 
	// 	}
	// 	cout<<endl ; 
	// }
	int ans=max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) ; 
	cout<<ans ; 
	
 
}

Measured memory_bytes: 6528
h, w = map(int, raw_input().split())
c = [map(int, raw_input().split()) for i in xrange(h)]
cnt = [[0]*w for i in xrange(h)]

for j in xrange(w):
    seq = 0
    for i in xrange(h):
        if c[i][j] == 0:
            seq += 1
        else:
            seq = 0
        cnt[i][j] = seq
ans = 0
st = [(0, -1)]
for i in xrange(h):
    for j in xrange(w):
        v = cnt[i][j]
        last = j
        while v < st[-1][0]:
            l, k = st.pop()
            last = k
            ans = max(ans, min(l, j-k))
        if st[-1][0] < v:
            st.append((v, last))
    while 0 < st[-1][0]:
        l, k = st.pop()
        ans = max(ans, min(l, w-k))
print ans**2

Measured memory_bytes: 55372
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
	int N;
	double A[1000];
	cin >> N;
	double ans = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		ans += 1 / A[i];
	}
	printf("%.12f\n", 1 / ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

double L;
int main() {
	cin >> L;
	double a = L / (3.0);
	double res = a * a * a;
	printf("%.12lf\n", res);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct element_t {
	int op;
	int val;
	friend bool operator<(const element_t& lhs, const element_t& rhs)
	{
		return lhs.op < rhs.op || (lhs.op == rhs.op && lhs.val < rhs.val);
	}
};
void disp(const element_t *e, int len)
{
	string s[4];
	int slen = 0, i;
	for (i = 0; i < 7; i ++) {
		if (e[i].op) {
			switch (e[i].op) {
			case 1:
				s[slen-2] = "(" + s[slen-2] + " + " + s[slen-1] + ")";
				slen --;
				break;
			case 2:
				s[slen-2] = "(" + s[slen-2] + " - " + s[slen-1] + ")";
				slen --;
				break;
			case 3:
				s[slen-2] = "(" + s[slen-2] + " * " + s[slen-1] + ")";
				slen --;
				break;
			}
		} else {
			char buf[10];
			sprintf (buf, "%d", e[i].val);
			s[slen++] = buf;
		}
	}
	cout << s[0] << endl;
}
int check(const element_t *e)
{
	int s[4], slen = 0, i;
	for (i = 0; i < 7; i ++) {
		if (e[i].op) {
			if (slen < 2)
				return 0;
			switch (e[i].op) {
			case 1:
				s[slen-2] += s[slen-1];
				slen --;
				break;
			case 2:
				s[slen-2] -= s[slen-1];
				slen --;
				break;
			case 3:
				s[slen-2] *= s[slen-1];
				slen --;
				break;
			}
		} else {
			s[slen++] = e[i].val;
		}
	}
	if (s[0] == 10) {
		disp(e, 7);
		return 1;
	}
	return 0;
}
int solve_op(const int *v, const int *op)
{
	element_t e[7];
	int i;
	for (i = 0; i < 4; i ++) {
		e[i].op = 0;
		e[i].val = v[i];
	}
	for (i = 0 ; i < 3; i ++) {
		e[4+i].op = op[i];
		e[4+i].val = 0;
	}
	sort(e, e+7);
	while (next_permutation(e, e+7)) {
		if (e[0].op == 0 && e[1].op == 0 && e[6].op != 0) {
			if (check(e))
				return 1;
		}
	}
	return 0;
}
void solve(const int *v)
{
	int op[3];
	for (op[0] = 1; op[0] <= 3; op[0] ++) {
		for (op[1] = 1; op[1] <= 3; op[1] ++) {
			for (op[2] = 1; op[2] <= 3; op[2] ++) {
				if (solve_op(v, op))
					return;
			}
		}
	}
	puts("0");
}
int main()
{
	int v[4];
	while (scanf("%d%d%d%d", v+0, v+1, v+2, v+3)>0, v[0]||v[1]||v[2]||v[3]) {
		solve(v);
	}
	return 0;
}

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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	char c;
	cin >> c;

	if (islower(c))
		cout << 'a';
	else
		cout << 'A';

	return 0;
}

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

using namespace std;

int main() {
	int N; cin >> N;
	int K; cin >> K;
	for (int i = 0; i < K; ++i) {
		int x, y; cin >> x >> y; --x, --y;
		x = min(x, N-x-1);
		y = min(y, N-y-1);
		int k = min(x, y);
		cout << k%3+1 << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define ll long long
#define pa pair<ll,int>
#define MN 100000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
priority_queue<pa,vector<pa>,greater<pa> >q;
int n,m,S,T,head[MN+5],f[MN+5],F[MN+5],cnt,in[MN+5],Q[MN+5],top,ans;
ll d[MN+5],D[MN+5];
struct edge{int to,next,w;}e[MN*4+5];
inline void ins(int f,int t,int w)
{
	e[++cnt]=(edge){t,head[f],w};head[f]=cnt;
	e[++cnt]=(edge){f,head[t],w};head[t]=cnt;	
}
void Dij(int from,ll*d)
{
	memset(d,40,sizeof(D));q.push(make_pair(d[from]=0,from));	
	while(!q.empty())
	{
		while(!q.empty()&&d[q.top().second]!=q.top().first) q.pop();
		if(q.empty()) break;
		int x=q.top().second;q.pop();
		for(int i=head[x];i;i=e[i].next)
			if(d[x]+e[i].w<d[e[i].to]) q.push(make_pair(d[e[i].to]=d[x]+e[i].w,e[i].to));	
	}
}
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
int main()
{
	n=read();m=read();S=read();T=read();
	for(int i=1,j,k;i<=m;++i) j=read(),k=read(),ins(j,k,read());
	Dij(S,d);Dij(T,D);
	for(int i=1;i<=n;++i) for(int j=head[i];j;j=e[j].next) if(d[i]+e[j].w==d[e[j].to]) ++in[e[j].to];
	Q[top=1]=S;f[S]=1;
	for(int i=1;i<=top;++i)
		for(int j=head[Q[i]];j;j=e[j].next)
			if(d[Q[i]]+e[j].w==d[e[j].to]&&(R(f[e[j].to],f[Q[i]]),!--in[e[j].to]))
				Q[++top]=e[j].to;
	for(int i=1;i<=n;++i) for(int j=head[i];j;j=e[j].next) if(D[i]+e[j].w==D[e[j].to]) ++in[e[j].to];
	Q[top=1]=T;F[T]=1;
	for(int i=1;i<=top;++i)
		for(int j=head[Q[i]];j;j=e[j].next)
			if(D[Q[i]]+e[j].w==D[e[j].to]&&(R(F[e[j].to],F[Q[i]]),!--in[e[j].to]))
				Q[++top]=e[j].to;
	ans=1LL*f[T]*f[T]%mod;
	for(int i=1;i<=n;++i) if(d[i]+D[i]==d[T])
	{
		if(d[i]*2==d[T]) ans=(ans-1LL*f[i]*F[i]%mod*f[i]%mod*F[i]%mod+mod)%mod;
		for(int j=head[i];j;j=e[j].next) if(d[i]+e[j].w==d[e[j].to]&&d[e[j].to]+D[e[j].to]==d[T])
		{
			ll l=d[i],r=d[e[j].to];
			if(l*2<d[T]&&r*2>d[T]) ans=(ans-1LL*f[i]*F[e[j].to]%mod*f[i]%mod*F[e[j].to]%mod+mod)%mod;
		}	
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10612
N, Y = list(map(int, input().split()))

answer = [-1, -1, -1]

flag = True
NF = int(Y / 10000) + 1
for nf in range(NF):
    if flag:
        cashf = Y - nf * 10000
        NH = int(cashf / 5000) + 1
        for nh in range(NH):
            cashh = cashf - nh * 5000
            if cashh < 0:
                break
            nn = int(cashh / 1000)
            if nf + nh + nn == N:
                flag = False
                answer = [nf, nh, nn]
                break

print(answer[0], answer[1], answer[2])


Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    S = input()
    L = len(S)

    ans = 0

    for i in range(2**(L-1)):
        nums = S[0]
        for j in range(1, L):
            if i & (1<<(j-1)):
                nums += " "
            nums += S[j]
        #print(nums)
        subtotal = sum(map(int, nums.split()))
        ans += subtotal

    print(ans)

if __name__ == "__main__": main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long
#define int long long 
# define INF 2e5+5
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}


int32_t main()
{
    
    c_p_c();
   
         int n;
         cin>>n;
         int ans=(n+999)/1000;
         //cout<<ans<<"\n";
         cout<<abs(n-ans*1000)<<"\n";
        


             
     return 0;
}
 


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

const int INF = 5000000000000000000;

int t, n, a, b, c, d;
map<int, int> mp;

int dfs(int x) {
	if (x == 0)return 0;
	if (x == 1)return d;
	if (mp[x])return mp[x];
	int res = INF;
	if (INF / d >= x)res = min(res, d*x);
	int s = 2 * (x / 2);
	res = min(res, dfs(s / 2) + a + d * (x - s));
	s = 2 * (x / 2 + 1);
	if (x % 2)res = min(res, dfs(s / 2) + a + d * (s - x));
	s = 3 * (x / 3);
	res = min(res, dfs(s / 3) + b + d * (x - s));
	s = 3 * (x / 3 + 1);
	if (x % 3)res = min(res, dfs(s / 3) + b + d * (s - x));
	s = 5 * (x / 5);
	res = min(res, dfs(s / 5) + c + d * (x - s));
	s = 5 * (x / 5 + 1);
	if (x % 5)res = min(res, dfs(s / 5) + c + d * (s - x));
	mp[x] = res;
	return res;
}

signed main() {
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n >> a >> b >> c >> d;
		mp.clear();
		cout << dfs(n) << endl;
	}
}

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

int top = 0;
int stack[100];

void push(int x) {
  top++;
  stack[top-1] = x;
}

int pop() {
  top--;
  return stack[top];
}

int main() {
  char s[7];
  int a, b;

  while ( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      push(pop() + pop());
    } else if ( s[0] == '-' ) {
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ) {
      push(pop() * pop());
    } else {
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



Measured memory_bytes: 2736
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

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

string rotate(string S) {
    return S.substr(S.size() - 1) + S.substr(0, S.size() - 1);
}

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

    string T;
    cin >> T;

    REP(0, i, S.size()) {
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        } else {
            S = rotate(S);
        }
    }

    cout << "No" << endl;

    return 0;
}


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

// A - Cats and Dogs
int main(){
    int A, B, X;
    cin >> A >> B >> X;
    
    string ans = "YES";
    if(X-A<0 || X-A>B) ans ="NO";
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256