akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int number = sc.nextInt();
		int[] n = new int[]{
				number/1000,
				number%1000 / 100,
				number%100 / 10,
				number%10
		};
		String[][] dp = new String[n.length+1][81];
		for (int i = 0; i < dp.length; i++) {
			Arrays.fill(dp[i], "INF");
		}
		dp[1][40+n[0]] = "root";
		for (int i = 1; i < n.length; i++) {
			for (int j = 0; j < dp[i].length; j++) {
				if (dp[i][j] != "INF") {
					dp[i+1][j+n[i]] = "+";
					dp[i+1][j-n[i]] = "-";
				}
			}
		}
		int p = 47;
		String[] op = new String[3];
		for (int i = 4; i > 1; i--) {
			op[i-2] = dp[i][p];
			if (dp[i][p] == "+") {
				p = p - n[i-1];
			}else if (dp[i][p] == "-") {
				p = p + n[i-1];
			}	
		}
		out.print(n[0]);
		for (int i = 0; i < op.length; i++) {
			out.print(op[i]);
			out.print(n[i+1]);
		}
		out.println("=7");
		out.close();
	}
	
	

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}



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

int main() {
    string S;
    cin >> S;
    if (S == "Sunny"){
        cout << "Cloudy" <<endl;
    } else if (S == "Cloudy"){
        cout << "Rainy" <<endl;
    } else {
        cout << "Sunny" <<endl;
    }
}


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

int main() {
    int N;
    cin >> N;
    int a[N];
    int max_sum = 0;

    for (int i=0; i<N; i++)
    {
        cin >> a[i];
        max_sum += a[i] - 1;
    }

    cout << max_sum;

    return 0;
}


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

using namespace std;

