akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  x                     first                 
#define  y                     second                
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  1e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll t=1,d,dp[10008][108][2],dig[10008],sz;
string k;

ll rec(ll ind, ll s, ll f1){
    if(ind == sz){
        if(s == 0) return 1;
        return 0;
    }
    if(dp[ind][s][f1] != -1) return dp[ind][s][f1];
    dp[ind][s][f1] = 0;
    ll j = 9;
    if(f1 == 1) j = dig[ind];
    for(int i = 0; i <= j; i++){
        dp[ind][s][f1] += rec(ind+1,(s+i)%d,f1&(dig[ind]==i));
        dp[ind][s][f1] %= mod;
    }
    return dp[ind][s][f1];
}

ll solve(){
    memset(dp,-1,sizeof(dp));
    cin>>k>>d;
    sz = k.size();
    for(int i = 0; i < sz; i++) dig[i] = k[i] - '0';
    ll ans = rec(0,0,1)-1;
    if(ans < 0) ans += mod;
    cout<<ans<<endl;
}

int main(){
    fastio;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double dist = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    printf("%f\n",dist);
    return 0;
}


Measured memory_bytes: 3200
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
print(y * pow(y-1,x-1))

Measured memory_bytes: 13676
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

int main()
{
	while (1)
	{
		int n, m;
		std::cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		std::vector<int> vec(m, 0);
		for (int i = 0; i != n; ++i)
		{
			for (int j = 0; j != m; ++j)
			{
				int a;
				std::cin >> a;
				vec[j] += a;
			}
		}
		std::vector<int> vec2 = vec;
		std::sort(vec.begin(), vec.end(), std::greater<int>());
		std::vector<bool> check(m, true);
		for (int i = 0; i != m; ++i)
		{
			for (int j = 0; j != m; ++j)
			{
				if (check[j] && vec[i] == vec2[j])
				{
					std::cout << j + 1;
					check[j] = false;
					break;
				}
			}
			if (i != m - 1)
				std::cout << " ";
			else
				std::cout << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

long power(int n) {
    if (n == 0) return 1;
    return 2 * power(n - 1) % MOD;
}

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

    int row[n];
    fill(row, row + n, 0);

    for (int i = 0; i < n; i++) {
        int diff;
        cin >> diff;

        if (n % 2 == 0 && diff % 2 == 0) {
            cout << 0 << endl;
            return 0;
        } else if (n % 2 != 0 && diff % 2 != 0) {
            cout << 0 << endl;
            return 0;
        } else {
            ++row[diff];
            if (row[diff] > 2) {
                cout << 0 << endl;
                return 0;
            } else if (n % 2 != 0 && row[0] > 1) {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    int sisu = n / 2;
    cout << power(sisu) << endl;
}


Measured memory_bytes: 1408
#include <iostream>

#include <cstdio>

using namespace std;

int main()
{
    char c;    
    cin >> c;

    char a = 'a';

    if(c >= a)
    {
        cout << "a" << endl;
    }
    else
    {
        cout << "A" << endl;
    }

    return 0;    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  string s;
  int n;
  cin >> s >> n;
  for(int i=0; i<s.size(); i+=n){
    string tmp = s.substr(i,n);
    cout << tmp.front();
  }
  cout << endl;
  return 0;
}


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

int main()
{
int a, b;
cin >> a >> b;
 float average = (a + b) / 2.0 ;
int aveint = (a + b) / 2;
if( average >  aveint) {
cout << aveint + 1 << endl;
}
else{
cout << aveint << endl;
}

}


Measured memory_bytes: 256
//AtCoder ABC093 B - Small and Large Integers
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll A,B,K;
    cin>>A>>B>>K;
    unordered_set<ll> tbl;
    for(ll i=A;i<A+K&&i<=B;++i){
        tbl.insert(i);
    }
    for(ll i=B;i>B-K&&i>=A;--i){
        tbl.insert(i);
    }
    vector<ll> ans(tbl.size());
    std::copy(tbl.begin(), tbl.end(), ans.begin());
    sort(ans.begin(),ans.end());
    for(const auto& a:ans){
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
a,b,k = map(int, input().split())
if k > a and k >= a+b:
  print( 0 , 0 )
elif k < a :
  print(a-k , b)
elif k == a:
  print(0 , b)
elif k>a and k < a+b:
  print(0 , b-(k-a))

Measured memory_bytes: 8980
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL A, B;
	cin >> A >> B;

	if (A > 8 || B > 8) {
		O(":(");
	}
	else {
		O("Yay!");
	}

	return 0;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    string s;
    cin >> s;
    ll n = s.size();

    vector<ll> imos(n+1);
    for(ll i=1; i<=n; i++)
        imos[i] = imos[i-1] + (s[i-1]-'0');

    ll ok = 1, ng = n+1;
    while(abs(ng - ok) > 1 ) {
        ll k = (ok+ng)/2;

        ll l = n-k, r = k;
        bool pass = false;
        pass |= l >= r;
        pass |= imos[r] - imos[l] == 0;
        pass |= imos[r] - imos[l] == r - l;
        (pass ? ok : ng) = k;
    }
    cout << ok << endl;
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);++i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) if (scanf("%d", &v)<1);
#define in_s(v) if (scanf("%s", v)<1);
const int MOD = 1e9+7;

int main() {
  int N; in(N);
  char S1[N], S2[N];
  in_s(S1);
  in_s(S2);

  vi v;
  rep(i, N) {
    if (S1[i] == S1[i+1]) {
      v.push_back(2);
      ++i;
    } else v.push_back(1);
  }
  ll ans = 3;
  int before = 0;
  iter(it, v) {
    if (*it == 1) {
      if (*it != before) ans *= 1;
      else ans *= 2;
    } else {
      if (*it != before) ans *= 2;
      else ans *= 3;
    }
    before = *it;
    ans %= MOD;
  }
  printf("%lld\n", ans);


  return 0;
}


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

int main()
{
    string s,t;
    cin>>s>>t;

    int a,b;
    cin>>a>>b;

    string choice;
    cin>>choice;

    if (choice ==s)
        cout<<a-1<<" "<<b;
    else
        cout<<a<<" "<<b-1;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
ans=[]
while n:
    n-=1
    tmp=n%26
    ans.append(al[tmp])
    n//=26
ans.reverse()
print("".join(ans))

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

void printBit(int x, int w){
    if (!w) return;
    printBit(x/2, w-1);
    cout << x%2;
}

main(){
    int B[11] = {63, 6, 91, 79, 102, 109, 125, 39, 127, 111, 0};
    int n, p;
    while( cin >> n && n != -1 ){
	for ( int i = 0, cur = 10; i < n; i++ ){
	    cin >> p;
	    printBit(B[cur]^B[p], 7);
	    cout << endl;
	    cur = p;
	}
    }
}

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

int main() {

  int N;
  cin >> N;

  int S = 0;
  int Aodd = 0;
  
  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
    if (i % 2 == 1) {
      Aodd += A[i];
    }
  }

  vector<int> X(N+1);

  X[0] = S - 2 * Aodd;
  
  cout << X[0] << " ";

  for (int i = 1; i < N; i++) {
    X[i] = 2 * A[i-1] - X[i-1];
    cout << X[i];
    if (i == N-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b;
  cin >> a >> b;
  set<int> k={1,2,3};
  k.erase(a);
  k.erase(b);
  for(auto value: k){
    cout << value << endl;
  }
}

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() {
  int n;
  cin >> n;
  vector<vector<int>> testimony(n, vector<int>(n, -1));
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      testimony[i][x - 1] = y;
    }
  }

  int ans = 0;
  rep(bit, 1 << n) {
    vector<int> honest(n);
    rep(i, n) {
      if (bit & 1 << i) honest[i] = 1;
    }

    bool ok = true;
    rep(i, n) {
      if (honest[i]) {
        rep(j, n) {
          if (testimony[i][j] == -1) continue;
          if (testimony[i][j] != honest[j]) ok = false;
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(bit));
  }

  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> P;
const int mod = 1000000007;

int calc(int n){
    int res = 0;
    int m = 0, tmp = 1;
    while(n > 0){
        int x = n % 10;
        n /= 10;
        m = tmp * x + m;
        tmp *= 10;
        res = max(res, n * m);
    }
    return res;
}


signed main(){

    int q;
    cin >> q;
    while(q--){
        int n;
        cin >> n;
        int cnt = 0;
        while(n >= 10){
            n = calc(n);
            //cout << n << endl;
            cnt++;
        }
        cout << cnt << endl;
    }
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL A, B; cin >> A >> B;
	
	LL ans = 0;
	if (B%A == 0)ans = A + B;
	else ans = B - A;

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;
int a[8];
int main()
{
    memset(a,-1,sizeof(a));
    int n,m;cin>>n>>m;
    int x,y;
    while(m--)
    {
        cin>>x>>y;
        if(a[x]!=-1&&a[x]!=y) return cout<<"-1",0;
        a[x]=y;
    }
    if(n!=1&&a[1]==0) return cout<<"-1",0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=-1) cout<<a[i];
        else if(n==1||i!=1) cout<<0;
        else cout<<1;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

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

int main(){
  int W, H;
  cin >> H >> W;

  vector<vector<char>> f(H, vector<char>(W));
  REP(i, 0, H){
    REP(j, 0, W){
      cin >> f[i][j];
    }
  }

  PII a = {0, 0};
  while(1){

    PII u = {a.fst - 1, a.snd};
    PII b = {a.fst, a.snd-1};

    if((u.fst >= 0 && f[u.fst][u.snd] == '#') ||
       (b.snd >= 0 && f[b.fst][b.snd] == '#')){
      cout << "Impossible" << endl;
      break;
    }

    if(a.fst == H - 1 && a.snd == W - 1){
      cout << "Possible" << endl;
      break;
    }
    
    PII x = {a.fst, a.snd+1};
    PII y = {a.fst + 1, a.snd};
    
    char cx = '.', cy = '.';
    if(x.snd < W){
      cx = f[x.fst][x.snd];
    }
    if(y.fst < H){
      cy = f[y.fst][y.snd];
    }
    if(cx == '.' && cy == '.'){
      cout << "Impossible" << endl;
      break;
    }
    if(cx == '#' &&  cy == '#'){
      cout << "Impossible" << endl;
      break;
    }
    f[a.fst][a.snd] = '.';
    if(cx == '#'){
      a = x;
    } else {
      a = y;
    }
  }
  return 0;
}


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

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  int down = 0, up = 0;
  for(int i = 0 ; i < m; i++){
    int a;
    cin >> a;
    if(x < a) up++;
    else down++;
  }
  cout << min(up, down) << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // Atcoder
    // template: cpp
    ll n;
    cin >> n;
    vector<ll> a(3 * n);
    rep(i, 3 * n) cin >> a[i];
    ll sum = 0;
    sort(all(a));
    reverse(all(a));

    for(size_t i = 1; i < 2 * n; i += 2) {
        sum += a.at(i);
    }
    cout << sum;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define PF push_front
#define P push
#define INC(i,a,b) for (ll i = a; i <= b; i++)
#define DEC(i,b,a) for (ll i = b; i >= a ; i--)
#define inf LLONG_MAX
#define neginf LLONG_MIN
#define mod  1000000007
#define eps 1e-9
typedef ostringstream OS ;
typedef stringstream SS ;
typedef long long ll ;
typedef unsigned long long ull;
typedef pair < ll , ll > PLL ;
typedef pair < char,ll > PCL ;
typedef deque < double > DD ;
typedef deque < PCL > DCL ;
typedef deque < ll > DL ;
typedef deque < PLL > DLL ;
typedef deque < char > DC ;
typedef deque < string > DS ;
typedef vector < double > VD;
typedef vector < PCL > VCL ;
typedef vector < ll > VL;
typedef vector < PLL > VLL ;
typedef vector < char > VC ;
typedef vector < string > VS ;
typedef map < ll ,ll > MLL ;
typedef map < char,ll > MCL;
typedef map < ll,char > MLC;
typedef map < string,ll> MSL;
typedef priority_queue < PLL > PQLL ;
typedef priority_queue < ll > PQL ;
typedef stack < ll > SKL ;
typedef stack < PLL > SKLL ;
typedef queue < ll > QL ;
typedef queue < PLL > QLL ;
typedef set < ll > SL ;
typedef set < PLL > SLL ;
typedef set < char > SC ;
 
string numtostr(ll n) {
     OS str1 ;
     str1 << n ;
     return str1.str();
}
ll strtonum(string s) {
     ll x ;
     SS str1(s);
     str1 >> x ;
     return x ;
}
ll GCD(ll a, ll b) {
    if ( b == 0 ) return a ;
    else return GCD(b,a%b);
}
ll LCM(ll a , ll b) {
    ll gcd = GCD(a,b);
     return (a/gcd)*b ;
}
ll cost[102];
ll weight[100005];
ll dp[102][100005];
ll knapsack(ll itemnumber,ll capacity) {
    INC(i,1,itemnumber) cin >> weight[i] >> cost[i];
    memset(dp,-1,sizeof(dp));
    INC(i,0,itemnumber) 
        INC(j,0,capacity)
            if ( i == 0 || j == 0) dp[i][j] = 0 ;
    

    INC(i,1,itemnumber) {
        INC(j,1,capacity) {
            if ( weight[i] <= j) 
                dp[i][j] = max(cost[i]+dp[i-1][j-weight[i]],dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
    }     
    return dp[itemnumber][capacity];
} 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll itemnumber,capacity ;
    cin >> itemnumber >> capacity ;
    cout << knapsack(itemnumber,capacity) << endl;
 
    return 0 ;
}

Measured memory_bytes: 83316
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int n;
long long DP[25][2500000];
int arr[25][25],bt;

long long dp(int pos, int mask){
//printf("%d %d\n", pos, mask);
	if(pos>=n-1){
		if(mask==bt) return 1;
		else return 0;
	}
	if(DP[pos][mask]!=-1) return DP[pos][mask];
	long long ret = 0;
	for(int i = 0;i<n;i++){
		if(arr[pos+1][i]==1 && !(mask&(1<<i))){
			ret+= dp(pos+1,mask|(1<<i));
			ret%=MOD;
		} 
	}
	return DP[pos][mask] = ret;
}

int main(){
	memset(DP,-1,sizeof DP);
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		for (int j = 0; j<n;j++){
			scanf("%d",&arr[i][j]);
		}
	}
	bt = (1<<n)-1;
	long long ans =0;
	for(int i = 0;i<n;i++){
		if(arr[0][i]==1 ){
			ans+= dp(0,(1<<i));
			ans%=MOD;
		} 
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 488576
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string A, B;
  cin >> A >> B;
  if(A.size() < B.size()){
    cout << "LESS";
  }else if(A.size() > B.size()){
    cout << "GREATER";
  }else{
    for(int i = 0; i < A.size(); i++){
      if(A.at(i) < B.at(i)){
        cout << "LESS";
        break;
      }else if(A.at(i) > B.at(i)){
        cout << "GREATER";
        break;
      }else{
        if(i+1 == A.size()){
          cout << "EQUAL";
        }
      }
    }
  }
  return 0;
}
        

Measured memory_bytes: 256
#include<stdio.h>
/*abc
abc
*/
int main()
{
  int n;
  int val[100];
  int cost[100];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&val[i]);
  }
  for(int i=0;i<n;i++){
    scanf("%d",&cost[i]);
  }
  
  int sum=0;
  for(int i=0;i<n;i++){
    if(val[i]>cost[i]){
      sum+=val[i]-cost[i];
    }
  }
  printf("%d\n",sum);
  return(0);
}

Measured memory_bytes: 128
[n,t]=[int(i) for i in input().split()]

c=[]
tli=[]
for i in range(n):
    [tempc, tempt]=[int(i) for i in input().split()]
    c.append(tempc)
    tli.append(tempt)

min=1001
f=0
for i in range(n):
    if tli[i] <= t:
        f=1
        if c[i] < min:
            min=c[i]

if f:
    print(min)
else:
    print("TLE")


Measured memory_bytes: 3064
n, m = map(int, input().split())
coin = sorted(list(map(int, input().split())))
T = [0]+[float('inf')]*n
for i in range(m):
    for j in range(coin[i], n+1):
        T[j] = min(T[j], T[j-coin[i]]+1)
print(T[-1])

Measured memory_bytes: 9468
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001

int gcd(int a, int b) {
  if (a < b) return gcd(b, a);
  int r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int k;
  cin >> k;
  ll ret = 0;
  for(int a = 1; a <= k; a++) {
    for(int b = 1; b <= k; b++) {
      for(int c = 1; c <= k; c++) {
        //cout << a << b << c ;
        int j = gcd(b,c);
        ret += gcd(a, j);
        //cout << ret << endl;
      }
    } 
  }
  cout << ret << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (auto &r: a) for (auto &e: r) cin >> e;
    for (auto &r: a) for (auto &e: r) {
        int b;
        cin >> b;
        e = abs(e-b);
    }

    const int bias = 80*80;
    const int sz = bias*2+1;
    vector<bitset<sz>> fw(w), rev(w);
    fw[0][a[0][0]+bias] = fw[0][-a[0][0]+bias] = true;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w-i; j++) {
            if (i != 0) {
                fw[j] <<= a[i][j];
                fw[j] |= fw[j] >> (2*a[i][j]);
            }
            if (j != 0) {
                fw[j] |= fw[j-1] << a[i][j];
                fw[j] |= fw[j-1] >> a[i][j];
            }
        }
    }

    rev[w-1][bias] = true;
    for (int i = h-1; i >= 0; i--) {
        for (int j = w-1; j >= max(0, w-i-1); j--) {
            if (i != h-1) {
                rev[j] <<= a[i+1][j];
                rev[j] |= rev[j] >> (2*a[i+1][j]);
            }
            if (j != w-1) {
                rev[j] |= rev[j+1] << a[i][j+1];
                rev[j] |= rev[j+1] >> a[i][j+1];
            }
        }
    }

    int ans = sz;
    for (int i = max(w-h, 0); i < w; ++i) {
        int pa = -sz, pb = -sz;
        for (int j = 0; j < sz; ++j) {
            if (fw[i][j]) {
                ans = min(ans, j - pb);
                pa = j;
            }
            if (rev[i][j]) {
                ans = min(ans, j - pa);
                pb = j;
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const int N=3005,P=1e9+7,inv2=(P+1)/2;
int n,m,f[N][N],a[N],ans,pw[N],ipw[N];

inline void read(int &i){
	i=0;char c=getchar();bool j=0;
	for(;!isdigit(c);c=getchar())if(c=='-')j=1;
	for(;isdigit(c);c=getchar())i=(i<<1)+(i<<3)+c-'0';i=j?-i:i;
}

int main(){
	read(n);read(m);
	for(int i=1;i<=n;++i)read(a[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			f[i][j]=a[i]<a[j];
	pw[0]=1;for(int i=1;i<=m;++i)pw[i]=pw[i-1]*2%P;
	ipw[0]=1;for(int i=1;i<=m;++i)ipw[i]=(ll)ipw[i-1]*inv2%P;
	for(int t=0;t<m;++t){
		int x,y;read(x);read(y);
		f[x][y]=(ll)f[x][y]*pw[t]%P;
		f[y][x]=(ll)f[y][x]*pw[t]%P;
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])%P;
		f[x][y]=f[y][x]=(ll)f[x][y]*ipw[t+1]%P;
		for(int i=1;i<=n;++i)if(i!=x&&i!=y){
			f[i][x]=(ll)f[i][x]*pw[t]%P;
			f[i][y]=(ll)f[i][y]*pw[t]%P;
			f[i][x]=f[i][y]=(f[i][x]+f[i][y])%P;
			f[i][x]=f[i][y]=(ll)f[i][x]*ipw[t+1]%P;
			f[x][i]=(ll)f[x][i]*pw[t]%P;
			f[y][i]=(ll)f[y][i]*pw[t]%P;
			f[x][i]=f[y][i]=(f[x][i]+f[y][i])%P;
			f[x][i]=f[y][i]=(ll)f[x][i]*ipw[t+1]%P;
		}
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<i;++j)
			ans=(ans+(ll)f[i][j]*pw[m])%P;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35456
#include <iostream> 
using namespace std;
int main(){
    int n;
    int cnt5=0,cnt7=0;
    for (int i=0; i<3; i++){
        cin >> n;
        if (n==5) cnt5++;
        else if(n==7) cnt7++;
    }
    cout << (cnt5==2 && cnt7==1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N, Y, a, b, c, d;
	cin>>N>>Y;				
	for(a=0;a<=N;++a){
		for(b=0;b<=N;++b){
			if(N-a-b >= 0){
				d = 10000*a + 5000*b + (N-a-b)*1000;
				if(d==Y){
					cout<<a<<' '<<b<<' '<<N-a-b<<endl;
					return 0;
				}
			}
		}
	}
	cout<<-1<<' '<<-1<<' '<<-1<<endl;
	return 0;
}
		

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int l=a+b,r=c+d;
	if(l>r)cout<<"Left"<<endl;
	if(l==r)cout<<"Balanced"<<endl;
	if(l<r)cout<<"Right"<<endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def bw(i, p):
    if dp[i] != [0, 0]:
        return dp[i]
    b = w = 1
    for ii in h[i]:
        if ii == p: continue
        bwi = bw(ii,i)
        w *= (bwi[0] + bwi[1])
        b *= bwi[1]
        w %= md
        b %= md
    dp[i] = [b, w]
    return [b, w]


md = 10 ** 9 + 7
n = int(input())
if n == 1:
    print(2)
    exit()
h = {}
for _ in range(n - 1):
    a, b = map(int, input().split())
    h.setdefault(a, [])
    h.setdefault(b, [])
    h[a] += [b]
    h[b] += [a]
dp = [[0, 0] for _ in range(n + 1)]
b, w = bw(1, 1)
print((b + w) % md)


Measured memory_bytes: 115528
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int a, b, c;
  scanf("%d/%d/%d", &a, &b, &c);
  if (b == 4) {
    puts(c <= 30 ? "Heisei" : "TBD");
  } else if (b < 4) {
    puts("Heisei");
  } else {
    puts("TBD");
  }
  return 0;
}


Measured memory_bytes: 256
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

num_list = list(map(int, input().split()))

product(num_list)

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

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

    int p[N];
    for(int i = 0; i < N; i++)
        cin >> p[i];

    sort(p, p+N);

    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += p[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

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

        if (X >= 30) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }
}

Measured memory_bytes: 35748
<?php
$input = trim(fgets(STDIN));
$a = explode(' ',$input);
$x = $a[0];
$y = $a[1];
$z = $a[2];
	
for ($i = 0; $i < 3 ;$i++){
	if ($x > $y ){
		$temp = $x;
		$x = $y;
		$y = $temp;
	}
	if ($y > $z ){
		$temp = $y ;
		$y = $z;
		$z = $temp;	
	}
	
}
echo $x." ".$y." ".$z;
 

?>

Measured memory_bytes: 15264
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
 
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, pii>> vpiii;
 
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;
typedef map<int, vpii> mivpii;

const int MAXN = 1e5;
const int UNSET = -1;
const int MAXK = 3;

int d[MAXN + 1];
ll dp[MAXN + 1][MAXK + 1][2];

string S;
int N, K;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

ll solve(int pos, int k, bool r) {
	if(pos == N) return k == K;
	if(dp[pos][k][r] != UNSET) return dp[pos][k][r];
	
	int lim = (r ? d[pos] : 9);
	ll ans = 0;
	
	for(int i = 0; i <= lim; i++) {
		bool nr = (i == d[pos]) ? r : 0;
		int nk = (i) ? k + 1 : k;
		if(nk <= K) ans += solve(pos + 1, nk, nr);
	}
	return dp[pos][k][r] = ans;
}

void prepare() {
	memset(dp, UNSET, sizeof(dp));
	for(int i = 0; i < S.length(); i++)
		d[i] = S[i] - '0';
	N = S.length();
}

int main() {
	fast_io();
//	freopen("input/ABC154E.txt", "r", stdin);
	
	cin >> S >> K;
	prepare();
	cout << solve(0, 0, 1) << '\n';
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

int main() {
    int x,y;
    cin >> x >> y;

    vector<int> g1 = {1,3,5,7,8,10,12};
    vector<int> g2 = {4,6,9,11};
    vector<int> g3 = {2};

    int xg, yg;
    rep(i,g1.size()){
        if(x == g1[i]) xg = 1;
        if(y == g1[i]) yg = 1;
    }
    rep(i,g2.size()){
        if(x == g2[i]) xg = 2;
        if(y == g2[i]) yg = 2;
    }
    rep(i,g3.size()){
        if(x == g3[i]) xg = 3;
        if(y == g3[i]) yg = 3;
    }

    if(xg == yg) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];

    ll ans = LINF;
    rep(i, 1<<(n-1)) {
        int color = 1;
        ll cost = 0;
        vint tmp = a;
        int mx = a[0];
        rep(j, n-1) {
            if (!(i & (1<<j))) {
                if (mx < tmp[j+1]) color++;
                mx = max(mx, tmp[j+1]);
                continue;
            }
            int d = mx+1 - tmp[j+1];
            if (d > 0) {
                cost += d;
                tmp[j+1] += d;
            }
            color++;
            mx = max(mx, tmp[j+1]);
        }
        if (color >= k) ans = min(ans, cost);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	public static void main(String[] args) {
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int b=1,ans=0;
		for(int i=0;i<N;i++){
			A[i]=stdIn.nextInt();
			if(A[i]==b)
				b++;
			else
				ans++;
		}
		if(b==1)
			System.out.println(-1);
		else
			System.out.println(ans);
	}
}


Measured memory_bytes: 22596
#include <stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
  if(H==0&&W==0){
    break;
  }
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      printf("#");
    }
    printf("\n");
  }
  printf("\n");
  }
  return 0;
}
    

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

int main() {
	int h, w;
	std::cin >> h >> w;

	std::vector<std::vector<int>>c(10, std::vector<int>(10));
	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			std::cin >> c.at(i).at(j);

	std::vector<std::vector<int>>a(h, std::vector<int>(w));
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			std::cin >> a.at(i).at(j);

	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			for (int k = 0; k < 10; ++k)
				c.at(j).at(k) = std::min(c.at(j).at(k), c.at(j).at(i) + c.at(i).at(k));

	long long ans = 0;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			if (a.at(i).at(j) != -1)
				ans += c.at(a.at(i).at(j)).at(1);

	std::cout << ans;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

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

    long M = 1_000_000_007;
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();
    long res = 0;
    BinaryIndexTree bit = new BinaryIndexTree(2000);
    for (int i = 0; i < N; i++) {
      res += i - bit.query(A[i]);
      bit.add(A[i], 1);
    }
    res *= K;
    res %= M;
    Arrays.sort(A);
    long count2 = 0;
    for (int i = 0; i < N; i++) {
      count2 += N - lowerBound(A, A[i]);
    }
    count2 *= K - 1;
    count2 %= M;
    count2 *= K;
    count2 %= M;
    count2 *= inverse(2, M);
    count2 %= M;

    res += count2;
    res %= M;
    System.out.println(res);
  }

  private static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }

  public static int lowerBound(int[] a, int k) {
    int left = -1;
    int right = a.length;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (k < a[mid]) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return right;
  }

  public static class BinaryIndexTree {
    private final int[] a;

    public BinaryIndexTree(int size) {
      a = new int[size + 1];
    }

    public int query(int index) {
      int res = 0;
      while (index > 0) {
        res += a[index];
        index -= Integer.lowestOneBit(index);
      }
      return res;
    }

    public void add(int index, int value) {
      while (index < a.length) {
        a[index] += value;
        index += Integer.lowestOneBit(index);
      }
    }
  }
}


Measured memory_bytes: 26072
import math

N,M=map(int, input().split())
H=list(map(int, input().split()))
G=[1]*N
j=0
for i in range(M):
  a,b=map(int, input().split())
  if H[a-1]>H[b-1]:
    G[b-1]=0
  elif H[a-1]<H[b-1]:
    G[a-1]=0
  else:
    G[a-1]=0
    G[b-1]=0
print(G.count(1))

Measured memory_bytes: 20128
n = int(input())
for i in range(n):
    b = list()
    c = list()
    a =  list(map(int, input().split()))
    # print(a)
    b.append(a.pop(0))

    for _  in range(9):
        a0 = a.pop(0)
        if b[-1] < a0:
            b.append(a0)
        elif len(c)==0 or c[-1]<a0:
            c.append(a0)
        else:
            a.append(a0)
            print('NO')
            break
    if len(a)==0:
        print('YES')



Measured memory_bytes: 5588
import java.util.*;

class Main{
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
     int n = sc.nextInt();
     String s = sc.next();
     int cnt = 0;
      if(n%2 == 1){
      	System.out.println("No");
        return;
      }
     for(int i=0;i<n/2;i++){
     	if(s.charAt(i) == s.charAt(n/2 + i) ){
        	cnt++;
        }
     } 
      if(cnt == n/2){
      System.out.println("Yes");
      } else {
      System.out.println("No");
      }
	}
}

Measured memory_bytes: 35844
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll mat[500][500],digits[500][500];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    for(int i=0; i<10; i++)
    {
        for(int j=0; j<10; j++)
            cin>>digits[i][j];
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            cin>>mat[i][j];
    int t=50;
    while(t--)
    {
        for(int k=0; k<10; k++)
        {
            for(int i=0; i<10; i++)
            {
                for(int j=0; j<10; j++)
                {
                    digits[i][j]=min(digits[i][j],digits[i][k]+digits[k][j]);
                }
            }
        }
    }
    ll sum=0;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            if(mat[i][j]!=1 && mat[i][j]!=-1)
            {
                int cur=mat[i][j];
                sum+=digits[cur][1];
            }
        }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4484
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------

let main() =
    let [| a; b; c; x; y |] = reada int64
    let cand1 = a * x + b * y
    let cand2 = 2L * c * (max x y)

    let cand3 =
        let nin, nax = min x y, max x y
        let diff = nax - nin

        let m =
            if nax = x then a * diff else b * diff
        2L * nin * c + m

    List.min [ cand1; cand2; cand3 ] |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 11476
//#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = 1; i <= ty - sy; i++)
        cout << "U";
    for (int i = 1; i <= tx - sx; i++)
        cout << "R";
    for (int i = 1; i <= ty - sy; i++)
        cout << "D";
    for (int i = 1; i <= tx - sx; i++)
        cout << "L";
    cout << "L";
    for (int i = 1; i <= ty - sy + 1; i++)
        cout << "U";
    for (int i = 1; i <= tx - sx + 1; i++)
        cout << "R";
    cout << "D";
    cout << "R";
    for (int i = 1; i <= ty - sy + 1; i++)
        cout << "D";
    for (int i = 1; i <= tx - sx + 1; i++)
        cout << "L";
    cout << "U";
    return 0;
}


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

const int MAX = 100001;

int main(){
  bitset<1000000> is_prime(0); 
  for (int i = 2; i < MAX; ++i)is_prime.set(i);
  
  for(int i = 2; i < MAX; ++i){
    if(is_prime[i]){
      for(int j = 2 * i; j < MAX; j += i){ 
        is_prime.reset(j); 
      }
    }
  }

  vector<int> a(MAX, 0);
  vector<int> sum(MAX + 1, 0);
  for(int i = 0; i < MAX; ++i){
    if(is_prime[i] && is_prime[(i + 1) / 2])a[i] = 1;
    sum[i + 1] = sum[i] + a[i];
  }

  int q;
  cin >> q;
  for(int i = 0; i < q; ++i){
    int l, r;
    cin >> l >> r;
    cout << sum[r + 1] - sum[l] << endl; 
  }
}


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

int main(void) {
    int N, K;
    cin >> N >> K;
    vector< int > p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    int t_i = 0, t = 0, t_max;
    for (int i = 0; i < K; i++) {
        t += p[i];
    }
    t_max = t;
    for (int i = 1; i < N - K + 1; i++) {
        t -= p[i - 1];
        t += p[i + K - 1];
        if (t > t_max) {
            t_i = i;
            t_max = t;
        }
    }
    double ans = 0.0;
    for (int i = t_i; i < t_i + K; i++) {
        ans += (p[i] + 1.0);
    }
    ans /= 2.0;
    printf("%lf\n", ans);
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll A,B,C,K; cin >> A >> B >> C >> K;
    ll ans = 0;
    ans += min(A, K);
    if(K-A > 0){
        K -= A;
        if(K-B > 0){
            K -= B;
            if(K > 0) ans -= K;
        }
    }
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 3620