akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

int main(){
    int n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9) cout<<"hon"<<endl;
    if(n==0 || n==1 || n==6 || n==8) cout<<"pon"<<endl;
    if(n==3) cout<<"bon"<<endl;
    return 0;
}

Measured memory_bytes: 3580
w, a, b = map(int, input().split())
ans = 0
if a < b:
  if a+w > b:
    ans = 0
  else:
    ans = b - (a+w)
elif a == b:
  ans = 0
 
else:
  if b+w > a:
    ans = 0
  else:
    ans = a - (b+w)
 
print(ans)

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 10, mod = 1e9 + 7;

int n, l;
char s[N];
deque<char> Q;

int main()
{
	cin >> n >> s;
	for (int i = 0; i < n; i ++ )
		if (s[i] == ')')
		{
			if (!Q.size() || !l)
			{
				Q.push_back(s[i]);
				Q.push_front('(');
			}
			else
			{
				l -- ;
				Q.push_back(s[i]);
			}
		}
		else
		{
			l ++ ;
			Q.push_back(s[i]);
		}
		
	while (l -- ) Q.push_back(')');
	for (auto u : Q) cout << u;
	puts("");
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ARangeFlipFindRoute solver = new ARangeFlipFindRoute();
        solver.solve(1, in, out);
        out.close();
    }

    static class ARangeFlipFindRoute {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            // 左上から順に更新していけばいい
            int h = in.nextInt();
            int w = in.nextInt();
            char[][] c = new char[h][w];
            long[][] dp = new long[h][w];
            for (int i = 0; i < h; i++) {
                c[i] = in.next().toCharArray();
            }

            dp[0][0] = c[0][0] == '#' ? 1 : 0;
            for (int i = 1; i < w; i++) {
                if (c[0][i] == '#' && c[0][i] != c[0][i - 1]) {
                    dp[0][i] = dp[0][i - 1] + 1;
                } else {
                    dp[0][i] = dp[0][i - 1];
                }
            }

            for (int i = 1; i < h; i++) {
                if (c[i][0] == '#' && c[i][0] != c[i - 1][0]) {
                    dp[i][0] = dp[i - 1][0] + 1;
                } else {
                    dp[i][0] = dp[i - 1][0];
                }
            }

            for (int i = 1; i < h; i++) {
                for (int j = 1; j < w; j++) {
                    if (c[i][j] == '#') {
                        int f = c[i][j] == c[i - 1][j] ? 0 : 1;
                        int g = c[i][j] == c[i][j - 1] ? 0 : 1;
                        dp[i][j] = Math.min(dp[i - 1][j] + f, dp[i][j - 1] + g);
                    } else {
                        dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]);
                    }

                }
            }

            out.println(dp[h - 1][w - 1]);

        }

    }
}



Measured memory_bytes: 24404
#include <stdio.h>
long long  dfs(long long m,long long n);
long long count;
long long num[51];
long long x[51];
int main()
{
	int i;
	long long  m,n;
	
	x[0]=1;
	num[0]=1;
	for(i=1;i<=50;i++)
	{
		num[i]=num[i-1]*2+3;
		x[i]=x[i-1]*2+1;
	}
	while(scanf("%lld %lld",&m,&n)!=EOF)
	{
		count=0 ;
		if(m==0)
		{
			if(n==1){
				count=1;
			}else if(n==0){
				count=0;
			}
			
		}else {
			count = dfs(m,n);
		}
		
		printf("%lld\n",count);
		
	}
}

long long  dfs(long long m,long long  n)
{
	if(m==1){
		if(n==0||n==1){
			return 0;
		}else if(n==2||n==3||n==4){
			return n-1;
		}else if(n==5){
			return 3;
		}
	}else {
		if(n==1||n==0){
			return 0;
		}else if(n>1&&n<(num[m]/2+1)){
			return dfs(m-1,n-1);
		}else if(n>=num[m]/2+1&&n<num[m]){
			return x[m-1]+dfs(m-1,n-(num[m]/2+1))+1;
		}else if(n==num[m]){
			return x[m-1]+dfs(m-1,n-(num[m]/2+1)-1)+1;
		}
	}
	
	
}

Measured memory_bytes: 128
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,W = inpl()
wvs = [inpl() for _ in range(N)]
dp = [0]*(W+1)

for w,v in wvs:
    for i in reversed(range(W+1)):
        dp[i] = max(dp[i-w] + v,dp[i])
        if i == w:
            break

print(max(dp))


Measured memory_bytes: 45612
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	ll k;
	int n;
	cin >> n >> k;
	vector<ll> a(n),f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(a.begin(),a.end());
	sort(f.begin(),f.end());
	reverse(f.begin(),f.end());
	ll left = -1, right = (ll)1e13;
	ll mid;
	while(left+1<right){
		mid = (left+right)/2;
		bool ok = [&]{
			ll s = 0;
			rep(i,n) s += max(a[i]-mid/f[i],0ll);
			return s<=k;
		}();
		if(ok){
			right = mid;
		}
		else{
			left = mid;
		}
	}
	cout << right << endl;
	return 0;
}

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