int main(){
    string str;
    cin >> str;
    int length = str.size();
    int s1, s2;
    s1 = 0;
    s2 = 0;
    string img1(length, '0');
    string img2(length, '0');
    if(length%2 == 0){
        for (int i = 0; i < length / 2;i++){
            img1[2 * i] = '1';
        }
        for (int i = 0; i < length;i++){
            if(str[i] != img1[i]){
                s1 += 1;
            }
        }
    }else if(length%2==1){
        for (int i = 0; i < (length + 1) / 2;i++){
            img1[2 * i] = '1';
        }
        for (int i = 0; i < length;i++){
            if(str[i]!=img1[i]){
                s1 += 1;
            }
        }
    }

    if(length%2 == 0){
        for (int i = 0; i < length / 2;i++){
            img2[2 * i + 1] = '1';
        }
        for (int i = 0; i < length;i++){
            if(str[i] != img2[i]){
                s2 += 1;
            }
        }
    }else if(length%2 ==1){
        for (int i = 0; i < (length-1) / 2;i++){
            img2[2 * i + 1] = '1';
        }
        for (int i = 0; i < length;i++){
            if(str[i] != img2[i]){
                s2 += 1;
            }
        }
    }

    cout << min({s1, s2}) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N, M;
    cin >> N >> M;
    vector<bool> is(N+1, true);
    vector<ll> dp(N+1, 0);
    rep(i, M){
        int a;
        cin >> a;
        is[a] = false;
    }

    int mod = pow(10, 9)+7;
    dp[0] = 1;
    rep(i, N){
        for(int j = i+1; j <= min(i+2, N); j++){
            if(is[j]){
                dp[j] = (dp[j] + dp[i]) % mod;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 4004
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,m,c; cin >> n >> m >> c;
    int b[m]; REP(i,m) cin >> b[i];
    int a[n][m]; REP(i,n)REP(j,m) cin >> a[i][j];
    int ans = 0;
    REP(i,n){
        int total = 0;
        REP(j,m) total += b[j]*a[i][j];
        if(total+c>0)ans++;
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 1000005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    int n, pk = 0;
    cin>>n;
    ll a[n],b[n] = {0};
    rep(i, n){
        cin >> a[i];
        if(i%2){ 
            pk -= a[i];
        }
        else{
            pk += a[i];
        }
    }
    b[0] = pk;
    fo(i, 1, n-1){
        b[i] = 2*a[i-1] - b[i-1];
    }
    rep(i, n){
        cout << b[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
        char op;
        int a,b;
        int retval;
        while(1) {
                scanf("%d %c %d",&a,&op,&b);


                switch(op) {
                case '+':
                        retval=a+b;
                        break;
                case '-':
                        retval=a-b;
                        break;
                case '*':
                        retval=a*b;
                        break;
                case '/':
                        retval=a/b;
                        break;
                case '?':
                        return 0;
                }
                cout<<retval<<endl;
        }

}



Measured memory_bytes: 3220
import itertools
import math

n, d = map(int,input().split())
vecList = []
for i in range(n):
  vecList.append(list(map(int,input().split())))

cVec = list(itertools.combinations(vecList,2))
count = 0

for i in cVec:
  sqT = 0
  for j in range(d):
    sqT += (i[0][j]-i[1][j])**2
  sqT = math.sqrt(sqT)
  if sqT.is_integer():
    count += 1

print(count)


Measured memory_bytes: 3064
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n, a, b;
int x[maxn];

int read() {
  if (scanf("%d%d%d", &n, &a, &b) < 3) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  return true;
}

void solve() {
  long long res = 0;
  for (int i = 0; i + 1 < n; i++) {
    res += min((long long) b, (long long) (x[i + 1] - x[i]) * a);
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
N = int(input())
def f(x):
  if x!='' and int(x) > N:
    return 0
  n = 0
  if '3' in x and '5' in x and '7' in x:
    n = 1
  for c in '357':
    n += f(x+c)
  return n
print(f(''))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long a[10000];
int main(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<((a[0]&1&a[1]&1&a[2]&1)?a[0]*a[1]:0)<<endl;
    return 0;
}

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X; X /= 50;
	int res = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				res += i * 10 + j * 2 + k == X;
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int beg[100100],nex[200100],tto[200100],e;
void putin(int s,int t){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
}
int stk[100100],top;
int ttk[100100],ttp;
bool vis[100100];
int main(){
//	freopen("B.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	int s,t;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&s,&t);
		putin(s,t);
		putin(t,s);
	}
	s=1,t=1;
	vis[1]=1;
	bool bo;
	while(1){
		bo=0;
		for(int i=beg[s];i;i=nex[i]){
			if(!vis[tto[i]]){
				s=tto[i];
				ttk[++ttp]=s;
				bo=1;
				break;
			}
		}
		vis[s]=1;
		if(!bo) break;
	}
	while(1){
		bo=0;
		for(int i=beg[t];i;i=nex[i]){
			if(!vis[tto[i]]){
				t=tto[i];
				stk[++top]=t;
				bo=1;
				break;
			}
		}
		vis[t]=1;
		if(!bo) break;
	}
	printf("%d\n",ttp+top+1);
	for(int i=ttp;i>=1;i--)
		printf("%d ",ttk[i]);
	printf("1");
	for(int i=1;i<=top;i++)
		printf(" %d",stk[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
// N - Slimes

using namespace std;

long long psa[404];
long long dp[404][404];

int main() {
    int N,i,j,k,a;

    scanf("%d",&N);

    for (i = 1;i <= N;i++) {
        scanf("%d",&a);
        psa[i] = psa[i - 1] + a;
    }

    memset(dp,0x3f,sizeof(dp));

    for (i = 1;i <= N;i++)
        dp[i][i] = 0;

    for (i = 1;i < N;i++) {
        for (j = 1;i + j <= N;j++) {
            for (k = j;k < i + j;k++)
                dp[j][i + j] = min(dp[j][i + j],dp[j][k] + dp[k + 1][i + j]);
            dp[j][i + j] += (psa[i + j] - psa[j - 1]);
        }
    }

    printf("%lld\n",dp[1][N]);

    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++) {
    cin >> s[i];
  }
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      int cnt = 0;
      if(s[i][j] == '.') {
        for(int x=-1;x<=1;x++) {
          for(int y=-1;y<=1;y++) {
            if(i+x >= 0 && j+y >= 0 && i+x < h && j+y < w) {
              if(s[i+x][j+y] == '#')
                cnt++;
            }
          }
        }
        s[i][j] = char(cnt+'0');
      }
    }
  }
  for(int i=0;i<h;i++)
    cout << s[i] << endl;
}



Measured memory_bytes: 256
N = int(input())

P = []
for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))
        continue
    P.append(int(input().split()[1]))

dp = [[float("inf")]*N for _ in range(N)]

for i in range(N):
    dp[i][i] = 0

for l in range(1, N):  
    for i in range(N):
        j = i+l
        if j < N:
            for k in range(i, j): 
                dp[i][j] = min(dp[i][k] + dp[k+1][j] + P[i]*P[j+1]*P[k+1], dp[i][j])

print(dp[0][-1])    


Measured memory_bytes: 5668
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A(sc);
	}
	
	public static void A(Scanner sc) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a*b)%2==1) out.println("Odd");
		else out.println("Even");
	}
}

