akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
const int MAXN = 110;
int graph[MAXN][MAXN];
int h, w;
int cnt = 0;

void solve(int color, int time) {
    if (time == 0) return;
    int x = cnt / w;
    int y = cnt % w;
    if (x % 2 == 1) y = w - y - 1;
    graph[x][y] = color;
    cnt++;
    solve(color, time-1);

}

int main() {
//    freopen("test.txt", "r", stdin);
    scanf("%d%d", &h, &w);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int a;
        scanf("%d", &a);
        solve(i, a);
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            printf("%d", graph[i][j]);
            if(j != w-1) printf(" ");
            else printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  double h;
  vector<double> v;
  while(cin >> h) {
    v.push_back(h);
  }
  cout << *max_element(ALL(v)) - *min_element(ALL(v)) << endl;
}

Measured memory_bytes: 0
N, M = map(int,input().split(" "))
KA = [list(map(int, input().split(" "))) for i in range(N)]

i = 0
inter_set = set(KA[0][1:])
for line in KA:
  tmp_lst = []
  for j in range(1,line[0]+1):
    tmp_lst.append(KA[i][j])
  inter_set = inter_set & set(tmp_lst)
  i+=1
print(len(inter_set))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n,int w){
	int mxl=0,mxh=0,in;
	double ans=0;
	vi v(102);
	rep(i,n){
		cin>>in;
		chmax(mxl,in/w);
		v[in/w]++;
		chmax(mxh,v[in/w]);
	}
	rep(i,mxl+1){
		ans+=(mxl-i)*v[i];
	}
	ans=ans/(mxl*mxh);
	ans+=0.01;
	fcout(7)<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,w;
	while(cin>>n>>w,n)solve(n,w);
}


Measured memory_bytes: 3256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = a * 2 + b * 2;
        System.out.println(area + " " + length);
        sc.close();
        }
        
}


Measured memory_bytes: 26148
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0] * N
    pre = 0
    for i, c1, c2 in zip(range(1, N), S[:], S[1:]):
        if c1 == "A" and c2 == "C":
            pre += 1
        AC[i] = pre
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()


Measured memory_bytes: 31612
N,T = map(int,input().split())
ctlist = [list(map(int,input().split())) for _ in range(N)]

minimum_cost = 1001

for sub_list in ctlist:
    if sub_list[1] <= T:
        if sub_list[0] < minimum_cost:
            minimum_cost = sub_list[0]

if minimum_cost == 1001:
    print("TLE")
else:
    print(minimum_cost)


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

struct trump {
	char a;
	int num;
	int num2;
};

void bubblesort(trump a[], int n) {
	int j = 20000;

	for (int j = 0; j < n; j++) {
		for (int i = n - 1; i >= j + 1; i--) {
			if (a[i].num < a[i - 1].num) {
				swap(a[i].num, a[i - 1].num);
				swap(a[i].a, a[i - 1].a);
				swap(a[i].num2, a[i - 1].num2);
			}
		}
	}
}

void selectionsort(trump v[], int n) {
	int b;
	for (int i = 0; i < n; i++) {
		b = i;
		for (int j = i; j < n; j++) {
			if (v[b].num > v[j].num)
				b = j;
		}
		if (v[i].num > v[b].num) {
			swap(v[i].num, v[b].num);
			swap(v[i].a, v[b].a);
			swap(v[i].num2, v[b].num2);
		}
	}
}

int main() {
	int n;
	trump x[36];
	trump y[36];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i].a;
		cin >> x[i].num;
		x[i].num2 = i + 1;
	}
	for (int i = 0; i < n; i++) {
		y[i].a = x[i].a;
		y[i].num = x[i].num;
		y[i].num2 = i + 1;
	}

	bubblesort(x, n);

	for (int i = 0; i < n; i++) {
		if (i > 0)
			cout << " ";
		cout << x[i].a << x[i].num;
	}
	cout << endl;

	int asd = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (x[i].num == x[j].num && x[i].num2 > x[j].num2) {
				asd = 1;
			}
		}
	}

	if (asd == 1) {
		cout << "Not stable\n";
	}
	else
		cout << "Stable\n";

	selectionsort(y, n);

	for (int i = 0; i < n; i++) {
		if (i > 0)
			cout << " ";
		cout << y[i].a << y[i].num;
	}
	cout << endl;

	asd = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (y[i].num == y[j].num && y[i].num2 > y[j].num2) {
				asd = 1;
			}
		}
	}

	if (asd == 1) {
		cout << "Not stable\n";
	}
	else
		cout << "Stable\n";

	return 0;
}