N = int(input())
S_list = [input() for _ in range(N)]

AC_c = 0
WA_c = 0
TLE_c = 0
RE_c = 0
for S in S_list:
    if S == "AC\n":
        AC_c += 1
    elif S == "WA\n":
        WA_c += 1
    elif S == "TLE\n":
        TLE_c += 1
    else:
        RE_c += 1
print("AC x " + str(AC_c))
print("WA x " + str(WA_c))
print("TLE x " + str(TLE_c))
print("RE x " + str(RE_c))

Measured memory_bytes: 16276
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String cipherText;
	for (int i = 0; i < n; i++) {
	    cipherText = scan.nextLine();
	    solve(cipherText);
	}
    }
    static void solve (String cipherText) {
	int[] alpa = {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
	for (int i = 0; i < alpa.length; i++) {
	    int a = alpa[i];
	    for (int b = 0; b < 26; b++) {
		if (cipherText.contains(encode("this", a, b)) || cipherText.contains(encode("that", a, b))) {
		    System.out.println(decode(cipherText, a, b));
		    return;
		}
	    }
	}
    }
    
    static String encode (String plainText, int a, int b) {
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < plainText.length(); i++) {
	    char c = plainText.charAt(i);
	    sb.append((char)((a * (c - 'a') + b) % 26 + 'a'));
	}
	return sb.toString();
    }

    static String decode (String cipherText, int a, int b) {
	StringBuilder sb = new StringBuilder();
	int[] table = new int[26];
	for (int i = 0; i < 26; i++) {
	    int n = (a * i + b) % 26;
	    table[n] = i;
	}
	for (int i = 0; i < cipherText.length(); i++) {
	    char c = cipherText.charAt(i);
	    if (c == ' ') {
		sb.append(c);
	    } else {
		sb.append((char)(table[c - 'a'] + 'a'));
	    }
	}
	return sb.toString();
    }
}

Measured memory_bytes: 26356
#include <bits/stdc++.h>
#define N 12
#define M 1005
#define int long long
using namespace std;

const int INF = 1e9;

int n, m, a[M], b[M], c[M];
int dp[1<<N];

signed main(){
  
  cin >> n >> m;
  
  for(int i=0;i<m;i++){
    
    cin >> a[i] >> b[i];
    
    for(int j=0;j<b[i];j++){
      int bit;
      cin>>bit;
      bit--;
      c[i] |= (1<<bit);
    }
    
  }
  
  for(int i=0;i<(1<<n);i++) dp[i] = INF;
  
  dp[0] = 0;
  
  for(int i=0;i<(1<<n);i++){
    
    for(int j=0;j<M;j++){
      
      dp[i|c[j]] = min( dp[i|c[j]], dp[i] + a[j] );
      
    }
    
  }
  
  if( dp[(1<<n)-1] == INF ) cout << -1 << endl;
  else cout << dp[(1<<n)-1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		N = 1000 - N;
		int ans = 0;
		vector<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N %= m;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
	for j in range(W + 1):
		# 品物(w[i],v[i])を選ぶとき、j-w[i]>=0に限って、価値v[i]が加算される
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		# 品物(w[i],v[i])を選ばないとき、何も加算しない
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Measured memory_bytes: 120684
#include<iostream>
using namespace std;
int main(){
	int a=0;
	int b=0;
	int c=0;
	int x=0;
	int i=0;
	cin>>a>>b>>c;
	for(i=a;i<b+1;i++){
		if(c%i==0){
			x++;
		}
	}
	cout<<x<<endl;
}

Measured memory_bytes: 1164
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int sum = accumulate(a.begin(),a.end(),0LL);
  int ans = INF, now = 0;

  REP(i,n-1){
    now += a[i]; sum -= a[i];
    ans = min(ans,abs(sum-now));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b)){
		cout<<'A'<<endl;
	}
	else{
		cout<<'B'<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int min = Integer.MAX_VALUE;
        int sum = 0;
        int ans = n;

        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
            sum += m[i];
            if (min > m[i]) {
                min = m[i];
            }
        }
        sc.close();

        k -= sum;

        System.out.println(ans + k / min);
    }
}

