akhauriyash/Code-Regression huggingface dataset:
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

array<int, 100000> A = {};

int main()
{
	fastIOS();

	string A, B, C;
	cin >> A >> B >> C;

	cout << A[0] << B[0] << C[0] << "\n";

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	char op;
	while (cin >> a >> op >> b) {
		if (op == '+') {
			c = a + b;
		}
		else if (op == '-') {
			c = a - b;
		}
		else if (op == '/') {
			c = a / b;
		}
		else if (op == '*') {
			c = a * b;
		}
		else {
			break;
		}
		cout << c << endl;
	}
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

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

  int n;cin>>n;
  int a=0;
  int b=0;
  int ba=0;
  ll res=0;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    for(int j=0;j<s.size()-1;j++){
      if(s[j]=='A'&&s[j+1]=='B')res++;
    }
    if(s[0]=='B')b++;
    if(s[s.size()-1]=='A')a++;
    if(s[0]=='B'&&s[s.size()-1]=='A')ba++;
  }

  res+=min(b,a);
  if(b==a&&ba==b&&ba>0)res--;

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
using namespace std;

int main() {
	int H, W, i, j;
	string str[26][26];
	string s = "snuke";
	char w;

	cin >> H >> W;


	for (i = 0; i < H; i++) {
		for (j= 0; j < W; j++) {
			cin >> str[i][j];

		}
	}

	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (str[i][j] == s) {
				w = j + 65;
				cout << w << i + 1;
			}
		}
	}
	cout << endl;

	return 0;
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 32;
vector<vector<Int> > X;
vector<Int> Y;
Int dpa[MAX][MAX];
Int dpb[MAX][MAX];
Int dfs(Int l,Int r,Int (*dp)[MAX],vector<Int> &s,Int n){
  //if(l>=r) cout<<l<<" "<<r<<endl;
  Int &res=dp[l%n][r%n];
  if(~res) return res;
  if(l+1==r) return res=1LL<<s[l];
  res=0;
  for(Int i=0;i<(Int)X.size();i++){
    Int k=X[i].size();
    vector<vector<Int> > dp2(MAX*2,vector<Int>(MAX*2,0));
    dp2[l][0]=1;
    for(Int p=l;p<r;p++){
      for(Int j=0;j<k;j++){
	if(!dp2[p][j]||r-p<k-j) continue;
	dp2[p+1][j+1]|=s[p]==X[i][j];	
	for(Int q=p+2;q<=r;q++)
	  dp2[q][j+1]|=(dfs(p,q,dp,s,n)>>X[i][j])&1;
      }
    }
    res|=dp2[r][k]<<Y[i];
  }
  return res;
}

Int n,m;
inline Int ag(Int l,Int r){return dpa[l%n][r%n];};
inline Int bg(Int l,Int r){return dpb[l%m][r%m];};

Int dp[MAX*2][MAX*2];