Measured memory_bytes: 3100
/*  -*- coding: utf-8 -*-
 *
 * 2792.cc: SNS
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

ll gcd(ll m, ll n) {
  if (m < n) swap(m, n);
  while (n > 0) {
    ll r = m % n;
    m = n;
    n = r;
  }
  return m;
}

inline ll absll(ll a) { return (a >= 0) ? a : -a; }

/* main */

int main() {
  ll a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);

  ll mind = absll(b - a);

  // an / bn = a' / b -> a' = b * an / bn;
  for (int an = 1; an <= n; an++)
    for (int bn = 1; bn <= n; bn++) {
      ll ban = b * an;
      if (ban % bn == 0) {
	ll d = absll(ban / bn - a);
	if (mind > d) mind = d;
      }
    }

  printf("%lld\n", mind);
  return 0;
}



Measured memory_bytes: 3220
w=[input() for _ in range(int(input()))]

used=[w[0]]
last_chr=w[0][-1]

for word in w[1:]:
    if (word[0]==last_chr) and (word not in used):
        used.append(word)
        last_chr=word[-1]
    else:
        print("No")
        exit()
print('Yes')

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

using namespace std;

typedef long long LL;

#define fin "\n"


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

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

int f(int turn, LL sum, vector<LL> A){
    int one=0,two=0,odd=0,O=-1;
    int N=A.size();
    REP(i,N){
        if(A[i]==1)one++;
        else if(A[i]%2==0)two++;
        else odd++,O=i;
    }
    if(one){
        if((sum-N)%2==1)return turn;
        else return 1-turn;
    }
    else if(odd>=1&&(sum-N)%2==1)return turn;
    else if(odd==1){
        LL g=A[O]-1;
        REP(i,N)if(i!=O)g=gcd(g,A[i]);
        vector<LL> B=A;
        B[O]--;
        REP(i,N)B[i]/=g;
        return f(1-turn,(sum-1)/g,B);
    }
    else return 1-turn;
}
int main(){
    int N;
    cin>>N;
    LL sum=0;
    vector<LL> A(N);
    REP(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    if(sum==N)cout<<"Second"<<endl;
    else 
    if(f(0,sum,A)==0)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 37888
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	a,b,h,m = readline() |> split |> parseMap
	hs = h/6+m/360
	ms = m/30
	println(sqrt((a*cos(hs*pi)-b*cos(ms*pi))^2+(a*sin(hs*pi)-b*sin(ms*pi))^2))
end

main()

Measured memory_bytes: 209360
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

long long int abss(long long int x){return x>=0?x:-x;}

int main(){
int n;
long long int sum_a, sum=1000000000000000;
cin >> n;
long long int a[n],bi[n];
for(int i=0;i<n;i++){
cin >> a[i];
bi[i] = a[i] - (i+1);
//cout<<bi[i]<<endl;
}

sort(bi, bi+n);
for(int c=-1;c<=1;c++){
int b=bi[n/2+c];
sum_a = 0;
for(int i=0;i<n;i++) sum_a += abs(a[i]-(b+i+1));
if(sum_a<=sum){sum=sum_a;}
}

cout << sum << "\n";
}

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
 string s, t;
 cin >> s >> t;
 int cnt = 0;
 FOR(i, 0, 3) {
   if (s[i] == t[i]) cnt++;
  }
  cout << cnt << "\n";
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

char formula[101];
int p;

int additive() {
  int result = multitive();
  while (formula[p] == '+' || formula[p] == '-')
    if (formula[p++] == '+')
      result += multitive();
    else
      result -= multitive();
  return result;
}

int multitive() {
  int result = term();
  while (formula[p] == '*' || formula[p] == '/')
    if (formula[p++] == '*')
      result *= term();
    else
      result /= term();
  return result;
}

int term() {
  int result = 0;
  if (formula[p] == '(') {
    p++;
    result = additive();
    p++;
  } else while ('0' <= formula[p] && formula[p] <= '9')
    result = result * 10 + formula[p++] - '0';
  return result;
}

int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", formula);
    p = 0;
    printf("%d\n", additive());
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define N 100
int main(){
int M[N][N];
int i,j,n,u,k,v;
scanf("%d",&n);
for(i=0;i<n;i++){
  for(j=0;j<n;j++)M[i][j]=0;
}
for(i=0;i<n;i++){
  scanf("%d%d",&u,&k);
  u--;
  for(j=0;j<k;j++){
scanf("%d",&v);
  v--;
  M[u][v]=1;
}
}
for(i=0;i<n;i++){
  for(j=0;j<n;j++){
    if(j)printf(" ");
    printf("%d",M[i][j]);
  }
printf("\n");
}
return 0;
}



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

string S;
int v[100000];
long long vote[100000];
vector<vector<int>> G;
int nodeCnt;
int idx;
int makeTree(int crt) {
    int num = 0;
    while (idx < S.length() - 1) {
        if (S[idx] != '[' && S[idx] != ']') {
            num *= 10;
            num += S[idx] - '0';
            vote[crt] = num;
            idx++;
        } else if (S[idx] == '[') {
            nodeCnt++;
            G[crt].push_back(nodeCnt);
            idx++;
            makeTree(nodeCnt);            
        } else {
            idx++;
            return 0;
        }
    }
    return 0;
}

long long calc(int crt) {
    if (vote[crt] > 0) return vote[crt] = vote[crt]/2+1;
    
    long long ret = 0;
    vector<long long> childs;
    for (int i = 0; i < G[crt].size(); i++) {
        childs.push_back(calc(G[crt][i]));
    }
    sort(childs.begin(), childs.end());
    for (int i = 0; i <= childs.size()/2; i++) {
        ret += childs[i];
    }
    return vote[crt] = ret;
}

int solve(void) {
    cin >> S;
    G = vector<vector<int>> (100000);
    nodeCnt = 0;
    idx = 1;
    memset(vote, 0, sizeof(vote));
    
    makeTree(0);
    /*for (int i = 0; i <= nodeCnt; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            cout << G[i][j] << ", ";
        }
        cout << endl;
    }*/
    
    long long ret = calc(0);
    return ret;
}

int main(void){
    int N; cin >> N;
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        ans.push_back(solve());
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    
}



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

int main(){
    int A, B;
    cin >> A >> B;
    int ans = 0;
    int kosu = 1;
    for(int i = 1; i < 100; i++){
        if(kosu >= B){
            break;
        }else{
            kosu += A - 1;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int dp[105][10005];
int N,W;
int v[105],w[105];

signed main(){
    memset(dp,0,sizeof(dp));
    cin>>N>>W;
    for(int i=1;i<=N;++i)cin>>v[i]>>w[i];
    for(int i=1;i<=N;++i){
        for(int j=0;j<=W;++j){
            if(j<w[i])dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],max(dp[i-1][j-w[i]]+v[i],dp[i][j-w[i]]+v[i]));
        }
    }
    int ans=0;
    for(int i=0;i<=W;++i){
        ans=max(dp[N][i],ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9376
#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();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int A,B;
    int result=0;
    cin >> A >> B;
    REP(i,2){
        if(A<B){
            result += B;
            B--;
        }else{
            result += A;
            A--;
        }
    }
    cout << result << endl;
    return 0;
}

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

#define ll long long
#define EPSION numeric_limits<double>::epsilon()
#define REP(i,n) for(int i=0; i<n; ++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

//ifstream f("input.in");
//ofstream g("output.out");

signed main(int argc, char **argv)
{
    IOS;

    string t;
    int ans = 0, n, q;

    cin>>n>>q>>ws;
    int dp[n] = {0};
    getline(cin, t);

    dp[0] = 0;
    for(int i = 1; i < n; ++i)
    {
        if(t[i] == 'C' && t[i-1] == 'A')
        {
            dp[i] = dp[i-1] + 1;
        }
        else
            dp[i] = dp[i-1];
    }

    REP(i, q)
    {
       int s, e;
       cin>>s>>e;
       cout<<dp[e-1] - dp[s-1]<<'\n';
    }

    return 0;
}



Measured memory_bytes: 1488
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int n, k;
  while (scanf("%d %d", &n, &k)) {
    if ((n|k) == 0)
      break;

    bool blank = false;
    vector<int> num(n+2, 0);
    for (int i = 0; i < k; ++i) {
      int m;
      scanf("%d", &m);
      if (m == 0)
	blank = true;
      else
	++num[m];
    }

    int ans = 0;
    if (blank) {
      int cnt = 0, prev = 0;
      for (int i = 0; i <= n+1; ++i) {
	if (num[i]) {
	  ++cnt;
	} else {
	  ans = max(ans, cnt);
	  cnt = i - prev;
	  prev = i;
	}
      }
    } else {
      int cnt = 0;
      for (int i = 0; i <= n+1; ++i) {
	if (num[i]) {
	  ++cnt;
	} else {
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
from collections import deque

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

g = [[] for _ in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

d = [10000000]*n
d[0] = 0
q = deque([0])

prev = [0] * n

while q:
    p = q.popleft()
    for v in g[p]:
        if d[v] == 10000000:
            d[v] = d[p] + 1
            prev[v] = p
            q.append(v)

print("Yes")
for i in range(1, n):
    print(prev[i] + 1)

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

int main (){
  int N,max = 0,min;
  cin >> N;
  vector<int> A (N);
  for (int i = 0;i < N;i++)
    cin >> A.at(i); 
  min = A.at(0);
  for (int i = 0;i < A.size();i++){
    if(min > A.at(i)) min = A.at(i);
    if(max < A.at(i)) max = A.at(i);
  }
  cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int INF = 2e18 + 239;

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

	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	vector<int> c(n);
	for (auto &t : p) {
		cin >> t;
		t--;
	}
	for (auto &t : c) {
		cin >> t;
	}
	int ans = -INF;
	for (int i = 0; i < n; i++) {
		vector<int> cs;
		int pnt = i;
		for (int j = 0; ; j++) {
			if (j > 0 && pnt == i) break;
			cs.push_back(c[p[pnt]]);
			pnt = p[pnt];
		}
		int F = -INF;
		int S = -INF;
		{
			int all = (k / (int)cs.size());
			int cmod = (k % (int)cs.size());
			int alls = 0;
			for (auto t : cs) {
				alls += t;
			}
			if (alls <= 0) {
				all = 0;
				cmod = min(k, (int)cs.size());
			} else {
				//
			}
			int add = 0;
			int s = 0;
			if (cmod) {
				add = -INF;
			}
			for (int j = 0; j < cmod; j++) {
				s += cs[j];
				add = max(add, s);
			}
			F = add + alls * all;	
		}
		{
			int all = (k / (int)cs.size()) - 1;
			int cmod = min(k, (int)cs.size());
			if (all >= 0) { 
				int alls = 0;
				for (auto t : cs) {
					alls += t;
				}
				int add = 0;
				int s = 0;
				if (cmod) {
					add = -INF;
				}
				for (int j = 0; j < cmod; j++) {
					s += cs[j];
					add = max(add, s);
				}
				S = add + alls * all;
			}
		}
		ans = max(ans, F);
		ans = max(ans, S);
			
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3380
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	map<string, int> blue, red;
	rep(i,n){
		string s;
		cin >> s;
		++blue[s];
	}
	int m;
	cin >> m;
	rep(i,m){
		string t;
		cin >> t;
		++red[t];
	}
	for(auto p : blue){
		chmax(ans, p.second - red[p.first]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3656
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string b = Console.ReadLine();
            int A = int.Parse(b);
            if (A == 1) { Console.Write("Hello World"); }
            else
            {
                string c = Console.ReadLine();
                string d = Console.ReadLine();
                Console.Write(int.Parse(c) + int.Parse(d));
            }
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {

        string str = Console.ReadLine();

        string[] strer = new string[3];

        strer = str.Split(' ');

        long a = long.Parse(strer[0]);
        long b = long.Parse(strer[1]);
        long k = long.Parse(strer[2]);
        long count = 0;

        while (true)
        {
            if (a % 2 != 0)
            {
                a -= 1;
            }
            b = b + a / 2;
            a = a / 2;
            count++;
            if (count == k)
            {
                break;
            }

            if (b % 2 != 0)
            {
                b -= 1;
            }
            a = a + b / 2;
            b = b / 2;
            count++;
            if (count == k)
            {
                break;
            }
        }
           
        Console.WriteLine($"{a} {b}");


    }
}

Measured memory_bytes: 13140
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n = int(input())
    a = Counter(map(int, input().split()))
    key_count = len(a.keys())
    keys_values = a.most_common()

    if key_count == 1:
        if keys_values[0][0] == 0:
            print('Yes')
        else:
            print('No')
    elif key_count == 2:
        if keys_values[0][0] == 0 or keys_values[1][0] == 0:
            if n % 3 == 0:
                if keys_values[1][0] == 0:
                    if keys_values[0][1] // keys_values[1][1] == 2 and keys_values[0][1] % keys_values[1][1] == 0:
                        print('Yes')
                    else:
                        print('No')
                elif keys_values[0][0] == 0:
                    if keys_values[1][1] // keys_values[0][1] == 2 and keys_values[1][1] % keys_values[0][1] == 0:
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                print('No')
        else:
            print('No')
    elif key_count == 3:
        if keys_values[0][1] == keys_values[1][1] == keys_values[2][1]:
            xors = keys_values[0][0] ^ keys_values[1][0] ^ keys_values[2][0]

            if xors == 0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 15528
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"math"
)

var (
	in = bufio.NewScanner(os.Stdin)
)

func init() {
	in.Buffer([]byte{}, math.MaxInt64)
	in.Split(bufio.ScanWords)
}
func main() {
	a := readInt64Slice(2)
	n := a[0]
	k := a[1]
	ans := int64(0)
	l := n % k
	r := k-(n%k)
	if l > r {
		ans = r
	}else{
		ans = l
	}
	//if n > k {
	//	tmp := n % k
	//	if tmp == 0 {
	//		ans = 0
	//	} else {
	//		ans = k - tmp
	//	}
	//
	//} else {
	//	ans = n
	//}
	fmt.Println(ans)
}

func readInt64Slice(n int) []int64 {
	line := readStringSlice(n)
	slice := make([]int64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseInt(tmp, 10, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)
	}
	return slice
}
func readFloat64Slice(n int) []float64 {
	line := readStringSlice(n)
	slice := make([]float64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseFloat(tmp, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)

	}
	return slice
}
func readString() string {
	in.Scan()
	return in.Text()

}
func readStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = readString()
	}
	return s
}
func dump(value ...interface{}) {
	for _, v := range value {
		fmt.Printf("%#v\n", v)
	}
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int m,n;
    cin>>n>>m;
    int total=0;
    int sum=0;
    vector<int> vote(n);

    for(int i=0; i<n; i++){
        cin>>vote[i];
        sum+=vote[i];
    }

    for(int x : vote){
        if((x*4*m)>=sum)
            ++total;
    }
    if(total>=m)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,n1,cnt=0,q;
    cin>>n;
    n1=n;
    while(n1>0)
    {
        q=n1%10;
        if(q==2)
            cnt++;
        n1/=10;
    }
    cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

int main() {
    double x1, y1, x2, y2;
    double dx, dy;
    std::cin >> x1 >> y1 >> x2 >> y2;
    dx = x2 - x1;
    dy = y2 - y1;
    printf("%lf\n", sqrt( pow(dx, 2) + pow(dy, 2) ));
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct UnionFind {
    vector<int> node;
    UnionFind(int N) {
        node.resize(N, -1);
    }
    int find(int x) {
        return node[x] < 0 ? x : node[x] = find(node[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;

        node[x] += node[y];
        node[y] = x;
        return true;
    }
};

struct Edge {
    int from, to, dist, cost;
    Edge(int f, int t, int d, int c) : from(f), to(t), dist(d), cost(c) {}
    Edge(int t, int d, int c) : to(t), dist(d), cost(c) {}
    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
};
using Graph = vector< vector< Edge > >;

struct Elem {
    int pos, cost;
    bool operator<(const Elem &e) const {
        return cost > e.cost;
    }
};

struct Query{
    int from, to, dist, cost;
    bool operator<(const Query &q) const {
        return cost > q.cost;
    }
};

const int INF = 1 << 29;
int main() {
    int N, M;
    while(cin >> N >> M, N || M) {
        UnionFind uf(N);
        
        Graph G(N);
        for(int i=0; i<M; i++) {
            int u, v, d, c; cin >> u >> v >> d >> c;
            u--; v--;
            G[u].push_back(Edge(v, d, c));
            G[v].push_back(Edge(u, d, c));
        }

        vector<int> dist(N, INF);
        dist[0] = 0;

        priority_queue<Elem> que;
        que.push(Elem{0, 0});

        while(que.size()) {
            Elem cur = que.top(); que.pop();

            if(cur.cost > dist[cur.pos]) continue;
            for(auto e : G[cur.pos]) {
                int to = e.to, cost = e.dist;
                if(dist[to] > cur.cost + cost) {
                    dist[to] = cur.cost + cost;
                    que.push(Elem{to, dist[to]});
                }
            }
        }

        vector<int> min_cost(N, INF);
        min_cost[0] = 0;
        for(int i=0; i<N; i++) {
            for(auto e : G[i]) {
                int u = i, v = e.to, cost = e.dist;
                if(dist[v] - dist[u] == cost) {
                    min_cost[v] = min(min_cost[v], e.cost);
                }
            }
        }
        cout << accumulate(min_cost.begin(), min_cost.end(), 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 4224
import math

a, b, x = map(int, input().split())

L = (a ** 2) * b

if L == x:
    print(0)
else:
    r = L - x
    if r <= L / 2:
        y = 2 * r / (a ** 2)
        print(math.degrees(math.acos(a / (math.sqrt(y ** 2 + a ** 2)))))
    else:
        y = 2 * x / (b * a)
        print(math.degrees(math.acos(y / (math.sqrt(y ** 2 + b ** 2)))))

Measured memory_bytes: 38384
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    x: usize,
    l: [usize; n]
    }
    let mut ans = 1;
    let mut d = 0;
    for i in l{
        d += i;
        if x >= d {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2184
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;



void Main(){

  ll MOD=1000000007;
  int N;
  ll K;
  cin >> N;
  cin >> K;
  vector<int> A;

  rep(i,N){
    int aa;
    cin >> aa;
    A.emplace_back(aa);
  }

  ll ct=0;

  ll ct1[N]={};
  ll ct2[N]={};

  rep(i,N){
   reps(j,i+1,N){
     if(A[i]>A[j]) ct1[i]++;
     if(A[j]>A[i]) ct2[j]++;
   }
  }

  ll a=((K*(K-1))/2)%MOD;
  ll b=((K*(K+1))/2)%MOD;

  rep(i,N){
    ll c1=ct1[i];
    ll c2=ct2[i];
    ct=(ct+( c1*b + c2*a ))%MOD;
  }



  cout << ct <<"\n";
}


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


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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }


int n;
ll a[3005];
ll memo[3005][3005][2];
ll dfs(int l, int r, int t) {
    if (r < l) return 0;
    if (memo[l][r][t] != -1) return memo[l][r][t];
    if (t == 0) return memo[l][r][t] = max(dfs(l + 1, r, 1) + a[l], dfs(l, r - 1, 1) + a[r]);
    else return memo[l][r][t] = min(dfs(l + 1, r, 0) - a[l], dfs(l, r - 1, 0) - a[r]);
}

void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];
    fillArray(memo, -1);
    cout << dfs(0, n - 1, 0) << endl;
}

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


Measured memory_bytes: 141568
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

const long long MOD = 1e9+7;
const int N = 1e6;
long long inv[N];
long long fact[N];
long long fact_inv[N];

int main()
{
    for (long long i = 1; i < N; i++) {
        inv[i] = (i == 1) ? 1 : (MOD - (MOD / i) * inv[MOD % i] % MOD);
    }

    fact[0] = 1;
    fact_inv[0] = 1;

    for(int i = 1; i < N; ++i) {
        fact[i] = fact[i - 1] * i % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    long long ans = 0;
    for(int i = 0; i < w - b; ++i) {
        long long x = fact[(h - a - 1) + (b + i)] * fact_inv[h - a - 1] % MOD * fact_inv[b + i] % MOD;
        long long y = fact[(a - 1) + (w - b - 1 - i)] * fact_inv[a - 1] % MOD * fact_inv[w - b - 1 - i] % MOD;
        ans += x * y % MOD;
        ans %= MOD;
    }    
    cout << ans % MOD << endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int n, m;
   cin >> n >> m;
   if (n % 2) {
      for (int l = 2, r = n; l < r; l++, r--) {
         if ((m--) > 0) printf("%d %d\n", l, r);
      }
   } else {
      bool fg = false;
      for (int l = 2, r = n; l < r; l++, r--) {
         if (!fg && r - l <= n / 2) {
            l++;
            fg = true;
         }
         if ((m--) > 0) printf("%d %d\n", l, r);
      }
   }
   return 0;
}

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

#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define nrof(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define rep(i, k, n) for(int i = (int)k; i < (int)n; ++i)
#define per(i, k, n) for(int i = (int)k - 1; i >= (int)n; --i)
#define x first
#define y second
#define mp make_pair
#define sz(a) (int)(a.size())
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e6 + 9;
const int M = 2e3 + 9;
const int INFINT = 1e9 + 9;
const ll INFLL = 1e18 + 9;
const ll MOD = (ll) (1000000007);

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    forn(i, n) cin >> a[i];
    ll sum = 0;
    forn(i, n) sum += a[i];

    ll ans = 0;
    forn(i, n) {
        sum -= a[i];
        ans = (ans + (sum % MOD) * (a[i] % MOD)) % MOD;
    }
    cout << ans % MOD << endl;
}

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

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4780
module Main where

import Control.Applicative
import Data.Int

data Test = Test Int64 Int64 Int64 Int64 Int64 Int64 Int64

solve :: Test -> Int64
solve (Test ai ao _ aj al _ _) = ao + go ai aj al
    where go ai aj al | odd ai && odd aj && odd al = ai + aj + al
                      | even ai && even aj && even al = ai + aj + al
                      | ai == 0 || aj == 0 || al == 0 = 2 * (ai `div` 2 + aj `div` 2 + al `div` 2)
                      | otherwise = max u v
                      where u = 2 * (ai `div` 2 + aj `div` 2 + al `div` 2)
                            v = 3 + 2 * ((ai - 1) `div` 2 + (aj - 1) `div` 2 + (al - 1) `div` 2)

test0 = Test 2 1 1 0 0 0 0
test1 = Test 0 0 10 0 0 0 0

runTests = map solve [test0, test1]

main :: IO ()
main = do
  [ai, ao, at, aj, al, as, az] <- map read . words <$> getLine
  print . solve $ Test ai ao at aj al as az

Measured memory_bytes: 508
//44
#include<iostream>
#include<map>

using namespace std;

void rot(int *x,int i){
  int da[][4]={{0,4,5,1},{0,3,5,2},{0,2,5,3},{0,1,5,4},{1,2,4,3}};
  int *d=da[i];
  int t=x[d[0]];
  x[d[0]]=x[d[1]];
  x[d[1]]=x[d[2]];
  x[d[2]]=x[d[3]];
  x[d[3]]=t;
}

int main(){
  for(int n;cin>>n,n;){
    map<int,map<int,map<int,int> > > m;
    int c[7]={};
    while(n--){
      int t,f;
      cin>>t>>f;
      int d[]={1,2,3,4,5,6};
      for(;;){
	rot(d,0);
	if(d[0]==t)break;
	rot(d,1);
	if(d[0]==t)break;
      }
      while(f!=d[1]){
	rot(d,4);
      }
      int x=0,y=0,z=99;
      for(;;){
	while(m[z-1][y][x]==0&&z>0){
	  z--;
	}
	if(z==0)break;
	int dy[]={1,0,0,-1};
	int dx[]={0,1,-1,0};
	int rd,mf=3;
	for(int i=0;i<4;i++){
	  int ny=y+dy[i];
	  int nx=x+dx[i];
	  if(d[i+1]>mf&&m[z][ny][nx]==0&&m[z-1][ny][nx]==0){
	    mf=d[i+1];
	    rd=i;
	  }
	}
	if(mf==3)break;
	y+=dy[rd];
	x+=dx[rd];
	rot(d,rd);
      }
      c[m[z-1][y][x]]--;
      c[m[z][y][x]=d[0]]++;
    }
    for(int i=1;i<=6;i++){
      cout<<c[i]<<((i==6)?'\n':' ');
    }
  }
  return 0;
}

Measured memory_bytes: 1232
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;


long long int N,M,K;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;    
    if(N>=13){
        cout<<M<<endl;
    }else if(N>=6){
        cout<<M/2<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 256
L = int(input())
C = list(map(int, input().split()))
A = []
for i in range(len(C)):
	if C[i]>0:
		if A.count(C[i]):
			print(i+1)
			exit(0)
		else:
			A.append(C[i])
	else:

		if len(A)==0 or A[len(A)-1]!=abs(C[i]):
			print(i+1)
			exit(0)
		else:
			del(A[len(A)-1])
print('OK')


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      string s;
      cin >> s;
      string t;
      cin >> t;
      cout << (t+s);
      return 0;
}

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

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

    vector<vector<int> > s(m);
    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            --x;
            s[i].push_back(x);
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int res = 0;
    for (int bit = 0; bit < (1<<n); bit++) {
        bool numSwitch[n];
        for (int i = 0; i < n; i++) {
            numSwitch[i] = false;
        }
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                numSwitch[i] = true;
            }
        }

        bool judge = true;
        for (int i = 0; i < m; i++) {
            int num = 0;
            for (int j = 0; j < s[i].size(); j++) {
                if (numSwitch[s[i][j]]) ++num;
            }
            if (num % 2 != p[i]) judge = false;
        }
        if (judge) ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;



int main()
{



     flash;
     ///////////////////////////////////////////////////////////////////////////////////////

     
     ll a,b;
     cin>>a>>b;
     if(a==1||b==1)
     {
     	cout<<1;
     }
     else 
     {
     ll val=a*b;
     if(val%2==0)
     {
     	cout<<val/2;
     }
     else
     {
     	cout<<val/2+1;
     }

}

    ///////////////////////////////////////////////////////////////////////////////////////

     return 0;

}


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


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll a[maxn];
int main()
{
  initFactorials();
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  for(int i = 1; i <= n ; i++)
  {
    cin >> a[i];
  }

  sort(a + 1, a + n + 1);
  ll ans = 0;
  for(int i = 1 ; i <= n; i++)
  {
    int left = i - 1;
    int right = n - i;
    ans += (a[i] * (C(left, k - 1) - C(right, k - 1))) % mod;
    ans += mod;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7508
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 200500;
int d[maxn], t[maxn];

int main()
{
	int N, M;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) scanf("%d", &d[i]);
	scanf("%d", &M);
	for (int i = 1; i <= M; i++) scanf("%d", &t[i]);
	sort(d+1, 1 + N+d);
	sort(t+1, 1 + M+t);
	int p1 = 1, p2 = 1;
	bool flag = false;
	while (p1<=M&&p2<=N)
	{
		if (p1 != M) {
			if (d[p2] == t[p1]) {
				p2++, p1++;
			}
			else {
				p2++;
			}
		}
		else
		{
			if (d[p2] == t[p1]) {
				flag = true;
				break;
			}
			else
			{
				p2++;
			}
		}
	}
	if (flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#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() {
  char a;
  cin >> a;
  cout << (char)  (a + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

string s;

int f(int now){
    // cout << now << endl;
    if(s[now] != 'm') return -1;
    now++;
    if(s[now] != 'e'){
        now = f(now);
        if(now == -1) return -1;
    }
    now++;
    if(s[now] != 'w'){
        now = f(now);
        if(now == -1) return -1;
    }
    now++;
    return now;
}

signed main(){
    cin >> s;
    cout << (f(0) == (int)s.size() ? "Cat" : "Rabbit") << endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

ll func(ll n){
  if(n == 0) return 0;
  return n/5 + func(n/5);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  if(N%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  cout << func(N/2) << endl;
}

Measured memory_bytes: 256