Measured memory_bytes: 22100
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N+1];
        int[] b = new int[N+1];
        int M = 0;
        for (int i=1; i<N/2+1; i++) {
            a[i] = sc.nextInt();
        }
        for (int i=N/2+1; i<N+1; i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
            if(b[i] == 1) {
                M += 1;
            }
        }
        for (int i=N/2; i>0; i--) {
            int k = 0;
            for (int j=2*i; j<N+1; j+=i) {
                k += b[j];
            }
            if(a[i] == 0) {
                if (k % 2 == 0) {
                   b[i] = 0;
                } else {
                    b[i] = 1;
                }
            } else {
                if (k % 2 == 0) {
                   b[i] = 1;
                } else {
                   b[i] = 0;
                }
            }

            if(b[i] == 1) {
                M += 1;
            }
        }
        System.out.println(M);
        if (M > 0) {
            for (int i=1; i<N+1; i++) {
                if (b[i] == 1) {
                    System.out.print(i);
                    System.out.print(" ");
                }
            }
        }
    }
}

Measured memory_bytes: 84096
#include <stdio.h>
#define MAX 10000000
#define INFTY 1000000000

int L[MAX], R[MAX];
int cnt;

void merge(int A[], int left, int mid, int right){
  	int i,  j,  k;

  	int n1 = mid - left;
  	int n2 = right - mid;
  	for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  	for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  	L[n1] = INFTY;
  	R[n2] = INFTY;
  	i = 0;
  	j = 0;
  	for ( k = left; k < right; k++ ){
    	cnt++;
    	if ( L[i] <= R[j] ) A[k] = L[i++];
    	else A[k] = R[j++];
  	}
}

void mergeSort(int A[], int left, int right ){
  int mid;
  if ( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(){
  int  i, n, A[MAX];
  cnt = 0;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%d", &A[i]);
    if (A[i] >= INFTY ){
      return 1;
    }
  }
  mergeSort(A, 0, n);

  for ( i = 0; i < n; i++ ) {
    if ( i ) printf(" ");
    printf("%d", A[i]);
    }
  printf("\n");

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

  return 0;
}


Measured memory_bytes: 5704
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        String t = stdIn.next();
        int a = Integer.parseInt(stdIn.next());
        int b = Integer.parseInt(stdIn.next());
        String u = stdIn.next();

        if (u.equals(s)) {
            a--;
        } else if (u.equals(t)) {
            b--;
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 21844
mark = ["S","H","C","D"]
numbers = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]

cardlist = {}

for m in mark:
    for n in numbers:
        key = m + " " + n
        cardlist[key] = 0


n = int(input())

for _ in range(n):
    card = input()
    cardlist[card] = 1


for card in cardlist:
    if cardlist[card] == 0:
        print(card)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  vl sum(n + 1, 0);
  rep(i, n) sum[i + 1] = sum[i] + a[i];
  ll ok = 0, ng = 1e18, ans = 0, cnt0;
  while(ok + 1 < ng) {
    ll s = (ok + ng) / 2;
    ll cnt = 0, now = 0;
    rep(i, n) {
      ll it = lower_bound(all(a), s - a[i]) - a.begin();
      cnt += n - it;
      now += a[i] * (n - it) + sum[n] - sum[it];
    }
    if(cnt >= m) {
      ok = s;
      cnt0 = cnt;
      ans = now;
    } else
      ng = s;
  }
  ans -= ok * (cnt0 - m);
  cout << ans << endl;
}

