akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
while(1){
int sina[1000],n,m,sum=0;
scanf("%d%d",&n,&m);
if(n==0&&m==0)return 0;
for(int i=0;i<n;i++){
scanf("%d",&sina[i]);
sum+=sina[i];
}
sort(sina,sina+n);
for(int i=n-m;i>=0;i-=m){
sum-=sina[i];
}
printf("%d\n",sum);
}
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int H, W;
    cin>>H>>W;
    vvi A(H, vi(W, 0));
    vector<pint> B;
    REP(i, 0, H){
        string S;
        cin >> S;
        REP(j, 0, W){
            if(S[j] == '#'){
                A[i][j] = 1;
                B.push_back({i, j});
            }
        }   
    }
    queue<pint> que;
    vvi Map(H, vi(W, -1));
    for(pint a: B){
        que.push(a);
        Map[a.first][a.second] = 0;
    }
    vector<pint> D = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    int ans = 0;
    while(!que.empty()){
        auto cur = que.front(); que.pop();
        int count = Map[cur.first][cur.second];
        //cout << cur.first << " " << cur.second << endl;
        ans = max(ans, count);
        for(pint x: D){
            int new_x = cur.first + x.first;
            int new_y = cur.second + x.second;
            if(new_x < 0 || new_y < 0 || new_x >= H || new_y >= W) continue;
            if(Map[new_x][new_y] == -1){
                que.push({new_x, new_y});
                Map[new_x][new_y] = count + 1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 24168
n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
count = 1
p = 0
for i in range(n):
    if i == 0:
        if s1[i] == s2[i]:
            count *= 3
        else:
            count *= 6
            p = 1
    elif p == 0:
        if s1[i - 1] == s2[i - 1] and s1[i] != s2[i]:
            count *= 2
            p = 1
        elif s1[i - 1] == s2[i - 1] and s1[i] == s2[i]:
            count *= 2
        elif s1[i - 1] != s2[i - 1] and s1[i] == s2[i]:
            count *= 1
        elif s1[i - 1] != s2[i - 1] and s1[i] != s2[i]:
            count *= 3
            p = 1
    elif p == 1:
        p = 0
print(count % mod)

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if(a[0]==5 && a[1]==5 && a[2]==7)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>

using namespace std;

int main()
{
	int n,l,minNum=1000000000;
	cin >> n >> l;
	vector<int> apple(n);
	for (int i = 0; i < n; i++)apple[i] = l+(i+1)-1;
	for (int i = 0; i < n; i++) {
		minNum = min(minNum,abs(accumulate(apple.begin(),apple.end(),0) - (accumulate(apple.begin(), apple.end(), 0)-apple[i])));
	}
	cout << (accumulate(apple.begin(), apple.end(), 0) - minNum >=0 ? accumulate(apple.begin(), apple.end(), 0) - minNum : accumulate(apple.begin(), apple.end(), 0) + minNum) << endl;
}

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


int main(){
    char a[5];
    scanf(" %s",a);
    char c1,c2;
    c1 = a[0];
    if (a[0] == a[1] && a[2] == a[3] && a[0] != a[2]) printf("Yes");
    else if (a[0] == a[2] && a[1] == a[3] && a[0] != a[1]) printf("Yes");
    else if (a[0] == a[3] && a[1] == a[2] && a[0] != a[1]) printf("Yes");
    else printf("No");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1
 
void testCase() {
    string s, t;
    cin >> s >> t;
    for (int i=0; i<s.size(); i++) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

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

        while (sc.hasNext()) {
            int n = sc.nextInt();

            int noCombinations = 0;
            for (int a = 0; a <= 9; a++)
                for (int b = 0; b <= 9; b++)
                    for (int c = 0; c <= 9; c++)
                        for (int d = 0; d <= 9; d++)
                            if (a + b + c + d == n)
                                noCombinations++;

            System.out.println(noCombinations);
        }
    }
}

Measured memory_bytes: 26740
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = [0]*len(A)
C = [0]*len(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)


Measured memory_bytes: 59168
#include <bits/stdc++.h>
using namespace std;
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; }

vector<vector<int>> G;

const int lim = 1e5 + 10;
int dp[lim];
int rec(int v) {
    if (dp[v] != -1) return dp[v];

    int res = 0;
    for (auto nv : G[v]) {
        chmax(res, rec(nv) + 1);
    }
    dp[v] = res;
    return dp[v];
}


int main() {
    int N, M;
    cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        G[from].push_back(to);
    }

    for (int v = 0; v < lim; ++v) dp[v] = -1;

    int res = 0;
    for (int v = 0; v < N; ++v) chmax(res, rec(v));
    cout << res << endl;
}

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

using namespace std;

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

	struct Store
	{
		long long A;
		int B;
	};

	vector<Store> store(N);

	for (int i = 0; i < N; i++) 
		cin >> store[i].A >> store[i].B;

	

	sort(store.begin(), store.end(), [](const Store& x, const Store& y) { return x.A < y.A; });

	long long ans = 0;

	int count = 0;

	for (int j = 0; j < N; j++)
	{
		count += store[j].B;
		if (count > M)
		{
			ans += store[j].A * (M - count + store[j].B);
			break;
		}
		else
		{
			ans += store[j].A * store[j].B;
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
   int a,b;
   
   cin >> a >> b;
   if (a > b) {
    cout << "a" << " > " << "b" << endl;    
   } else if (a < b) {
       cout << "a" << " < " << "b" << endl;
   } else {
       cout << "a" << " == " << "b" << endl;
   }
   
   
  
    return 0;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

char s[200005];
int len, ps[26][200005], num[200005];
int dp[200005];
map<int, int> M;

int main(){
	scanf("%s", s + 1);
	len = strlen(s + 1);
	FI(i, 1, len){
		FI(j, 0, 25) ps[j][i] = ps[j][i - 1];
		ps[s[i] - 'a'][i]++;
		FI(j, 0, 25) if(ps[j][i] & 1){
			num[i] += (1 << j);
		}
	}
	M[0] = 0;
	FI(j, 1, len){
		dp[j] = 999999;
		FI(k, 0, 26){
			int x = num[j];
			if(k != 26) x ^= (1 << k);
			if(M.count(x)){
				dp[j] = min(dp[j], M[x] + 1);
			}
		}
		if(M.count(num[j])){
			M[num[j]] = min(M[num[j]], dp[j]);
		}
		else M[num[j]] = dp[j];
	}
	printf("%d\n", dp[len]);
	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N, ans = 0;
    string S;
    cin >> N >> S;
    for (int i = 1; i < N; i++)
    {
        string str1 = S.substr(0, i);
        string str2 = S.substr(i, N);
        int tmp = 0;
        for (char c = 'a'; c <= 'z'; c++)
        {
            if ((count(str1.begin(), str1.end(), c) > 0) && (count(str2.begin(), str2.end(), c) > 0))
            {
                tmp++;
            }
        }
        if (ans < tmp)
        {
            ans = tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

long long int combination(long long int n, long long int r)
{
	if (r == 0 || r == n)
		return (1);
	else if (r == 1)
		return (n);
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int keta(int a, int n)
{
	if (n == 1)
		return a % 10;

	for (int i = 0; i < n - 1; i++)
		a /= 10;

	return a % 10;
}

int main()
{
	int N, M, L, K;
	int A[200001];
	int B[200001];
	int C[200001] = { 0 };

	long long int comb = 0;
	int count = 0;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
		B[i] = A[i];
		C[A[i]]++;
	}
	
	//sort(A, A + N);

	for (int i = 0; i <= N; i++)
	{
		if(C[i]>=2)
			comb += combination(C[i], 2);
	}
	

	//printf("%d\n\n", comb);

	for (int i = 0; i < N; i++)
	{
		if(C[B[i]]<2)
			printf("%lld\n", comb);
		else
			printf("%lld\n", (long long int)(comb - ((long long int)(C[B[i]]-1)) ));
	}

}


Measured memory_bytes: 4864
#重み付きUnion-Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)

n,m = map(int,input().split())

#初期化
#par:根なら-size,子なら親の頂点
#wei:親からの距離,根なら0
par = [-1]*(n+1)
wei = [0]*(n+1)

ans=True
for i in range(m):
    p=[int(j) for j in input().split()]
    if same(p[0],p[1]):
        if diff(p[0],p[1])!=p[2]:
            ans=False
    else:
        unite(p[0],p[1],p[2])

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8976
def main():
    x, y = list(map(int, input().strip().split()))
    groups = [
        [1, 3, 5, 7, 8, 10, 12],
        [4, 6, 9, 11],
        [2]
    ]
    answer = "No"
    for g in groups:
        if x in g and y in g:
            answer = "Yes"
            break
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
bool safe[105];
main(){
	int n,k;
	while(~getII(n,k)){
		F(i,0,105) safe[i]=0;
		F(i,0,k){
			VgetI(d);
			F(j,0,d){
				VgetI(tmp);
				safe[tmp]=1;
			}
		}
		int ans=0;
		FE(i,1,n) ans+=!safe[i];
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3864
/*input
2 2 1
3 5
3 5
2 2 2
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  int a, b, m;
  cin >> a >> b >> m;

  vector < int > v1(a), v2(b);
  int mi = SINF, ma = SINF;
  for(auto &x: v1) {
    cin >> x;
    mi = min(mi, x);
  } 

  for(auto &x: v2) {
    cin >> x;
    ma = min(ma, x);
  }

  int ans = SINF;
  for(int i = 0; i < m; i ++) {
    int x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, v1[x - 1] + v2[y - 1] - c);
  }
  cout << min(ans, mi + ma);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ", a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
#define py puts("Yes")
#define pn puts("No")
#define pY puts("YES")
#define pN puts("NO")
#define re(i, a, b) for (int i = a; i <= b; ++i)
#define de(i, a, b) for (int i = a; i >= b; --i)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const ll mode = 192600817;
template <class T>
inline void cmin(T &a, T b) { ((a > b) && (a = b)); }
template <class T>
inline void cmax(T &a, T b) { ((a < b) && (a = b)); }
int main()
{
  ll x;
  sl(x);
  double a = 100;
  int cnt = 0;
  while (a < x)
  {
    ll tem = a * (1.01);
    a = tem;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

const int maxn=1e5;

ll gcd(ll a,ll b)
{
  return b==0?a:gcd(b,a%b);
}

int main()
{
  int n;
  ll k;
  ll a[maxn];
  
  scanf("%d%lld",&n,&k);
  
  ll maxval=0;
  ll div=0;
  for(int i=0;i<n;i++)
  {
    scanf("%lld",&a[i]);
    maxval=max(maxval,a[i]);
    if(i>0)
      div=gcd(div,a[i]);
    else div=a[i];
  }
  if(maxval<k||k%div!=0) cout<<"IMPOSSIBLE"<<endl;
  else cout<<"POSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{   
    int x;
    int y;
    while(1){
        scanf("%d %d",&x , &y);
        if(x == 0 && y == 0){
            break;
        }else if(x > y){
            printf("%d %d\n", y, x);
        }else{
            printf("%d %d\n", x ,y);
        }
    }
    return 0;
}

Measured memory_bytes: 1028
N = int(input())
A_list = [0]
A_list.extend(list(map(int, input().split())))
A_list.append(0)
previous_val = 0
S = 0
for i in A_list[1:]:
    S += abs(previous_val - i)
    previous_val = i

for idx, val in enumerate(A_list):
    if idx == 0 or idx == (len(A_list) - 1):
        continue
    else:
        new_dif = abs(A_list[idx - 1] - A_list[idx + 1])
        old_dif = abs(A_list[idx - 1] - A_list[idx]) + abs(A_list[idx] - A_list[idx + 1])
        print(S + new_dif - old_dif)


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

int main() {
    int64_t N,K,S;
    cin >> N >> K >> S;
    
    vector<int64_t> A(N);

    for(int64_t i=0;i<N;i++){
        if(i<K) A[i]=S;
        else if(S!=1) A[i]=S-1;
        else A[i]=S+1;
    }

    for(int64_t i=0;i<N;i++){
        cout << A[i];
        if(i!=N-1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int judge(int a,int b,int digit){
  int cur=0;
  rep(i,0,digit){
    cur+=a;
    a*=10;
  }
  if(cur<=b) return 1;
  return 0;
}

int main(){
  string n;
  cin>>n;
  int digit=n.size();
  int dp[digit+1][2];
  dp[0][0]=0;
  dp[0][1]=1;
  rep(i,0,digit){
    if((n[i]-'0')<3){
      dp[i+1][0]=3*dp[i][0];
      dp[i+1][1]=0;
    }
    else if((n[i]-'0')==3){
      dp[i+1][0]=3*dp[i][0];
      dp[i+1][1]=dp[i][1];
    }
    else if((n[i]-'0')<5){
      dp[i+1][0]=3*dp[i][0]+dp[i][1];
      dp[i+1][1]=0;
    }
    else if((n[i]-'0')==5){
      dp[i+1][0]=3*dp[i][0]+dp[i][1];
      dp[i+1][1]=dp[i][1];
    }
    else if((n[i]-'0')<7){
      dp[i+1][0]=3*dp[i][0]+2*dp[i][1];
      dp[i+1][1]=0;
    }
    else if((n[i]-'0')==7){
      dp[i+1][0]=3*dp[i][0]+2*dp[i][1];
      dp[i+1][1]=dp[i][1];
    }
    else{
      dp[i+1][0]=3*dp[i][0]+3*dp[i][1];
      dp[i+1][1]=0;
    }
  }
  
  int dp35[digit+1][2];
  dp35[0][0]=0;
  dp35[0][1]=1;
  rep(i,0,digit){
    if((n[i]-'0')<3){
      dp35[i+1][0]=2*dp35[i][0];
      dp35[i+1][1]=0;
    }
    else if((n[i]-'0')==3){
      dp35[i+1][0]=2*dp35[i][0];
      dp35[i+1][1]=dp35[i][1];
    }
    else if((n[i]-'0')<5){
      dp35[i+1][0]=2*dp35[i][0]+dp35[i][1];
      dp35[i+1][1]=0;
    }
    else if((n[i]-'0')==5){
      dp35[i+1][0]=2*dp35[i][0]+dp35[i][1];
      dp35[i+1][1]=dp35[i][1];
    }
    else{
      dp35[i+1][0]=2*dp35[i][0]+2*dp35[i][1];
      dp35[i+1][1]=0;
    }
  }
  
  int dp37[digit+1][2];
  dp37[0][0]=0;
  dp37[0][1]=1;
  rep(i,0,digit){
    if((n[i]-'0')<3){
      dp37[i+1][0]=2*dp37[i][0];
      dp37[i+1][1]=0;
    }
    else if((n[i]-'0')==3){
      dp37[i+1][0]=2*dp37[i][0];
      dp37[i+1][1]=dp37[i][1];
    }
    else if((n[i]-'0')<7){
      dp37[i+1][0]=2*dp37[i][0]+dp37[i][1];
      dp37[i+1][1]=0;
    }
    else if((n[i]-'0')==7){
      dp37[i+1][0]=2*dp37[i][0]+dp37[i][1];
      dp37[i+1][1]=dp37[i][1];
    }
    else{
      dp37[i+1][0]=2*dp37[i][0]+2*dp37[i][1];
      dp37[i+1][1]=0;
    }
  }
  
  int dp57[digit+1][2];
  dp57[0][0]=0;
  dp57[0][1]=1;
  rep(i,0,digit){
    if((n[i]-'0')<5){
      dp57[i+1][0]=2*dp57[i][0];
      dp57[i+1][1]=0;
    }
    else if((n[i]-'0')==5){
      dp57[i+1][0]=2*dp57[i][0];
      dp57[i+1][1]=dp57[i][1];
    }
    else if((n[i]-'0')<7){
      dp57[i+1][0]=2*dp57[i][0]+dp57[i][1];
      dp57[i+1][1]=0;
    }
    else if((n[i]-'0')==7){
      dp57[i+1][0]=2*dp57[i][0]+dp57[i][1];
      dp57[i+1][1]=dp57[i][1];
    }
    else{
      dp57[i+1][0]=2*dp57[i][0]+2*dp57[i][1];
      dp57[i+1][1]=0;
    }
  }
  
  int a=dp[digit][0]+dp[digit][1]+(pow(3,digit)-3)/2;
  int a35=dp35[digit][0]+dp35[digit][1]+pow(2,digit)-2;
  int a37=dp37[digit][0]+dp37[digit][1]+pow(2,digit)-2;
  int a57=dp57[digit][0]+dp57[digit][1]+pow(2,digit)-2;
  int a3=digit-1+judge(3,stoi(n),digit);
  int a5=digit-1+judge(5,stoi(n),digit);
  int a7=digit-1+judge(7,stoi(n),digit);
  cout<<a-a35-a37-a57+a3+a5+a7<<endl;
}

Measured memory_bytes: 256
import heapq

Q = int(input())
Query = [input() for _ in range(Q)]

ans = 0

lq = []
rq = []

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        
        heapq.heappush(lq, -a)
        heapq.heappush(rq, a)

        lmax, rmin = -heapq.heappop(lq), heapq.heappop(rq)
        if lmax > rmin :
            lmax, rmin = rmin, lmax
            ans += rmin - lmax

        heapq.heappush(lq, -lmax)
        heapq.heappush(rq, rmin)

        ans += b

    else :
        print(-lq[0], ans)


Measured memory_bytes: 121432
memo = [[None for i in range(51)] for j in range(5)]
memo[0][0] = 1
for i in range(1, 51):
    memo[0][i] = 0


def f(n, sm):
    if memo[n][sm] is not None:
        return memo[n][sm]
    memo[n][sm] = 0
    for i in range(min(10, sm + 1)):
        memo[n][sm] += f(n - 1, sm - i)
    return memo[n][sm]

try:
    while True:
        print f(4, int(raw_input()))
except:
    pass

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  map<string, int> dict;
  
  for (int i = 0; i < N; ++i){
    string x; cin >> x;
    dict[x]++;
  }
  
  int max = -1;
  for (auto it = dict.begin(); it != dict.end(); ++it){
    if (max < it->second){
      max = it->second;
    }
  }
 
  
  for (auto it = dict.begin(); it != dict.end(); ++it){
    if (max == it->second){
      cout << it->first << endl;
    }
  }

}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X;
  string S,S2;
  cin >> S >> S2;
  if (S[0]==S2[2] && S[1]==S2[1] && S[2]==S2[0]) {cout << "YES" << endl;} else {cout << "NO" << endl;}
  
  
  
}


Measured memory_bytes: 256
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    vector<pii> v;
    ll pre[maxN];
    void solve(){
        ll n, x, y;
        cin >> n;
        rep(i, n){
            cin >> x >> y;
            v.pb({y, x});
        }
        sort(all(v));
        //pre[0] = v[0].snd;
        repA(i, 0, n-1){
            pre[i] = pre[i-1] + v[i].snd;
            if(pre[i] > v[i].fst){
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 6256
import std.stdio, std.string, std.conv, std.algorithm, std.range, std.typecons;

void main() {
    auto S = readln.split.to!(ulong[]);
    auto N = S[0], A = S[1], B = S[2];
    auto X = readln.split.to!(ulong[]);
    ulong res = 0;
    foreach (i; 0..N-1) {
        res += min((X[i+1] - X[i]) * A, B);
    }
    writeln(res);
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  int n, x, y, z;
  cin >> n >> x;
  int a[101] = {}, b[101] = {}, c[101] = {}, k;
  rep(i, 0, x) cin >> k, a[k] = 1;
  cin >> y;
  rep(i, 0, y) cin >> k, b[k] = 1;
  cin >> z;
  rep(i, 0, z) cin >> c[i];
  int ans = 0;
  rep(i, 0, z) if(b[c[i]] || !a[c[i]]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3176
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

cards = {}
for a in A:
	if not a in cards:
		cards[a] = 1
	else:
		cards[a] += 1

for b, c in BC:
	if not c in cards:
		cards[c] = b
	else:
		cards[c] += b

count, sum_card = 0, 0
for key in sorted(cards)[::-1]:
	value = cards[key]
	if count + value < N:
		sum_card += key * value
		count += value
	else:
		sum_card += key * (N - count)
		break

print(sum_card)


Measured memory_bytes: 51384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define f first
#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int maxi = 100001;

void add_self(int &a,int b){
	a += b;
	if(a>=mod){
		a -= mod;
	}
}

void sub_self(int &a,int b){
	a -= b;
	if(a<0){
		a += mod;
	}
}

int main()
{
	FASTIO;
	int n, k;
	cin >> n >> k;
	vector<int> dp(k+1);
	int value;
	dp[0]=1;
	for(int i=0;i<n;i++){
		cin >> value;
		vector<int> fake(k+1);
		for(int used=k;used>=0;used--){
			int tmp=dp[used];
			int L=used+1;
			int R = used+min(k-used,value);
			if(L<=R){
				add_self(fake[L],tmp);
				if(R+1<=k)
					sub_self(fake[R+1],tmp);
			}
		}
		int prefix_sum=0;
		for(int j=0;j<=k;j++){
			add_self(prefix_sum,fake[j]);
			add_self(dp[j],prefix_sum);
		}
	}
	cout << dp[k]<< "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    vector<vector<int>> memo(10,VI(10,0));
    FOR(i,1,N+1){
        int tmp = i;
        int sita = tmp % 10;
        int ue = sita;
        while(tmp/10 != 0){
            ue = tmp / 10;
            tmp /= 10;
        }
        memo[ue][sita]++;
    }
    LL ans = 0;
    REP(i,10) REP(j,10){
        if(i > j) continue;
        dump(i)
        dump(j)
        dump(memo[i][j])
        if(i == j){
            ans += memo[i][i] * memo[i][i];
        }else{
            ans += memo[i][j] * memo[j][i] * 2;
        }
        dump(ans)

    }
    cout << ans << endl;

}


Measured memory_bytes: 256
N = gets.to_i
S = N.times.map{
	gets.to_i(2)
}
D = lambda{|i0|
	d, p, q, r = -1, 0, 1<<(N-1-i0), 0
	until q == 0
		raise if 0 != q&r
		d, p, q, r = d+1, p|q, 0, (p^q)&q
		_ = r
		until 0 == (s = r&-r)
			q |= S[N-s.bit_length]
			r ^= s
		end
		r = _
	end
	return d
}
p(((0...N).map(&D).max rescue -1))


Measured memory_bytes: 1916
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

N = int(stdin.readline().rstrip().split()[0])

sqrtN = int(np.sqrt(N))
ans = 0
for i in range(1,sqrtN+1):
  if N%i == 0:
    if N//i - 1 > i:
      ans += N//i -1
    
print(ans)


Measured memory_bytes: 12508
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S;
    cin>>S;
    ll A=S[0]-'0';
    ll B=S[1]-'0';
    ll C=S[2]-'0';
    ll D=S[3]-'0';
    
    if(A+B+C+D==7){printf("%d+%d+%d+%d=7",A,B,C,D);return 0;}
    if(A+B+C-D==7){printf("%d+%d+%d-%d=7",A,B,C,D);return 0;}
    if(A+B-C+D==7){printf("%d+%d-%d+%d=7",A,B,C,D);return 0;}
    if(A+B-C-D==7){printf("%d+%d-%d-%d=7",A,B,C,D);return 0;}
    if(A-B+C+D==7){printf("%d-%d+%d+%d=7",A,B,C,D);return 0;}
    if(A-B+C-D==7){printf("%d-%d+%d-%d=7",A,B,C,D);return 0;}
    if(A-B-C+D==7){printf("%d-%d-%d+%d=7",A,B,C,D);return 0;}
    if(A-B-C-D==7){printf("%d-%d-%d-%d=7",A,B,C,D);return 0;}
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
S = input()
R_sum = [0]*N
G_sum = [0]*N
B_sum = [0]*N
rcnt = 0
gcnt = 0
bcnt = 0
cnt = 0
for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1
    R_sum[cnt] = rcnt
    G_sum[cnt] = gcnt
    B_sum[cnt] = bcnt
    cnt += 1

anssum = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]: continue
        clist = [S[i], S[j]]
        diff_idx = j - i

        if not ('R' in clist):
            anssum += (R_sum[N-1] - R_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'R':
                    anssum -= 1
        elif not ('G' in clist):
            anssum += (G_sum[N-1] - G_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'G':
                    anssum -= 1
        elif not ('B' in clist):
            anssum += (B_sum[N-1] - B_sum[j-1])
            if diff_idx + j < N:
                if S[diff_idx + j] == 'B':
                    anssum -= 1
print(anssum)


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



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  string so = "CODEFESTIVAL2016";
  int ans = 0;
  
  rep(i, 0, 16) {
    if(s.at(i) != so.at(i))
      ans++;
  }       
  cout << ans << "\n";
}


Measured memory_bytes: 256
// PCK2018 Yosen Q11 Disk
// YAMADA Terushige 2019.9.6.

#include <iostream>
#include <vector>

using namespace std;

void rebuild(int i,int K,vector <int> &m,vector <int> &t){
  i /=2;
  while(i > 0){
    int l = i*2;// left  child
    int r = l+1;// right child
    t[i] = t[l] * t[r];
    m[i] = ( m[l] + t[l]*m[r] ) % K;
    i /= 2;
  }
}

int main(){
  int K,N,Q;
  cin >> K >> N >> Q;

  // segment tree
  //        1
  //    2       3
  //  4   5   6   7

  int nleaf = 1;
  while(nleaf < N){
    nleaf <<= 1;
  }

  vector <int> m(nleaf*2);// segment tree of move
  vector <int> t(nleaf*2);// segment tree of turn (-1:turn 1:stay )

  for(int i = 0; i < nleaf*2; i++){// make tree
    t[i] = 1;
    m[i] = 0;
  }

  for(int i = 0; i < N; i++){// store leaves
    int j = nleaf +i;// nleaf:left edge leaves
    cin >> m[j];
    if(m[j] == 0) t[j] = -1;
  }

  for(int i = nleaf-1; i > 0; i--){// build tree
    int l = i*2;// left  child
    int r = l+1;// right child
    t[i] = t[l] * t[r];
    m[i] = ( m[l] + t[l]*m[r] ) % K;
  }

  for(int i = 0; i < Q; i++){
    int L,R;
    cin >> L >> R;
    L = L + nleaf - 1;;
    R = R + nleaf - 1;
    swap( m[L], m[R] );
    swap( t[L], t[R] );
    rebuild(L,K,m,t);
    rebuild(R,K,m,t);
    cout << t[1] * ((K-m[1])%K+1) << endl;
  }
  
  return 0;
}



Measured memory_bytes: 4940
def nig (x,y):
    if x[0] == y[0]: return -1 if x[1]>y[1] else 1
    return -1 if x[0] < y[0] else 1
cuc_fuk = []
for x in range(input()):
    a,b = raw_input().split()
    cuc_fuk.append((a,int(b),x+1))
for piss in sorted(cuc_fuk, cmp = nig ):
    print piss[2]

Measured memory_bytes: 85044
N = int(input())
M = [0 for i in range(N*3)]
for i in range(N):
    M[i *3], M[i * 3 +1] = input().split()
    M[i * 3 + 2] = i + 1
arr = [[0 for column in range(3)] for row in range(N)]
for i in range(N):
    arr[i][0] = M[i *3]
    arr[i][1] = int(M[i * 3 +1])
    arr[i][2] = M[i * 3 +2]
arr = sorted(arr, key=lambda x:(x[0], x[1]), reverse = True)
arr = sorted(arr, key=lambda x:x[0])
for i in range(N):
    print(arr[i][2])

Measured memory_bytes: 3064
import decimal
d = int(input())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

D_1 = 0
for i in range(d):
    L_i = abs(x[i] - y[i])
    D_1 += L_i

D_2 = 0
for i in range(d):
    L_i = abs(x[i]-y[i])**2
    D_2 += L_i
D_2 = (D_2) **(1/2)

D_3 = 0
for i in range(d):
    L_i = abs(x[i]-y[i])**3
    D_3 += L_i
D_3 = (D_3) ** (1/3)

L =[]
for i in range(d):
    L.append(abs(x[i]-y[i]))

D_ = max(L)

print('{:.8f}'.format(D_1))
print('{:.8f}'.format(D_2))
print('{:.8f}'.format(D_3))
print('{:.8f}'.format(D_))



Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll a,b;cin>>a>>b;
    ll ans = max(a+b, a-b);
    ans = max(ans, a*b);
    p(ans);
    
    return 0;
}

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

using namespace std;
using ll = long long ;

int main(){
    ll n,m;
    cin>>n>>m;
    ll ans =0;
    if (n>=3 && m>=3){
        ans += (n-2)*(m-2);
    }else if (n==1){
        ans = m-2;
    }else if (m==1){
        ans = n-2;
    }
    if (m==1 && n==1) {
        ans =1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#include<set>

const long long int MOD=1e9+7;

using namespace std;

int main(){
    long long n, h[100009];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    long long mx=0, cnt=0, cur=0;
    for(int i=0;i<n;i++){
        if(h[i]>cur){
            cur=h[i];
            mx=max(mx, cnt);
            cnt=0;
        }
        else{
            cur=h[i];
            cnt++;
        }
    }
    mx = max(mx, cnt);
    cout << mx << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h> 
#include <iostream>
#include<set>
#include<utility>
using namespace std;
#include<algorithm>
#define ll  long long 
#define MOD 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 1010;
char a[N][N];
int h, w;
ll dp[N][N];

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

	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (i == 1 && j == 1)
				dp[i][j] = 1;
			else {
				if (i - 1 > 0 && a[i - 1][j] == '.')
					dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
				if (j - 1 > 0 && a[i][j - 1] == '.')
					dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[h][w];

	return 0;
}


Measured memory_bytes: 9216
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 100000;
ll a[MAXN + 5], d[MAXN + 5];
void solve() {
	int N; scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%lld", &a[i]), d[i] = a[i];
	sort(a + 1, a + N + 1);
	int cnt = unique(a + 1, a + N + 1) - a - 1;
	if( cnt > 3 ) puts("No");
	else if( cnt == 3 ) {
		if( N % 3 || (a[1]^a[2]^a[3]) ) puts("No");
		else {
			int b[3] = {};
			for(int i=1;i<=N;i++)
				for(int j=0;j<3;j++)
					b[j] += (d[i] == a[j + 1]);
			if( b[0] != b[1] || b[1] != b[2] || b[0] != b[2] )
				puts("No");
			else puts("Yes");
		}
	}
	else if( cnt == 2 ) {
		if( a[1] || N % 3 ) puts("No");
		else {
			int b[2] = {};
			for(int i=1;i<=N;i++)
				for(int j=0;j<2;j++)
					b[j] += (d[i] == a[j + 1]);
			if( 2*b[0] != b[1] )
				puts("No");
			else puts("Yes");
		}
	}
	else if( cnt == 1 ) {
		if( a[1] ) puts("No");
		else puts("Yes");
	}
}
int main() {
	solve();
}

Measured memory_bytes: 1664
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n,a[10100],b[110][110]={},cnt=1,in=1,c[10100]={};
    cin>>h>>w>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        c[i+1]=c[i]+a[i];
    }
    rep(i,h){
        if(i%2==0)rep(j,w){
            if(c[in]>=cnt) b[i][j]=in;
            else{
                in++;
                b[i][j]=in;
            }
            cnt++;
        }
        else repr(j,w){
            if(c[in]>=cnt) b[i][j]=in;
            else{
                in++;
                b[i][j]=in;
            }
            cnt++;
        }
    }
    rep(i,h){
        rep(j,w-1) cout<<b[i][j]<<' ';
        cout<<b[i][w-1]<<endl;
    }
    return 0;
}

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

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

  vector<ll> A(n), F(n);
  for (ll i = 0; i < n; i++) cin >> A[i];
  for (ll i = 0; i < n; i++) cin >> F[i];

  sort(A.begin(), A.end()); //ascending order
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end()); //descending order

  //決め打ちで二分探索する
  ll left = -1; //leftは絶対にfalseになる値にする
  ll right = (ll)1e12+1;

  while (left + 1 < right) {
    ll mid = (left + right)/2;
    double reduce_sum = 0;
    for (ll i = 0; i < n; i++) {
      reduce_sum += max(0LL, A[i] - mid/F[i]);
    }
    if (reduce_sum <= k) right = mid;
    else left = mid;
  }

  cout << right << endl;
  return 0;
}


Measured memory_bytes: 3328
from collections import deque, defaultdict

N, K = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

dice = [0]
for i in range(1000):
  dice.append(1 + 0.5 * i)
  
lis = [0]
sum = 0
for p in P:
  sum += dice[p]
  lis.append(sum)
  
ans = 0
for i in range(N - K + 1):
  ans = max(ans, lis[K+i] - lis[i])
print(ans)

Measured memory_bytes: 25700
l = int(input())-1
n = input()+" "
s = 0
ans = 0
a = n[0]
while(s <= l):
  #print(s, l)
  while(n[s]=="R" and s <= l):
    s+=1
  while(n[l]=="W" and s <= l):
    l-=1
  if(s-1!=l):ans+=1
  s+=1
  l-=1
print(ans)
  

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

using namespace std;
typedef long long int ll;

int main()

{
    int a,b,t,rem;
    cin>>a>>b;
    if(a>b){
        t=a-b;
        rem=16-(2*b);
        if(rem>=(2*t)) cout<<"Yay!";
        else cout<<":(";
    }
    else{
        t=b-a;
        rem=16-(2*a);
        if(rem>=(2*t)) cout<<"Yay!";
        else cout<<":(";
    }

    return 0;
}


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

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )

#define INF 1000000000

void swap(int* x, int *y)
{
	int t;

	t = *x;
	*x = *y;
	*y = t;
}

int binary_search(int p[], int n, int key)
{
	int left, right, middle;

	left = 0;
	right = n-1;


	while (left <= right)
	{
		middle = (left + right) / 2;

		if (p[middle] == key)
			return middle;
		else if (p[middle] > key)
		{
			right = middle - 1;
		}
		else if (p[middle] < key)
		{
			left = middle + 1;
		}
	}

	return -1;

}

void bubble_sort(int p[], int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[i], &p[i + 1]);
		}
	}
}

int main()
{
	int i, count = 0;
	int a[10000];

	for (i = 0;; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] == 0)
			break;

		count++;
	}

	for (i = 0; i < count; i++)
		printf("Case %d: %d\n", i + 1, a[i]);


}


Measured memory_bytes: 1992