Measured memory_bytes: 21716
s = input()
x, y = map(int, input().split())
X = 0
num = 0
while num <= len(s) - 1:
    if s[num] == "F":
        X += 1
        num += 1
    else:
        num += 1
        break
flag = False
move_x = []
move_y = []
temp = 0
while num <= len(s) - 1:
    if s[num] == "F":
        temp += 1
        num += 1
    else:
        if flag == False:
            move_y.append(temp)
            flag = True
        else:
            move_x.append(temp)
            flag = False
        num += 1
        temp = 0
else:
    if flag == False:
        move_y.append(temp)
    else:
        move_x.append(temp)
set_x = {X}
set_y = {0}
for i in move_x:
    temp = set()
    for j in set_x:
        temp.add(j + i)
        temp.add(j - i)
    set_x = temp
for i in move_y:
    temp = set()
    for j in set_y:
        temp.add(j + i)
        temp.add(j - i)
    set_y = temp
if x in set_x and y in set_y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9824
#include <stdio.h>
int main() {
  int N, i, j, tmp1, tmp2;
  scanf("%d", &N);
 
  char moji[N][100], num[N], ans[N], tmp[100];
 
  for(i = 0; i < N; ++i){
    scanf("%s", moji[i]);
    scanf("%d", &num[i]);
    ans[i] = i + 1;
  }
 
  for(i = 1; i < N; ++i){
    for(j = 1; j < N; ++j){
      if(strcmp(moji[j-1], moji[j]) > 0 || (strcmp(moji[j-1], moji[j]) == 0 && num[j-1] < num[j])){
        strcpy(tmp, moji[j-1]);
        strcpy(moji[j-1], moji[j]);
        strcpy(moji[j], tmp);
        tmp1 = ans[j-1];
        ans[j-1] = ans[j];
        ans[j] = tmp1;
        tmp2 = num[j-1];
        num[j-1] = num[j];
        num[j] = tmp2;
      }
    }
  }
 
  for(i = 0; i < N; ++i){
    printf("%d\n", ans[i]);
  }
 
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int hcf (int n1, int n2)
{
  if (n2 != 0)
    return hcf (n2, n1 % n2);
  else
    return n1;
}

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  int mx = 78498;		//no.of primes less than 1e6;
  int maxn = 1e6 + 1;		//maximum size of array elements
  int sieve[maxn] = { 0 };
  int prime[mx];		//to store the primes
  int j = 0;
  for (int i = 2; i < maxn; i++)
    {
      if (sieve[i] == 0)
	{
	  prime[j++] = i;
	  for (int u = 2 * i; u < maxn; u += i)
	    sieve[u] = i;
	}
    }
  int freq[maxn] = { 0 };	//to store the frequencies of elements
  int n;
  cin >> n;
  int x[n];			//to store the array of elements
  int en = 1;			//counter to check if the set is pairwise coprime
  for (int i = 0; i < n; i++)
    {
      cin >> x[i];
      freq[x[i]] += 1;
    }
    if (en == 1)
    for (int i = 0; i < mx; i++)
      {
	int temp = prime[i];
	int cnt = 0;
	for (int j = temp; j < maxn; j += temp)
	  {
	    if (freq[j] != 0)
	      cnt+=freq[j];
	  }
	 if (cnt > 1)
	  {
	    en = 0;
	    break;
	  }
      }
  if (en == 1)
    cout << "pairwise coprime";
  else
    {
      int gcd = hcf (x[0], x[1]);
      for (int i = 2; i < n; i++)
	  gcd = hcf (gcd, x[i]);
	  if (gcd == 1)
	cout << "setwise coprime";
      else
	cout << "not coprime";
    }


}

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