signed main(){
  Int r;
  while(cin>>n>>m>>r,n){
    vector<Int> A(n),B(m);
    for(Int i=0;i<n;i++) cin>>A[i];
    for(Int i=0;i<m;i++) cin>>B[i];
    vector<vector<Int> > x(r);
    vector<Int> y(r);
    for(Int i=0;i<r;i++){
      Int k;
      cin>>k;
      x[i].resize(k);
      for(Int j=0;j<k;j++) cin>>x[i][j];
      cin>>y[i];
    }
    for(Int i=0;i<n;i++) A.emplace_back(Int(A[i]));
    for(Int i=0;i<m;i++) B.emplace_back(Int(B[i]));
    X=x;Y=y;
    memset(dpa,-1,sizeof(dpa));
    memset(dpb,-1,sizeof(dpb));
    for(Int i=0;i<n;i++)
      for(Int l=1;l<=n;l++)
	dfs(i,i+l,dpa,A,n);
    for(Int i=0;i<m;i++)
      for(Int l=1;l<=m;l++)
	dfs(i,i+l,dpb,B,m);

    memset(dp,-1,sizeof(dp));
    Int ans=-1;
    for(Int i=0;i<n;i++){
      for(Int j=0;j<m;j++){
	dp[i][j]=0;
	for(Int a=0;a<n;a++){
	  for(Int b=0;b<m;b++){
	    if(dp[i+a][j+b]<0) continue;
	    for(Int na=a+1;na<=n;na++)
	      for(Int nb=b+1;nb<=m;nb++)
		if(ag(i+a,i+na)&bg(j+b,j+nb))
		  chmax(dp[i+na][j+nb],dp[i+a][j+b]+1);      
	    dp[i+a][j+b]=-1;
	  }
	}
	
	chmax(ans,dp[i+n][j+m]);
	for(Int a=0;a<n;a++) dp[i+a][j+m]=-1;
	for(Int b=0;b<m;b++) dp[i+n][j+b]=-1;
	//cout<<dp[i+n][j+m]<<endl;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3908
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

if a < b:
    if a + v * t >= b + w * t:
        print("YES")
    else:
        print("NO")
elif a > b:
    if a - v * t <= b - w * t:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9176
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) V(N), C(N);
    READVEC(V);
    READVEC(C);

    int ret = 0;
    FOR(i, 0, N)
        if (V[i] > C[i])
            ret += V[i] - C[i];
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int((x).size()))
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
template<typename T> bool domax(T &a, T b) { return (b > a ? (a = b, true) : false); }
template<typename T> bool domin(T &a, T b) { return (b < a ? (a = b, true) : false); }
typedef long long ll;

const int maxn = 205;

int n, a[maxn], s;

int main() {
    scanf("%d", &n);
    n *= 2;
    for (int i = 0; i < n; i++) scanf("%d", a+i);
    std::sort(a, a+n);
    std::reverse(a, a+n);
    for (int i = 1; i < n; i += 2) s += a[i];
    printf("%d\n", s);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int A,B,K,L;
    scanf("%d%d",&A,&B);
    L=A+B;
    if(L%2==0){
        K=L/2;
        printf("%d",K);
    }
    else{
        printf("IMPOSSIBLE");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
const int INF = 2e9;

int change(string s){
	int res = 0, i = 0;
	for(i = 0; i < s.size(); i++){
		if(s[i] == '-') continue;
		 res = res * 10 + (int)(s[i] - '0');
		//cout << s[i] - '0' << " " << res << endl;
	}
	if(s[0] == '-') res *= -1;
	return res;
}
int main(){
   	int n;
	while(cin >> n, n){
		vector<int> a(n);
		rep(i, 0 ,n){
			string s;
			cin >> s;
			if(s == "x") a[i] = -INF;
			else a[i] = change(s);
			//cout << a[i] << endl;
		}
		int l = -INF, h = INF;// x must be [l, h]
		bool f = true;
		rep(i, 0, n){
			if(a[i] == -INF){
				if(i % 2){
					l = max(l, a[i - 1] + 1);
					if(i != n - 1) l = max(l, a[i + 1] + 1);
				}else{
					if(i != 0) h = min(h, a[i - 1] - 1);
					if(i != n - 1) h = min(h, a[i + 1] - 1);
				}
			}
		}
		rep(i, 0, n) if(a[i] == -INF) a[i] = l;
		rep(i, 0, n){
				if(i % 2){
					if(a[i] <= a[i - 1]) f = false;
					if(i != n - 1 && a[i] <= a[i + 1]) f = false;
				}else{
					if(i != 0 && a[i] >= a[i - 1]) f = false;
					if(i != n - 1 && a[i] >= a[i + 1]) f = false;
				}
//ut << i << " " << f << endl;
		}
		if(l == h && f) cout << l << endl;
		else if(l > h|| f == false) cout << "none" << endl;
		else cout << "ambiguous" << endl;
	}
}

Measured memory_bytes: 3080
fun main(args: Array<String>) {
    // Your code here!
    
    val N: Int       = readLine()!!.toInt()
    val d: List<Int> = readLine()!!.split(" ").map { it.toInt() }.sorted()
    
    println(d[d.size / 2] - d[(d.size / 2) - 1])
}

Measured memory_bytes: 52408
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b)cout << c << endl;
  else if(b==c)cout << a << endl;
  else cout << b << endl;
}


Measured memory_bytes: 256
def p(val):
    print(val)


x =  list(map(int,input().split()))
a=[x[0],x[1]]
b=[x[2],x[3]]
a1 = max(a)
b1 = max(b)
c=[x[0]*x[2],x[0]*x[3],x[1]*x[2],x[1]*x[3]]
p(max(c))

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

bool Is_Prime(int n){
  if(n==1) return false;
  else if(n==2)return true;
  else if(n%2==0)return false;

  for(int i=3;i*i<=n;i+=2){
    if(n%i==0)return false;
  }
  return true;
}
vector<int> a(100001);
signed main(){
  int q;
  cin>>q;

  vector<int> prime;
  set<int> s;
  LOOP(i,2,100001){
    if(Is_Prime(i)){
      prime.PB(i);
      s.insert(i);
    }
  }
  REP(i,100001){
    if(s.find(i)!=s.end()){
      int tmp=i+1;
      if(s.find(tmp/2)!=s.end())a[i]++;
    }
  }
  REP(i,100001)a[i+1]+=a[i];
  
  REP(i,q){
    int l,r;
    cin>>l>>r;
    // int ans=0;
    // auto itr=lower_bound(ALL(prime),l);
    // for(auto itr=lower_bound(ALL(prime),l);itr!=upper_bound(ALL(prime),r);itr++){
    //      int tmp=(*itr)+1;
    //      if(prime.find(tmp/2))ans++;
    // }
    // cout<<ans<<endl;
    cout<<a[r]-a[l-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define N 100001
#define NN 1001
using namespace std;
LL a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	if(b*c>=a)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L[i];
    sort(L.begin(), L.end());

    int ans = 0;
    for (int a = 0; a < N - 1; a++) {
        for (int b = a + 1; b < N; b++) {
            int dist = lower_bound(L.begin(), L.end(), L[a] + L[b]) - L.begin();
            ans += dist - b - 1;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,x,y,b=0;
  cin>>n>>k>>x>>y;
  for(int i=0;i<k;i++){
    b+=x;
  }
  for(int i=0;i<n-k;i++){
    b+=y;
  }
  if(k>n){
    b=b-(k-n)*x;
  }
  cout<<b<<'\n';
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    map<string,int> mp;
    rep(i,N){
        string S;
        cin >> S;
        mp[S]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3600
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
k=0
for i in range(1,n):
    b.append(a[i]+b[i-1])
for i in range(n-1):
    k+=a[i]*(b[n-1]-b[i])
print(k%(10**9+7))


Measured memory_bytes: 31420
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    ll n, k;
    cin>>n>>k;
    vector<ll> v;
    vector<ll> a;
    ll k2=k/2;
    for(ll i=1;i<=n;i++){
        if(i%k==0) v.push_back(i);
        else if(i%k==k2) a.push_back(i);
    }
    if(k%2==1){
        ll s=v.size();
        cout<<s*(s-1)*(s-2)+s*(s-1)*3+s<<endl;
    }
    else{
        ll s=v.size();
        ll t=a.size();
        cout<<s*(s-1)*(s-2)+s*(s-1)*3+s+t*(t-1)*(t-2)+t*(t-1)*3+t<<endl;
    }
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define zero_pad(num) setfill('0') << std::right << setw(num)
const int MOD=1e9+7;
const int INF=1e18;
const int N_MAX=1e5;

signed main(){
    int N;cin>>N;
    int A[N];
    REP(i,N)cin>>A[i];
    int dp[N];
    REP(i,N)dp[i]=0;
    REPS(i,N-1){
        if(i==1)dp[i]=abs(A[i]-A[i-1]);
        else dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1792
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):

        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [map(int,input().split()) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)

Measured memory_bytes: 57480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[3001],t[3001],com[3001];
    int max(int,int);
    cin>>s>>t;
    int len1=strlen(s),len2=strlen(t),i,j,m,count=0;
    int dp[len1+1][len2+1];
    for(i=0;i<=len1;i++)
    {
        for(j=0;j<=len2;j++)
        {
            if((i==0)||(j==0))
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    m=dp[len1][len2]-1;
    i=len1;j=len2;
    while(count<dp[len1][len2])
    {
        if((dp[i][j]!=dp[i-1][j])&&(dp[i][j]!=dp[i][j-1]))
        {
            com[m]=s[i-1];
            m--;
            i--;
            j--;
            count++;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
                i--;
            else
                j--;
        }
    }
    for(i=0;i<dp[len1][len2];i++)
        cout<<com[i];
}
int max(int a,int b)
{
    if(a>b)
        return(a);
    else
        return(b);
}

Measured memory_bytes: 35456
A = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
N = int(input())

print(A[N-1])

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

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  for(auto &e : edges) {
    if(dist[e.src] == INF) continue;
    if(dist[e.src] + e.cost < dist[e.to]) return vector< T >();
  }
  return dist;
}

int main() {
  int V, E, R;
  scanf("%d %d %d", &V, &E, &R);
  Edges< int > es;
  for(int i = 0; i < E; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    es.emplace_back(a, b, c);
  }
  auto dists = bellman_ford(es, V, R);
  if(dists.empty()) puts("NEGATIVE CYCLE");
  for(auto &dist : dists) {
    if(dist == numeric_limits< int >::max()) puts("INF");
    else printf("%d\n", dist);
  }
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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; }

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<string> a;
    REP(i,h){
        string s;
        cin>>s;
        a.push_back(s);
    }
    int cnt=0;
    REP(i,h) REP(j,w){
        if(a[i][j]=='#') cnt++;
    }
    if(cnt==h+w-1) cout<<"Possible";
    else cout<<"Impossible";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;
     
    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;                            
     
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()            
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) power(x, mod-2)
    #define ncr(n,r) ( n >= r ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-r]))%mod) : (ll)0)
    #define MAX 100005
     
    ll power(ll x, ll y) { 
        ll ans=1;
        x=x%mod;
        while(y>0) { 
            if (y&1) 
                ans=(ans*x)%mod; 
            y=y>>1;
            x=(x*x)%mod; 
        } 
        return ans; 
    }
    
    // vector<ll> adj[MAX];
    // ll visit[MAX];
    // void dfs(ll node){
    //     visit[node]=1;
    //     for(auto i : adj[node]){
    //         if(!visit[i]) dfs(i);
    //     }
    // }
    
    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }

    int main()
    {
        boost;
        ll n,flag=0;;
        cin>>n;
        pll arr[n];
        sidha(i,0,n)    cin>>arr[i].fi>>arr[i].se;
        sidha(i,0,n-2){
            if(arr[i].fi==arr[i].se && arr[i+1].fi==arr[i+1].se && arr[i+2].fi==arr[i+2].se)    flag=1;
        }
        if(flag)    cout<<"Yes";
        else    cout<<"No";
        return 0;
    }
    

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	map<int, int> c;
	for (int x = 1; x * x <= N; x++) {
		for (int y = 1; y * y <= N; y++) {
			for (int z = 1; z*z <= N; z++) {
				if (x*x + y*y + z*z + x*y + y*z + z*x > N) break;
				c[x*x + y*y + z*z + x*y + y*z + z*x]++;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		cout << c[i] << "\n";
	}
}



Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
int main(){
 int N; cin>>N;
  long long sum=0;
  vector<int> A(N);
  vector<long long> count(110000,0);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
    sum+=A[i];
    count[A[i]]++;
  }
  int Q; cin>>Q;
  for(int i=0 ;i<Q; i++){
    int B; int C; cin>>B>>C;
    sum+=(C-B)*count[B];
    count[C]+=count[B];
    count[B]=0;
    cout<<sum<<endl;
  }
}
  

Measured memory_bytes: 4500
import itertools


def main():
    N = int(input())
    PArry = list(map(int, input().split()))
    QArry = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            b = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
X,K,D = map(int, input().split())  

if X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
        
elif X > 0 :
    if (X // D) >= K:
        print(X - K*D)
    else:
        X1 = X - (X // D) * D
        K1 = K - (X // D)
        if K1 % 2 == 0:
            print(X1)
        else:
            print(abs(X1-D))
else:
    if (-X // D) >= K:
        print(abs(X + K*D))
    else:
        X1 = X + (-X // D)*D
        K1 = K - (-X // D)
        if K1 % 2 == 0:
            print(abs(X1))
        else:
            print(abs(X1+D))

Measured memory_bytes: 9080
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N; long long K;
    while(cin >> N >> K){
        vector<long long> P, M;
        for(int i=0;i<N;i++){
            int A; cin >> A;
            if(A >= 0) P.push_back(A);
            else M.push_back(-A);
        }
        sort(P.begin(), P.end());
        sort(M.begin(), M.end());
        long long minus = (long long)P.size() * M.size();
        if(K <= minus){
            long long L = 0, R = 1LL << 61;
            while(R-L > 1){
                long long cnt = 0;
                long long mid = (L+R)/2;
                for(auto& m : M){
                    cnt += P.size() - distance(P.begin(), lower_bound(P.begin(), P.end(), (mid+m-1)/m));
                }
                if(cnt >= K) L = mid;
                else R = mid;
            }
            cout << -L << endl;
        } else {
            K -= minus;
            long long L = -1, R = 1LL << 61;
            while(R-L > 1){
                long long cnt = 0;
                long long mid = (L+R)/2;
                auto check = [&](const vector<long long>& v){
                    int idx = v.size() - 1;
                    for(int i=0;i<v.size();i++){
                        while(idx >= 0 && v[i] * v[idx] > mid) --idx;
                        cnt += max(0, idx - i);
                    }
                };
                check(M);
                check(P);
                if(cnt >= K) R = mid;
                else L = mid;
            }
            cout << R << endl;
        }
    }
}

Measured memory_bytes: 2548
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	while (cin >> N, N) {
		vector<int>v(N);
		for (auto &i : v)cin >> i;
		vector<vector<int>>dp(N, vector<int>(N));
		for (int i = 0; i + 2 <= N; i++) {
			if (abs(v[i] - v[i + 1]) <= 1)dp[i][i + 1] = 1;
		}
		for (int i = 4; i <= N; i += 2) {
			for (int j = 0; j + i <= N; j++) {
				for (int k = j; k < i + j; k += 2) {
					for (int l = k + 1; l < i + j; l += 2) {
						if (abs(v[k] - v[l]) > 1)continue;
						if (k != j && !dp[j][k - 1])continue;
						if (l - k > 1 && !dp[k + 1][l - 1])continue;
						if (l + 1 != i + j && !dp[l + 1][i + j - 1])continue;
						dp[j][i+j-1] = 1;
				//		cout << k << " " << l << endl;
					}
				}
			}
		}
		vector<int>num(N);
		for (int i = 0; i < N; i++) {
			num[i] = dp[0][i] * (i + 1);
		}
		int cnt = num[0];
		for (int i = 1; i < N; i++) {
			for (int j = i; j < N; j++) {
				num[j] = max(num[j], cnt + dp[i][j] * (j - i + 1));
			}
			cnt = max(cnt, num[i]);
		}
		cout << cnt  << endl;
	}
}



Measured memory_bytes: 3268
/*
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;
	vi arr(n);
	REP(i,0,n-1)cin>>arr[i];
	int mc=0,cnt=0;
	for(int i=n-2;i>=0;i--) {
		if(arr[i]>=arr[i+1])cnt++;else cnt=0;
		mc=max(cnt,mc);
	}
	cout<<mc;
}

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: 3708
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    map<string,int> mp;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, q;
    cin >> n >> q;
    string s; 
    cin >> s;
    vector<pair<char, char>> op(q);
    for (auto &e: op) cin >> e.first >> e.second;

    int b = -1, e = n;
    while (e - b > 1) {
        int m = (b + e) / 2;
        int i = m;
        bool f = false;
        for (auto &&p: op) {
            if (p.first != s[i]) continue;
            if (p.second == 'L') --i;
            else ++i;
            if (i == -1) {
                f = true;
                break;
            }
            if (i == n) break;
        }
        if (f) b = m;
        else e = m;
    }
    int l = b+1;

    b = -1, e = n;
    while (e - b > 1) {
        int m = (b + e) / 2;
        int i = m;
        bool f = false;
        for (auto &&p: op) {
            if (p.first != s[i]) continue;
            if (p.second == 'L') --i;
            else ++i;
            if (i == n) {
                f = true;
                break;
            }
            if (i == -1) break;
        }
        if (f) e = m;
        else b = m;
    }
    int r = n - e;

    cout << n - (l + r) << endl;

    return 0;
}


Measured memory_bytes: 900
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;
const long double EPS = 1e-7;

long long int N, M, K, H, W, L, R;


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

	cin >> L >> R;
	if (L == R) {
		cout << 1 << endl;
		return 0;
	}
	N = L;
	M = R;
	while (N) {
		H++;
		N >>= 1;
	}
	H--;
	while (M) {
		W++;
		M >>= 1;
	}
	W--;
	while (H == W) {
		L -= 1LL << H;
		R -= 1LL << W;
		N = L;
		M = R;
		H = 0;
		W = 0;
		while (N) {
			H++;
			N >>= 1;
		}
		H--;
		while (M) {
			W++;
			M >>= 1;
		}
		W--;
	}
	//cout << L << " " << R << endl;
	//cout << (1LL << W) << endl;
	long long int l = L + (1LL << W);
	long long int r = (1LL << (W + 1)) - 1;
//	cout << l << " " << r << endl;
	long long int box = R;
	box -= (1LL << W);
	long long int bag = box;
	int num = 0;
	while (bag) {
		bag /= 2;
		num++;
	}
	//cout << (1LL << num) - 1+(1LL<<W) << endl;
	if (l <= (1LL << num) - 1 + (1LL << W)) {
		cout << (1LL << (W + 1)) - L << endl;
		return 0;
	}
	else {
		cout << r - l + 1 + (1LL << num) - 1 + (1LL << W) - L + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
A = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

def count(x):
    ans = 0
    left = 0
    total = 0
    for right in range(N):
        total += A[right]
        while total > x:
            total -= A[left]
            left += 1
            
        ans += right - left + 1
    return ans

for x in X:            
    print(count(x))


Measured memory_bytes: 16856
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int R, G;
	scanf("%d %d", &R, &G);
	return !printf("%d\n", 2 * G - R);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int T,n,f1[51],f2[51],d1[51],d2[51],ans,d[51];
bool vis[51],cur[51];
struct tree
{
	bool mp[51][51];
	struct bian{int nxt,to;}bi[110];
	int head[51],num;
	inline void add(int from,int to)
	{
		mp[from][to]=1;
		bi[++num]=bian{head[from],to};
		head[from]=num;
	}
	void clear()
	{
		memset(mp,0,sizeof(mp));
		memset(head,0,sizeof(head));
		num=0;
	}
}t1,t2;
void dfs1(int v,int fa)
{
	f1[v]=fa;
	for(int i=t1.head[v];i;i=t1.bi[i].nxt)
		if(t1.bi[i].to!=fa)++d1[v],dfs1(t1.bi[i].to,v);
}
void dfs2(int v,int fa)
{
	f2[v]=fa;
	for(int i=t2.head[v];i;i=t2.bi[i].nxt)
		if(t2.bi[i].to!=fa)++d2[v],dfs2(t2.bi[i].to,v);
}
void work(int x)
{
	queue<int>q;
	int y,cnt=0;
	memset(cur+1,0,n);
	q.push(x),vis[x]=1,cur[x]=1,++cnt;
	while(!q.empty())
	{
		x=q.front();q.pop();//printf("%d ",x);
		for(int i=t1.head[x];i;i=t1.bi[i].nxt)if(t2.mp[x][y=t1.bi[i].to]&&!vis[y])q.push(y),cur[y]=1,vis[y]=1,++cnt;
	}
//	printf("\n");
	memset(f1+1,0,n<<2);memset(d1+1,0,n<<2);
	memset(f2+1,0,n<<2);memset(d2+1,0,n<<2);
	for(int i=1;i<=n;++i)
		if(cur[i])
		{
			for(int j=t1.head[i];j;j=t1.bi[j].nxt)if(!cur[y=t1.bi[j].to])dfs1(y,i);
			for(int j=t2.head[i];j;j=t2.bi[j].nxt)if(!cur[y=t2.bi[j].to])dfs2(y,i);
		}
	int tot=cnt;
	for(int i=1;i<=n;++i)if(!cur[i]&&!d1[i]&&cur[f2[i]])q.push(i),cur[i]=1,++tot;
	while(!q.empty())
	{
		x=q.front();q.pop();
	//	printf("%d ",x);
		--d1[f1[x]];
		y=f1[x];
		if(!cur[y]&&!d1[y]&&cur[f2[y]])q.push(y),cur[y]=1,++tot;
		for(int i=t2.head[x];i;i=t2.bi[i].nxt)
		{
			y=t2.bi[i].to;
			if(f2[y]==x&&!cur[y]&&!d1[y])q.push(y),cur[y]=1,++tot;
		}
	}
//	printf("\n");
//	printf("%d\n\n",tot);
	if(tot==n)ans=min(ans,n-cnt);
}
bool work1(int x,int y)
{
	queue<int>q;
	memset(f1+1,0,n<<2);memset(d1+1,0,n<<2);
	memset(f2+1,0,n<<2);memset(d2+1,0,n<<2);
	memset(cur+1,0,n);
	dfs1(y,0);
	dfs2(x,0);
	--d1[f1[x]];
	int tot=1;
	cur[x]=1;
	for(int i=1;i<=n;++i)if(!cur[i]&&!d1[i]&&cur[f2[i]])q.push(i),cur[i]=1,++tot;
	while(!q.empty())
	{
		x=q.front();q.pop();
	//	printf("%d ",x);
		--d1[f1[x]];
		y=f1[x];
		if(!cur[y]&&!d1[y]&&cur[f2[y]])q.push(y),cur[y]=1,++tot;
		for(int i=t2.head[x];i;i=t2.bi[i].nxt)
		{
			y=t2.bi[i].to;
			if(f2[y]==x&&!cur[y]&&!d1[y])q.push(y),cur[y]=1,++tot;
		}
	}
	return tot==n;	
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		memset(vis+1,0,n);memset(d+1,0,n<<2);
		t1.clear(),t2.clear();
		ans=0x3f3f3f3f;
		int x,y;
		for(int i=1;i<n;++i)
		{
			scanf("%d %d",&x,&y);
			t1.add(x,y),t1.add(y,x);
			++d[x],++d[y];
		}
		for(int i=1;i<n;++i)
		{
			scanf("%d %d",&x,&y);
			t2.add(x,y),t2.add(y,x);
		}
		for(int i=1;i<=n;++i)if(!vis[i])work(i);
		if(ans!=0x3f3f3f3f)
		{
			printf("%d\n",ans);
			continue;
		}
		bool flag=0;
		for(int i=1;i<=n&&!flag;++i)
			if(d[i]==1)
				for(int j=1;j<=n&&!flag;++j)
					if(j!=i&&work1(i,j))flag=1;
		if(flag)printf("%d\n",n);
		else printf("-1\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.3.1
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define PI 3.141592653589793238462
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int x,y;
  cin >> x >> y;
  int ans = 0;
  if(x==1) ans+=300000;
  else if(x==2) ans+=200000;
  else if(x==3) ans+=100000;
  
  if(y==1) ans+=300000;
  else if(y==2) ans+=200000;
  else if(y==3) ans+=100000;
  
  if(x==1&&y==1) ans += 400000;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
A = int(input()) 
B = int(input()) 
C = int(input()) 
X = int(input())
count = 0

for A in range(0,A+1):
    for B in range(0,B+1):
        for C in range(0,C+1):
            price = A * 500 + B * 100 + C * 50 
            if price == X:
                count += 1
            else:
                continue
print(count)


Measured memory_bytes: 3060
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
int ctoi(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  return 0;
}
int xoror(int a,int b){
  return 0;
}


//cout << setprecision(123)<<ans;
//int a=atoi(S.c_str());
//string S=to_string(a);
//int &a=b;
int main(){
  char c,d;
  cin>>c;
  d=c+1;
  cout<<d<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int s, w; cin >> s >> w;
  cout << (w >= s ? "unsafe" : "safe") << endl;

}

// EOF


Measured memory_bytes: 3612
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();

        System.out.println(Math.ceil(a/d) >= Math.ceil(c/b)? "Yes" : "No");
    }
}

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

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int a[100001] = { 0 }; int b[100001] = { 0 }; int c[100001] = { 0 };
int main() {
	long long n, t, x, y; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> t >> x >> y;
		a[h] = t; b[h] = x; c[h] = y;
	}
	for (int h = 0; h < n; h++) {
		if (a[h] >= b[h] + c[h]) {
			if (a[h] % 2 != (b[h] + c[h]) % 2) {
				cout << "No" << endl; 
				return 0;
			}
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	cin >> n;
}

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

int main() {
    int A,B;
    cin >> A >> B;
    
    int a = 0;
    
    for (int i=A; i<=B; i++){
        int a1 = i/10000;
        int a2 = i/1000%10;
        int a4 = i/10%10;
        int a5 = i%10;
        if (a1==a5&&a2==a4) a++;
    }
    
    cout << a << endl;
}


Measured memory_bytes: 256
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M,P = map(int,(input().split()))
line = []
for i in range(M):
    a,b,c = map(int,(input().split()))
    line.append([a-1,b-1,-c+P])

min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする
#negative = [False]*N

"""
def Bellman_Ford(S,V,E,distance,negative):
    negative = [False]*N
    count = 1
    while count < V:
        count += 1
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = min_distance[s] + d # 最短距離を上書きする
                negative[s],negative[g] = True,True
    return min_distance,negative

min_distance,negative = Bellman_Ford(1,N,M,line,negative)
ans = min_distance[N-1]

negative = [False]*N
min_distance,negative = Bellman_Ford(1,N,M,line,negative)
print(negative)
print(min_distance)

if negative[N-1]:
    print(-1)
else:
    print(max(-ans,0))
"""
def Bellman_Ford(S,V,E,distance):
    update = False
    flag = 0
    for _ in range(V):
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = min_distance[s] + d # 最短距離を上書きする
                update = True
        if not update:
            flag = 1
            break
    return min_distance,flag

def Bellman_Ford2(S,V,E,distance):
    for _ in range(V):
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = -float("inf")
    return min_distance

min_distance,flag = Bellman_Ford(1,N,M,line)

if flag == 1:
    ans = min_distance[N-1]
    print(max(-ans,0))
else:
    min_distance = Bellman_Ford2(1,N,M,line)
    ans = min_distance[N-1]
    if ans == -float("inf"):
        print(-1)
    else:
        print(max(-ans,0))

#print(min_distance)

Measured memory_bytes: 75868
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int n,k;
	int *L,ans = 0,max,maxi;
	scanf("%d%d",&n,&k);
	L = (int *)malloc(sizeof(int) * n);

	for (int i = 0; i < n; ++i)	scanf(" %d",&L[i]);
	for (int i = 0; i < k; ++i){
		max = -1;
		for (int i = 0; i < n; ++i){
			if(max < L[i]){
				max = L[i];
				maxi = i;
			}
		}
		ans += max;
		L[maxi] = -1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128