Measured memory_bytes: 1792
/*************************************************************************
    > File Name: test.cpp
    > Author: Rylynnn
    > Mail: jingry0321@gmail.com
    > Created Time: 一 11/ 6 21:53:23 2017
 ************************************************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100007;
int n, a[N], b[N], c[N];
ll ans[N], h[N], tmp;
int main()
{
    cin >> n;
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    for(int i=0; i<n; ++i){
        cin >> b[i];
    }
    for(int i=0; i<n; ++i){
        cin >> c[i];
    }
    int q = 0, p = 0, k = 0;
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    while(p < n) {
        while(b[p] >= c[k] && k < n) {
            k++;
        }
        h[p] = n-k;
        //cout << h[p] << endl;
        p++;
    }
    p = 0;
    memset(ans, 0, sizeof(ans));
    for(int i=n-1; i>=0; i--){
        ans[i] = ans[i+1] + h[i];
        //cout << ans[i] << endl;
    }
    tmp = 0;
    while(q < n){
        while(a[q] >= b[p] && p < n) {
            p++;
        }
        tmp += ans[p];
        q++;
    }
    cout << tmp << endl; 
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,r[4005],g[4005],b[4005];
string s;
ll ans=0;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	cin>>s;
	if(n<3) return cout<<0,0;
	b[0]=g[0]=r[0]=1;
	if(s[0]=='B') b[0]=1;
	else if(s[0]=='G') g[0]=1;
	else if(s[0]=='R') r[0]=1;
	for(int i=1; i<n; i++) {
		b[i]=b[i-1];
		r[i]=r[i-1];
		g[i]=g[i-1];
		if(s[i]=='B') b[i]++;
		else if(s[i]=='G') g[i]++;
		else if(s[i]=='R') r[i]++;
	}
	for(int i=0;i<n-2;i++){
		for(int j=i+2;j<n;j++){
			if(s[i]==s[j]) continue;
			if(s[i]=='R'){
				if(s[j]=='B'){
					ans+=g[j]-g[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='G') ans--;
				}else if(s[j]=='G'){
					ans+=b[j]-b[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='B') ans--;
				}
			}else if(s[i]=='B'){
				if(s[j]=='R'){
					ans+=g[j]-g[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='G') ans--;
				}else if(s[j]=='G'){
					ans+=r[j]-r[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='R') ans--;
				}
			}else if(s[i]=='G'){
				if(s[j]=='B'){
					ans+=r[j]-r[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='R') ans--;
				}else if(s[j]=='R'){
					ans+=b[j]-b[i];
					if((j-i-1)%2==0) continue;
					if(s[(i+j)/2]=='B') ans--;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  rep2(i, A, B+1){
    string s = to_string(i);
    string t = to_string(i);
    reverse(all(t));
    if(s == t){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
from math import gcd as g
n = int(input())
mod = 10**9+7
sardines = set()
Ddic = defaultdict(int)
ans = 1
zcount = 0
for i in range(n):
  a,b = map(int,input().split())
  if a == 0 and b == 0:
    zcount += 1
    continue

  if a == 0:
    Ddic[(0,1)] += 1
    sardines.add((0,1))
    continue

  if b == 0:
    sardines.add((1,0))
    Ddic[(1,0)] += 1
    continue

  A,B = abs(a),abs(b)
  G = g(A,B)
  a //= G
  b //= G

  if b < 0:
    a = -a
    b = -b

  Ddic[(a,b)] += 1
  sardines.add((a,b))

for i in sardines:
  if i == (0,0) or (i[0] <= 0 and Ddic[(i[1],-i[0])] != 0):continue
  if i[0] <= 0:
    ans *= (2**Ddic[i] + 2**(Ddic[(i[1],-i[0])]))-1
  else:
    ans *= (2**Ddic[i] + 2**(Ddic[(-i[1],i[0])]))-1

  ans %= mod
print((ans+zcount-1)%mod)


Measured memory_bytes: 208892
//
//  ABC060pB.cpp
//  
//
//  Created by 楊承昊 on 2017/4/29.
//
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    long long int a,b,c;
//    cout<<"YES"<<endl;
    while(cin>>a>>b>>c)
    {
        int legal=0;
        long long int sum=a,mark=sum%b;
        if(mark==c)
            legal=1;
        sum+=a;
//        cout<<mark<<endl;
        long long int next=sum%b;
        while(mark!=sum%b&&legal==0)
        {
            if(sum%b==c)
                legal=1;
            sum+=a;
//            cout<<sum<<endl;
        }
        if(legal) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int m, d[212345];
    ll c[212345];

    ll sum = 0;
    ll ds = 0;

    cin >> m;
    REP(i, m)
    {
        cin >> d[i] >> c[i];
        sum += c[i] * d[i];
        ds += c[i];
    }

    ll res = (ds - 1) + (sum - 1) / 9;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm;
typedef vector<vm> vvm;

void solve() {
    ll n, s;
    cin >> n >> s;
    vll a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];
	vvm dp(n + 1, vm(s + 1));
	dp[0][0] = 1;
	for(ll i = 0; i < n; i++) {
		dp[i + 1][0] += 1;
		for(ll j = 0; j <= s; j++) {
			dp[i + 1][j] += dp[i][j];
			if(j + a[i] <= s) dp[i + 1][j + a[i]] += dp[i][j];
		}
	}
	mint ans;
	for(ll i = 0; i <= n; i++) ans += dp[i][s];
	cout << ans.x << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

// 
int N;
long long L[100];
int countOK = 0;

void calc(int no, int calcCount, int nos[3]) {
    // cout << "lll" << endl; // debug
    if (calcCount == 3) {
        if (L[nos[0]] != L[nos[1]] && L[nos[0]] != L[nos[2]] && L[nos[1]] != L[nos[2]] &&
            L[nos[0]] + L[nos[1]] > L[nos[2]] &&
            L[nos[1]] + L[nos[2]] > L[nos[0]] &&
            L[nos[0]] + L[nos[2]] > L[nos[1]])
        {
            // cout << "OK: " << nos[0] + 1 << ", " << nos[1] + 1 << ", " << nos[2] + 1 << endl; // debug
            countOK++;
        }
        return;
    }
    // cout << calcCount << " count : " << no + 1 << " no" << endl; // debug
    for (int i = no; i < N - (2 - calcCount); i++) {
        // cout << "i:" << i << ", N:" << N - (2 - calcCount) << endl;
        nos[calcCount] = i;
        calc(i + 1, calcCount + 1, nos);
    }
}

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


    int nos[3];
    for (int i = 0; i < N - 2; i++) {
        nos[0] = i;
        calc(i + 1, 1, nos);
    }
    cout << countOK;
}


Measured memory_bytes: 3504
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

char buf[SIZE];

int main(){

	int len;
	scanf("%d",&len);
	scanf("%s",buf);

	stack<int> S;
	int num_W = 0,num_R = 0;

	for(int i = 0; buf[i] != '\0'; i++){

		if(buf[i] == 'R'){

			num_R++;
			S.push(i);

		}else{

			num_W++;
		}
	}

	if(num_R == 0 || num_W == 0){

		printf("0\n");
		return 0;
	}

	int ans = 0;
	for(int i = 0; i < len; i++){

		if(buf[i] == 'R')continue;

		if(i < S.top()){

			S.pop();
			ans++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 4552
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define Z (128)

void mul(double (*a)[Z], const double (*b)[Z]) {
    static double t[Z][Z];
    memset(t, 0, sizeof(t));
    rep(k, Z) rep(i, Z) rep(j, Z) t[i][j] += a[i][k]*b[k][j];
    memcpy(a, t, sizeof(t));
}

void pow(double (*a)[Z], int x) {
    static double p[Z][Z];
    memcpy(p, a, sizeof(p));
    rep(i, Z) rep(j, Z) a[i][j] = i==j ? 1.0 : 0.0;
    rep(b, 32) {
        if(x&(1<<b)) mul(a, p);
        mul(p, p);
    }
}

void eqsolve(int n, double (*a)[Z]) {
    rep(k, n) {
        double mx = -1;
        int ix = -1;
        for(int i=k; i<n; i++) if(mx<fabs(a[i][k])) mx=fabs(a[i][k]), ix=i;
        if(k!=ix) rep(i, n+1) swap(a[k][i], a[ix][i]);
        const double p = a[k][k];
        for(int i=k; i<=n; i++) a[k][i] /= p;
        rep(i, n) if(i!=k) {
            const double d = a[i][k];
            for(int j=k; j<=n; j++) a[i][j] -= d*a[k][j];
        }
    }
}

int S, N, K;
double p[Z][Z], eqs[Z][Z], mat[Z][Z];

int main() {
    scanf("%d%d%d", &S, &N, &K);
    S = abs(S);
    if(N==1) {
        printf("%.9f\n", S%K==0 ? (double)(S/K) : 0.0);
        return 0;
    }
    p[0][0] = 1.0;
    const int M = N*K+1;
    rep(i, K) rep(j, M) rep(k, N) p[i+1][j+k+1] += p[i][j]/N;
    eqs[0][0] = 1;
    for(int k=1; k<M; k++) {
        eqs[k][k] = 1;
        rep(j, M) eqs[k][abs(k-j)] -= p[K][j];
        eqs[k][M] = -1;
    }
    eqsolve(M, eqs);
    if(S<M) printf("%.9f\n", fabs(eqs[S][M]));
    else {
        rep(i, M) mat[0][i] = p[K][i+1];
        mat[0][M] = 1;
        rep(i, M-1) mat[i+1][i] = 1;
        mat[M][M] = 1;
        pow(mat, S-M+1);
        double ans = 0;
        rep(i, M) ans += mat[0][i]*fabs(eqs[M-1-i][M]);
        ans += mat[0][M];
        printf("%.9f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	string s;
	int con = 0;
	stack<int> sta;
	
	cin>>N>>s;
	
	// cout<<(int)')'<<" "<<(int)'('<<endl;
	
	for(int i = 0; i < N; i++){
		if(s[i] == '('){
			sta.push(0);
			
		} else {
			if(sta.size() == 0){
				// cout<<"(";
				con++;
			} else {
				sta.pop();
			}
			
		}
		// cout<<s[i];
	}
	
	for(int i = 0; i < con; i++){
		cout<<"(";
	}
	
	cout<<s;
	for(int i = 0; i < sta.size(); i++){
		cout<<")";
	}
	cout<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

ll dp[55][55][3000];

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

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

    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < 2500; ++k){
                if(dp[i][j][k] == 0)    continue;
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
            }
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; ++i) ans += dp[n][i][i * a];
    cout << ans << endl;
}

Measured memory_bytes: 65792
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
const LL lm=1LL*mod*mod;

static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

typedef long long Int;
Int segMin[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

//区間[a, b)に値xを加算する.
void add(Int a, Int b, Int x, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return; //もし交差しない区間であれば終える.

	if (a <= l && r <= b){ //もし今みている区間[l, r)が[a, b)に完全に内包されていれば
		segAdd[k] = min(x,segAdd[k]);  //区間[l, r)にkを加算する.
		return;
	}

	add(a, b, x, k * 2 + 1, l, (l + r) / 2); //子の区間に(必要があれば)xを加算する.
	add(a, b, x, k * 2 + 2, (l + r) / 2, r); //〃

	//親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である.一様に加算される値は更新しなくて良い.
	segMin[k] = min(min(segMin[k * 2 + 1] , segAdd[k * 2 + 1]), min(segMin[k * 2 + 2] , segAdd[k * 2 + 2]));
}

Int getMin(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return (lm);

	if (a <= l && r <= b) return min(segMin[k] , segAdd[k]); //完全に内包されていれば,その区間の最小値を返す.

	Int left = getMin(a, b, k * 2 + 1, l, (l + r) / 2); //子の区間の最小値を求める.
	Int right = getMin(a, b, k * 2 + 2, (l + r) / 2, r); //子の区間の最小値を求める

	return min(min(left, right) , segAdd[k]); //親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である (大切なので2回書きました!!)

}

int main(){
	int n,m;
	cin>>n>>m;
	vl l(m),r(m),c(m);
	priority_queue<array<LL,3>> pq;
	FOR(i,0,m){
		cin>>l[i]>>r[i]>>c[i];
		pq.push({-l[i],-r[i],c[i]});
	}
	FORQ(i,0,2 * MAX_SIZE - 1){
    segAdd[i]=segMin[i]=lm;
  }
	add(1,2,0);
	cerr<<"test"<<endl;
	while(pq.size()){
		auto tpl=pq.top();
		pq.pop();
		LL ll=-tpl[0];
		LL rr=-tpl[1];
		LL cc=tpl[2];
		//cerr<<ll<<" "<<rr<<" "<<cc<<"  "<<getMin(ll,ll+1)<<endl;
		LL scr=getMin(ll,ll+1)+cc;
		add(ll+1,rr+1,scr);
	}
	if(getMin(n,n+1)==lm){
		cout<<-1;
	}else cout<<getMin(n,n+1);

}


Measured memory_bytes: 9840
import heapq
q = int(input())
l = []
r = []
ai = 0
bs = 0
for i in range(q):
    ipt = list(map(int,input().split()))
    if ipt[0] == 1:
        al = heapq.heappushpop(l,-ipt[1])
        ar = heapq.heappushpop(r,ipt[1])
        ai -= (al+ar)
        heapq.heappush(l,-ar)
        heapq.heappush(r,-al)
        bs += ipt[2]
    else:
        an = heapq.heappop(l)
        print(-an,bs+ai)
        heapq.heappush(l,an)


Measured memory_bytes: 19056
import numpy as np
n,k=map(int,input().split())
h=np.array(list(map(int,input().split())))
dp=np.zeros(n,dtype=int)
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    if i-k>0:
        dp[i]=min(dp[i-k:i]+abs(h[i]-h[i-k:i]))
    elif 0>=i-k:
        dp[i]=min(dp[0:i]+abs(h[i]-h[0:i]))
print(dp[n-1])

Measured memory_bytes: 22828
#include<stdio.h>

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    while(x!=0||y!=0)
    {
        if(x<y) printf("%d %d\n",x,y);
        else printf("%d %d\n",y,x);
        scanf("%d%d",&x,&y);
    }
    return 0;
}



Measured memory_bytes: 1972
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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


Measured memory_bytes: 256
Class Main
    Public Shared Sub Main()
    Dim NM() As string = Split(Console.ReadLine())
    dim N as integer = cint(NM(0))
    dim M as integer = cint(NM(1))
    dim HS() as string = Split(Console.ReadLine())
    dim H(N + 1) as long
    dim i1,i2 as integer
    for i1 = 0 to N - 1
    	H(i1 + 1) = clng(HS(i1))
  	next i1
    for i1 = 1 to M    
	    Dim AB() As string = Split(Console.ReadLine())
  dim A as integer = cint(AB(0))
  dim B as integer = cint(AB(1))
  		if H(A) < H(B) then
    		HS(A - 1) = ""
  elseif H(A) > H(B) then
    		HS(B - 1) = ""
  else
    		HS(A - 1) = ""
    		HS(B - 1) = ""
  		end if
	next i1  
	i2 = 0
for i1 = 0 to N - 1
		if HS(i1) <> "" then
			i2 += 1
		end if
  	next i1
      Console.WriteLine(i2)
   End Sub
End Class


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

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

   map<int,int> count;
   for (auto a : A) {
      ++count[a];
   }
   count[0] = 2;

   vector<int> best;
   for (auto i = count.rbegin(); i != count.rend(); ++i) {
      int a = i->first, num = i->second;
      while (num >= 2 && best.size() < 2) {
         num -= 2;
         best.push_back(a);
      }
      if (best.size() == 2) break;
   }

   cout << best[0] * best[1] << endl;

   return 0;
}


Measured memory_bytes: 7296
from collections import Counter

N = int(input())
inputs = [int(i) for i in input().split()]

inputs.sort(reverse=True)
counter_inputs = Counter(inputs)
powers_of_two = [2**i for i in range(1, 31)]
ans = 0

for item in inputs:
    if counter_inputs[item] > 0:
        counter_inputs[item] -= 1
    
        while powers_of_two[-1] > 2 * item:
            powers_of_two.pop(-1)
        
        pair = powers_of_two[-1] - item
        if counter_inputs[pair] > 0:
            ans += 1
            counter_inputs[pair] -= 1
    
print(ans)


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

int main(){
  int n;
  cin >> n;
  int l, r;
  l = 0; r = n;
  string sl, sr, sm;
  cout << 0 << endl;
  fflush(stdout);
  cin >> sl;
  if(sl == "Vacant") return 0;
  sr = sl;
  while(true) {
    int m = (l+r)/2;
    cout << m << endl;
    fflush(stdout);
    cin >> sm;
    if(sm == "Vacant") return 0;
    if((m-l) % 2) {
      if(sl == sm) {
        r = m; sr = sm;
      } else {
        l = m; sl = sm;
      }
    } else {
      if(sl == sm) {
        l = m; sl = sm;
      } else {
        r = m; sr = sm;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 852
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int combimax = 55;
vvll combi(combimax+1,vll(combimax+1,0));
void combination(){
    combi[0][0]=1LL;
    for(int i=1;i<=combimax;i++){
        combi[i][0]=1LL;
        for(int j=1;j<=i-1;j++){
            combi[i][j]=combi[i-1][j]+combi[i-1][j-1];
        }
        combi[i][i]=1LL;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    combination();
    int n;
    int p;
    cin >> n >> p;
    int o=0,e=0;
    REP(i,n){
        int a;
        cin >> a;
        if(a%2==0){
            e++;
        }else{
            o++;
        }
    }
    ll ans = 1LL;
    ans <<= e;
    ll od = 0LL;
    for(int i=p;i<=o;i+=2){
        od += combi[o][i];
    } 
    ans *= od;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(ll i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

vector<pll> ans;
ll K;

//X,Yまで幅KでN回追う
void trace(ll X, ll Y, ll N){
    if(X <= Y){
        rep2(i, 1, N){
            if(i*K <= X) ans.pb(pll(i*K, 0));
            else ans.pb(pll(X, i*K-X));
        }
    }
    else{
        rep2(i, 1, N){
            if(i*K <= Y) ans.pb(pll(0, i*K));
            else ans.pb(pll(i*K-Y, Y));
        }
    }
}

//(sx,sy)から(X,Y)まで幅Kで2回で行く
void finish(ll sx, ll sy, ll X, ll Y){
    ll R = X-sx + Y-sy;
    if(X-sx <= Y-sy){
        ans.pb(pll(X+K-R/2, Y-R/2));
    }
    else{
        ans.pb(pll(X-R/2, Y+K-R/2));
    }
    ans.pb(pll(X, Y));
}

int main(){
    ans.pb(pll(0, 0));
    ll x, y;
    cin >> K >> x >> y;
    ll X = abs(x), Y = abs(y), R = X+Y;
    //奇数、偶数
    if(R%2 == 1 && K%2 == 0){
        cout << -1 << endl;
        return 0;
    }
    //偶数、偶数
    elif(R%2 == 0 && K%2 == 0){
        if(R == K){
            ans.pb(pll(X, Y));
        }
        else{
            //n*K>=Rとなる最小のn
            ll n = (R+K-1)/K;
            trace(X, Y, n-2);
            pll p = ans[ans.size()-1];
            finish(p.first, p.second, X, Y);
        }
    }
    //偶数、奇数
    elif(R%2 == 0 && K%2 == 1){
        //n*K>=Rとなる最小の偶数n
        ll n = (R+K-1)/K;
        if(n%2 == 1) n++;
        trace(X, Y, n-2);
        pll p = ans[ans.size()-1];
        finish(p.first, p.second, X, Y);
    }
    //奇数、奇数
    else{
        if(R == K){
            ans.pb(pll(X, Y));
        }
        elif(R < K){
            ans.pb(pll(-K, 0));
            finish(-K, 0, X, Y);
        }
        else{
            //n*K>=Rとなる最小の奇数n
            ll n = (R+K-1)/K;
            if(n%2 == 0) n++;
            trace(X, Y, n-2);
            pll p = ans[ans.size()-1];
            finish(p.first, p.second, X, Y);
        }
    }
    cout << ans.size()-1 << endl;
    ll a = 1, b = 1;
    if(x < 0) a *= -1;
    if(y < 0) b *= -1;
    rep2(i, 1, ans.size()-1){
        cout << a*ans[i].first << ' ' << b*ans[i].second << endl;
    }
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
 
typedef __int128 LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 100000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}
 
LL fpm(LL a, LL b, LL mod) {
    LL res = 1;
    for(; b > 0; b >>= 1) {
        if(b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
 
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
 
LL exgcd(int a, int b, LL& x, LL& y) {
    if(!b) {
        x = 1;
        y = 0;
        return a;
    }
 
    LL g = exgcd(b, a % b, y, x);
    y -= (a / b) * x;
 
    return g;
}
 
int phi(int n) {
    int res = n;
    for(int i = 2; i * i <= n; ++i) if(n % i == 0) {
        res = res / i * (i - 1);
        while(n % i == 0) n /= i;
    }
    if(n > 1) res = res / n * (n - 1);
    return res;
}
 
LL solve(int a, int m) {
    if(m <= 500) {
        int x = a;
        for(int i = 1; ; i++) {
            if(x == i % m) return i;
            x = 1LL * x * a % m;
        }
    }
    
    int p = phi(m);
    int r = gcd(m, p);
    LL t = solve(a, r), a_t = fpm(a, t, m), x, y, l = p / r;
 
    exgcd(m / r, p / r, x, y);
 
    x *= (((t - a_t) % p + p) % p) / r;
    x = (x % l + l) % l + l;
    LL res = x * m + a_t;
 
    assert(x>0);
    return res;
}
 
void write(LL x) {
    if(x) { 
        write(x / 10);
        putchar(x % 10 + '0');
    }
}
 
int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
 
    for(int T = read<int>(); T--; ) {
        static int a, m;
        a = read<int>();
        m = read<int>();
        LL k = solve(a, m);
        write(k); putchar(10);
    }
 
    return 0;
}

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

int main()
{
	string s;
	cin >> s;
	int i = 0;
	int cnt = 0;
	if (s[0] == s[1] && s[1] == s[2])
		cout << "Yes" << endl;
	else if (s[1] == s[2] && s[2] == s[3])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return (0);
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <assert.h>  
#include <cstring>  
#include <algorithm>  
#include <vector>  
#include <map>  
#include <cmath>  
#include <set>  
#include <queue>  
const int INF=1e9+10;  
const double EPS = 1e-10;    
typedef long long ll;  
const ll mod=998244353;

char s[100];
int main(){
    while(scanf("%s",s+1)!=EOF){
        int len=strlen(s+1);
        int flag=1;
        for(int i=1;i<=len/2;i++)
            if(s[i]!=s[len-i+1]) flag=0;
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if(s.equals(t.substring(0,s.length()))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35596
#include <bits/stdc++.h> 
using namespace std; 
int block; 
struct Query 
{ 
	int L, R; 
}; 
map<pair<int,int>,int> mp;
bool compare(Query x, Query y) 
{  
	if (x.L/block != y.L/block) 
		return x.L/block < y.L/block; 
	return x.R < y.R; 
} 
void queryResults(int a[], int n, Query q[], int m) 
{ 
	block = (int)sqrt(n); 
	sort(q, q + m, compare); 
	int x=0;
	int arr[600000];
	for(int i=0;i<600000;i++) arr[i]=0;
	for(int i=0;i<n;i++)
	{
	   if(arr[a[i]]==0) x++;	
	   arr[a[i]]++;	
	}
	int currL=0;
	int currR=n;
	//mp[make_pair(q[0].L,q[0].R)]=x;
	for (int i=0; i<m; i++) 
	{ 
		int L = q[i].L, R = q[i].R; 
		while (currL < L) 
		{ 
			if(arr[a[currL]]==1)
			 x--;
			arr[a[currL]]--; 
			currL++; 
		} 
		while (currL > L) 
		{ 
			if(arr[a[currL-1]]==0)
			 x++;
			arr[a[currL-1]]++; 
			currL--; 
		} 
		while (currR <= R) 
		{ 
			if(arr[a[currR]]==0)
			 x++;
			arr[a[currR]]++; 
			currR++;
		} 
		while (currR > R+1) 
		{ 
			 if(arr[a[currR-1]]==1)
			  x--;
			 arr[a[currR-1]]--; 
			currR--; 
		} 
	  mp[make_pair(q[i].L,q[i].R)]=x;	
	} 
} 

// Driver program 
int main() 
{ 
	    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]--;
	}
	Query q[m];
	Query ns[m];
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		q[i].L=a;
		q[i].R=b;
		ns[i].L=a;
		ns[i].R=b;
	}
	queryResults(a, n, q, m); 
	//cout<<q[1].L<<" "<<q[1].R<<endl;
	for(int i=0;i<m;i++)
	 {
	 	cout<<mp[make_pair(ns[i].L,ns[i].R)]<<"\n";
	 }
	return 0; 
} 

Measured memory_bytes: 47152