signed main(){
  
  int h, w, k;
  cin >> h >> w >> k;
  
  string s[6];
  
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<(1<<h);i++){
    for(int j=0;j<(1<<w);j++){
      string t[6];
      for(int k=0;k<6;k++) t[k] = s[k];
      for(int I=0;I<h;I++){
	for(int J=0;J<w;J++){
	  if( i & ( 1 << I ) ) t[I][J] = '.';
	  if( j & ( 1 << J ) ) t[I][J] = '.';
	}
      }
      int cnt = 0;
      for(int I=0;I<h;I++){
	for(int J=0;J<w;J++){
	  if( t[I][J] == '#' ) cnt++;
	}
      }
      if( cnt == k ) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() { 
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> AB;
    FOR(i, N) {
        vector<ll> tmp(2);
        cin >> tmp[0] >> tmp[1];
        //AをMまでの余裕としてとる
        tmp[0] = M - tmp[0];
        AB.push_back(tmp);

    }
    function<bool(vector<ll>,vector<ll>)> f
     = [](vector<ll> a, vector<ll> b) -> bool {
        // if(a[0]!=b[0]){
        return a[0] < b[0];
        //}else{
        //    return a[1] > b[1];
        //}
    };
    sort(AB.begin(), AB.end(), f);
    //FOR(i, N) { cout << AB[i][0]; }
    ll day = M-1;
    ll ii = 0;
    ll num = 0;
    vector<ll> mati;
    while(true) {
        if(day==-1)
            break;
        vector<ll> a{day, 0};
        auto itr1 = lower_bound(AB.begin(), AB.end(), a, f);
        auto itr2 = upper_bound(AB.begin(), AB.end(), a,f);
        //cout << distance(itr1, itr2);
        for(auto it = itr1; it != itr2;++it){
            //cout << (*it)[0]<<endl;
            auto itt = lower_bound(mati.begin(), mati.end(),(*it)[1]);
            mati.insert(itt, (*it)[1]);
        }
        //cout << endl;
        if(mati.size()>0){
            num += mati.back();
            
            mati.pop_back();
        }
        day--;
        //if(A[i]-day==)
    }
    cout << num << endl;
}


Measured memory_bytes: 7984
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
ll n;
ll a[310][310];
int main(){
  scan(n);
  rep(i,n){
    rep(j,n){
      scan(a[i][j]);
    }
  }
  bool c[310][310];
  rep(i,n){
    rep(j,n){
      c[i][j]=true;
    }
  }
  bool f=true;
  rep(i,n){
    rep(j,n){
      rep(k,n){
	if(i!=j&&j!=k&&k!=i){
	  if(a[i][j]+a[j][k]<a[k][i]){
	    f=false;
	  }
	  else if(a[i][j]+a[j][k]==a[k][i]){
	    c[k][i]=false;
	  }
	}
      }
    }
  }
  if(f){
    ll res=0;
    rep(i,n){
      rep(j,n){
	if(c[i][j]){
	  res+=a[i][j];
	}
      }
    }
    prin(res/2);
  }
  else prin(-1);
  

  return 0;
}


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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long a{0}, b{0}, c{0};
    unsigned long ans{1};
    for(unsigned long _ = 0, i; _ < N; ++_){
        cin >> i;
        auto k{0UL};
        k += (a == i) + (b == i) + (c == i);
        (ans *= k) %= 1000000007;
        if(a == i)++a;
        else if(b == i)++b;
        else if(c == i)++c;
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back

using namespace std;

const int INF = 1000000000;

int main() {
  while(1){
    int h;
    cin>>h;
    if(!h)break;
    vector<vector<int>> t(h,vector<int>(5));
    REP(i,h)REP(j,5)cin>>t[i][j];
    int pt=0;
    while(1){
      bool ch=false;
      REP(i,h){
        int len=1;
        REP(j,4){
          if(t[i][j]==t[i][j+1]){
            len++;
          }else{
            if(len >= 3 && t[i][j]!=0){
              pt+=len*(t[i][j]);
              REP(k,len){
                t[i][j-k]=0;
              }
              ch=true;
            }
            len=1;
          }
        }
        if(len >= 3 && t[i][4]!=0){
          pt+=len*(t[i][4]);
          REP(k,len){
            t[i][4-k]=0;
          }
          ch=true;
        }
      }
      if(!ch)break;
      REP(i,5){
        for(int j=h-1;j>=0;--j){
          for(int k=j+1;k<h;++k){
            if(t[k][i]==0){
              swap(t[k][i],t[k-1][i]);
            }
          }
        }
      }
    }
    cout<<pt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	print $ n * 800 - ( n `div` 15 ) * 200


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

using namespace std;


int main() {
	int d, g;
	int tab[10][2];
	cin >> d >> g;
	for (int i = 0; i != d; ++i) {
		int p, c;
		cin >> p >> c;
		tab[i][0] = p;
		tab[i][1] = c;
	}
	int m = 99999;
	for (int i = 0; i < 1 << d; ++i) {
		int gg = g;
		int s = 0;
		for (int j = 0; j != d; ++j) {
			if (i >> j & 1) {
				gg -= 100 * (j + 1) * tab[j][0] + tab[j][1];
				s += tab[j][0];
			}
		}
		if (gg > 0) {
			for (int j = d - 1; j >= 0; --j) {
				if (!(i >> j & 1)) {
					if (gg < 100 * (j + 1) * tab[j][0]) {
						s += gg / (100 * (j + 1)) + (gg % (100 * (j + 1)) != 0);
					}
					else {
						s = 99999;
					}
					break;
				}
			}
		}
		m = min(m, s);
	}
	cout << m << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n) cin>>a[i];
  rep(t,k){
    vi sum(n+1,0);
    rep(i,n){
      sum[max(ll(0),i-a[i])]++;
      sum[min(n,i+a[i]+1)]--;
      //outv(sum);
    }
    a.resize(n,0);
    a[0]=sum[0];
    REP(i,1,n) a[i]=a[i-1]+sum[i];
    if(a[0]==n) break;
  }
  outv(a);
}

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


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

//Write From this Line

const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >>  n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll sum = 0;
	rep(i,n){
		sum += a[i];
		sum %= mod;
	}
	ll ans = 0;
	rep(i,n){
		sum -= a[i];
		if(sum <= 0){
			sum += mod;
		}
		sum %= mod;
		ans += (a[i] * sum) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "mydebug.h"
#else
#define debug(...)
#endif
typedef long long ll;typedef unsigned long long ul; typedef vector<ll> vl;

int main() {
  ios_base::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;

  double prob = (1.0/(1<<M));

  double value=0;
  double remaining=1.0;
  for(ll i=0;i<10'000'000 ;++i) {
    if(i<10)debug(value, remaining, prob, i);
    value+=prob*remaining*(1900*M+(100*(N-M)))*(i+1);
    remaining*=(1-prob);
    if(remaining < 1e-20) { debug(i); break;}
  }

  cout << (ll)value + (((value-(ll)value)>0.5)?1:0) << endl;



}

Measured memory_bytes: 256
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int h = sc.nextInt(); int w = sc.nextInt();
		int[][] ar = new int[h+1][w+1];
		for (int i=0; i<h; i++) {
			int sum = 0;
			for (int j=0; j<w+1; j++) {
				if (j == w) ar[i][w] = sum;
				else {
					ar[i][j] = sc.nextInt();
					sum += ar[i][j];
				}
			}
		}
		
		for (int i=0; i<w+1; i++) {
			int sum = 0;
			for (int j=0; j<h+1; j++) {
				if (j == h) ar[h][i] = sum;
				else sum += ar[j][i];
			}
		}
		
		for (int i=0; i<h+1; i++) {
			for (int j=0; j<w+1; j++) {
				System.out.print((j==0?"":" ")+ar[i][j]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 40740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <vector <ll>> v(n, vector <ll> ());
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b;
    if (a == 0) {
      cin >> c;
      v.at(b).push_back(c);
    } else if (a == 1) {
      rep(j, v.at(b).size()) {
        if (j) {
          cout << ' ' << v.at(b).at(j);
        } else {
          cout << v.at(b).at(j);
        }
      }
      cout << endl;
    } else {
      v.at(b).clear();
    }
  }
}


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

int main(){
  int N, M;
  cin >> N >> M;
  int L, R;
  
  vector<int>	temp(N,0);
  cin >> L >> R;
  int l=L, r=R;  
  for(int i = 0; i < M-1; i++){
    cin >> L >> R;    
    if(l<L)	l = L;
    if(r>R) r = R;
  }
  
  int cnt = 0;  
  for(int i = l-1; i < r; i++)	cnt++;

  cout << cnt << endl;
}

Measured memory_bytes: 640
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let h: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    const INF: usize = 1_000_000_001;
    let mut dp: Vec<usize> = vec![INF; n];
    dp[0] = 0;
    for i in 0..n {
        for j in 1..(k + 1) {
            if i + j >= n {
                continue;
            }
            dp[i + j] = min(dp[i + j], dp[i] + (h[i + j] - h[i]).abs() as usize);
        }
    }
    return dp[n - 1].to_string();
}


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

using namespace std;

int main() {
  int A, B;
  
  cin >> A >> B;
  
  int _min = min(A, B), _max = max(A, B);
  
  if (_min == _max) {
    cout << _min + _max << endl;
  } else {
    cout << 2 * _max - 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = 100005;
const int LOGN = 20;
int n, k, a[102];
int win_dp[maxn]; // 1 means win, 0 means lose
int cal(int stone)
{
    if(stone<a[1])
        return 0;
    int &win = win_dp[stone];
    if(win!=-1) return win;
    win = 0;
    f1(i,n) if(a[i]<=stone)
        win|=!cal(stone-a[i]);
    return win;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>k;
    f1(i,n) cin>>a[i], win_dp[a[i]]=1;
    mem(win_dp,-1);
    int win = cal(k);
    if(win)
        cout << "First\n";
    else cout << "Second\n";
    return 0;
}


Measured memory_bytes: 5376
n=int(input())
a=list(map(int,input().split()))
d=1
kabu=0
ans=1000
while d<=n-1:
    if a[d]>a[d-1]:
        f=ans//a[d-1]
        kabu+=f
        ans=ans-a[d-1]*f
    if a[d]<a[d-1]:
        ans+=kabu*a[d-1]
        kabu=0
    d+=1
ans+=kabu*a[n-1]
print(ans)

Measured memory_bytes: 9196
import java.util.Scanner;

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

		int small = (a > c)? a : c;
		int large = (b < d)? b : d;

		int time = (large > small)? large-small : 0;
		System.out.println(time);
	}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	int c;
	int k;
	int n;
	int m;
	int p;
	int q;
	long long s;
	int x;
	int y;
	int z;
	c = 0;
	long long plus=0;
	long long minus=0;
	long long max;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (a[i] > 0)s = s + a[i];
	}
	for (int i = 0; i < k; i++){
		if (a[i] > 0)plus = plus + a[i];
		else minus = minus - a[i];
	}
	if (minus < plus)max = minus;
	else max = plus;
	for (int i = 0; i < n - k; i++){
		if (a[i] > 0)plus = plus - a[i];
		else minus = minus + a[i];
		if (a[i+k] > 0)plus = plus + a[i+k];
		else minus = minus - a[i+k];
	if (minus < max)max = minus;
	if(plus<max) max = plus;
	}

	printf("%lld\n", s-max);

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int a[8];
int main(void)
{
	int n,k,min,max,i;
	int t=0,cnt=0;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&k);
		if(k>=3200) t++;
		else a[k/400]++;
	}
	FOR(i,0,8){
		if(a[i]) cnt++;
	}
	if(cnt) min=cnt,max=cnt+t;
	else min=1,max=t;
	printf("%d %d\n",min,max);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	multiset<int> p;
	while (n--)
	{
		int oper;
		cin >> oper;
		switch (oper)
		{
			int num;
		case 0:
			cin >> num;
			p.insert(num);
			cout << p.size() << endl;
			break;
		case 1:
			cin >> num;
			cout << p.count(num) << endl;
			break;
		case 2:
			cin >> num;
			p.erase(num);
			break;
		case 3:
			int head, end;
			cin >> head >> end;
			set<int>::iterator p1 = p.lower_bound(head);
			set<int>::iterator p2 = p.upper_bound(end);
			for (;p1 != p2;p1++)
			{
				cout << *p1 << endl;
			}

			
		}
	}
}


Measured memory_bytes: 12252
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n';

typedef long long ll;

using namespace std;

int main()
{

    int N, X;
    cin >> N >> X;

    int cnt = 1;
    int sum = 0;
    REP(i, N)
    {
        int tmp;
        cin >> tmp;

        sum += tmp;
        if (sum <= X)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char s1[4], s2[4];
  
  scanf("%s %s", s1, s2);
  
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]){
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
/*
 * src.cpp
 *
 *  Created on: 2016/09/03
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef long long ll;

const int MAX_N=50,MAX_X=50;

int N,A,x[MAX_N];

ll memo[MAX_N][MAX_N*MAX_X+8][MAX_N];

ll dfs(int i,int sum,int card){
	if (i==N){
		if (card!=0 && sum==A*card){
			return 1;
		}
		return 0;
	}
	if (memo[i][sum][card]!=-1){
		return memo[i][sum][card];
	}
	ll res=dfs(i+1,sum,card)+dfs(i+1,sum+x[i],card+1);
	return memo[i][sum][card]=res;
}

int main(){
	scanf("%d %d",&N,&A);
	REP(i,N){
		scanf("%d",&x[i]);
	}
	memset(memo,-1,sizeof(memo));
	printf("%lld\n",dfs(0,0,0));
	return 0;
}


Measured memory_bytes: 49280
#include <stdio.h>

int n, a[100001], cnt;

int main()
{
    scanf("%d", &n);

    for(int i=1; i<=n; i++) scanf("%d", a+i);

    for(int i=1; i<=n; i++) {
        if(i==a[a[i]]) cnt++;
    }

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

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

using namespace std;

int N, nr, a[200009], st[200009], L[200009], R[200009];
long long sum;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
for (int i=1; i<=N; i++)
{
    while (nr > 0 && a[st[nr]] >= a[i]) nr --;
    if (nr == 0) L[i] = 1;
    else L[i] = st[nr] + 1;
    st[++nr] = i;
}
nr = 0;
for (int i=N; i>=1; i--)
{
    while (nr > 0 && a[st[nr]] >= a[i]) nr --;
    if (nr == 0) R[i] = N;
    else R[i] = st[nr] - 1;
    st[++nr] = i;
}
for (int i=1; i<=N; i++)
    sum += 1LL * (i - L[i] + 1) * (R[i] - i + 1) * a[i];
printf ("%lld\n", sum);
return 0;
}


Measured memory_bytes: 3328
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char s[200001];

int main(void) {
	char a, b;

	scanf("%c %c", &a, &b);

	printf("%c\n", (a == 'H' && b == 'H') || (a == 'D' && b == 'D') ? 'H' : 'D');

	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt() % 10;

        switch (n) {
            case 3: {
                System.out.println("bon");
                return;
            }

            case 0:
            case 1:
            case 6:
            case 8: {
                System.out.println("pon");
                return;
            }

            default: {
                System.out.println("hon");
            }
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 32500
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = Counter(A)
q = int(input())
BC = [list(map(int, input().split())) for _ in range(q)]
ans = sum(A)
for b,c in BC:
    ans -= b*a[b] - c*a[b]
    if c in a:a[c] += a[b]
    else: a[c] = a[b]
    a[b] = 0
    print(ans)

Measured memory_bytes: 39468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.length();
	int ans=0;
	for(int i=0;i<len;i++){
		ans=(ans+s[i]-'0')%9;
	}
	if(ans==0) puts("Yes");
	else puts("No");
	return 0;
}

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


int main()
{
	int X;
	cin>>X;
	int ans=1;
	Rep(i,2,X)
	{
		for(int j=2;pow(i,j)<=X;j++)
		{
			ans=max(ans,(int)pow(i,j));
		}	
	}
	cout<<ans<<endl;
	return 0;
}


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

char s[102],t[102];
int vis[102],p=0;

bool cmp(char a,char b)
{
	return a<b;
}

int main()
{
	scanf("%s\n%s",s,t);
	sort(s,s+(strlen(s)),cmp);
	sort(t,t+(strlen(t)),cmp);
	int i,j,flag=0;
	if(strlen(s)<=strlen(t))
	{
		for(i=0;i<strlen(s);i++)
		{
			flag=0;
			for(j=0;j<strlen(t);j++)
			{
				if(s[i]==t[j]&&vis[j]==0)
				{
					vis[j]=1;
					flag=1;
					break;
				}
			}
			if(flag==0)
			{
				break;
			}
		}
		if(flag)
		{
			p=1;
		}
	}
	
	if(s[0]>=t[strlen(t)-1])
	{
		if(p)
		{
			if(strlen(s)<strlen(t))
			{
				printf("Yes");
				return 0;
			}
			else
			{
				printf("No");
			}
		}
		else
		{
			printf("No");
		}
	}
	else
	{
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 128
use std::io;


/// https://beta.atcoder.jp/contests/agc004/tasks/agc004_a
fn main() {
    let mut abc = read::<usize>();

    if (abc[0] * abc[1] * abc[2]) % 2 == 0 { println!("0"); }
    else {
        abc.sort();
        println!("{}", abc[0] * abc[1]);
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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

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

	int cnt = 0;
    while (true) {
        bool flg = false;
        for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				flg = true;
			}
			
        }

	if (flg == true) {
		break;
	}

        for (int i = 0; i < N; i++) {
			A[i] = A[i] / 2;
		}
        cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256