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

int p, q, a, n, cnt;

int gcd(int c, int d){
    return d == 0 ? c : gcd(d, c%d);
}

void dfs(int num, int now, int acc, int tmpp, int tmpq){
    if(p == tmpp && q == tmpq){
        cnt++;
        return;
    }
    
    if(num == n)    return;
    
    if(tmpp*now*q+(n-num)*tmpq*q < p*tmpq*now || acc*now > a)    return;
    
    int mo = tmpq*now;
    int ch = tmpp*now + tmpq;
    int g = gcd(mo, ch);
    mo /= g, ch /= g;

    if(ch*q <= mo*p)    dfs(num+1, now, acc*now, ch, mo);
    
    dfs(num, now+1, acc, tmpp, tmpq);
}

int main(){
    while(cin >> p >> q >> a >> n, p+q+a+n){
        int g = gcd(p, q);
        p /= g, q /= g;
        cnt = 0;
        dfs(0, 1, 1, 0, 1);
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
  u,v=map(int,input().split())
  G[u-1].append(v-1)

s,t=map(int,input().split())
s-=1
t-=1
from collections import deque
dist=[[-1]*3 for i in range(n)]
dist[s][0]=0
q=deque()
q.append([s,0])
while q:
  cur,parity=q.popleft()
  for nx in G[cur]:
    nx_parity=(parity+1)%3
    if dist[nx][nx_parity]==-1:
      dist[nx][nx_parity]=dist[cur][parity]+1
      q.append([nx,nx_parity])
if dist[t][0]==-1:
  print(-1)
else:
  print(int(dist[t][0]//3))

Measured memory_bytes: 38064
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  vector<bool> seen(26,false);
  REP(i, s.size()){
    seen[s[i]-'a'] = true;
  }
  REP(i, 26){
    if(!seen[i]){
      cout << (char)('a'+i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
	int n,k;
	int i,j,u[5],v=0;
	int a[100000],sum=0,w=0;
	while(scanf("%d%d",&n,&k),n!=0 && k!=0){
		for(i=0;i<n;i++) scanf("%d",&a[i]);
		for(i=0;i<n-k+1;i++){
			for(j=i;j<k+i;j++) sum+=a[j];
			if(sum>w) w=sum;
			sum=0;
		}
		u[v]=w,v++;
	}
	for(i=0;i<v;i++) printf("%d\n",u[i]);
	return 0;
}



Measured memory_bytes: 2100
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();	//湖の円周（Kメートル）
        int n = scan.nextInt();	//家の数（N軒）
        int space = 0;
        int[] a;				//家の北側からの時計回りの距離(1, 2, 3...N)
        a = new int[n];

//		System.out.println("k="+k);
//		System.out.println("n="+n);
//		System.out.println("space="+space);

        for (int i=0; i<n; i++) {
        	a[i] = scan.nextInt();
        }

        space = (k-a[n-1])+a[0];		//家と家との間の距離
//		System.out.println("space="+space);

        for (int i=0; i<n-1; i++) {
 			if(space<(a[i+1]-a[i])) {
 				space = (a[i+1]-a[i]);
 			}       
        }
        
        // 全体（Kメートル）-（間が一番空いている距離）= （答え）
		System.out.println(k-space);
	    scan.close();	
    }
}

Measured memory_bytes: 74920
N,A,B= map(int,input().split())
S=input()
sanka=0
kaigai=0

for i in range(N):
  if S[i]=="a":
    if sanka< A+B:
      print("Yes")
      sanka += 1
    else:
      print("No")
  elif S[i]=="b":
    if sanka < A+B and kaigai <B:
      print("Yes")
      sanka += 1
      kaigai += 1
    else:
      print("No")    
  else:
    print("No")

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    map<int,int> A;
    REP(i,N){
        int a; cin >> a;
        A[a] ++;
    }
    int ans = 0;
    for(auto a: A){
        if(a.first < a.second){
            ans += a.second - a.first;
        }else if(a.first > a.second){
            ans += a.second;
        }
    }

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

Measured memory_bytes: 7944
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<vector<pii>> g;
set<pii> e;
vector<int> dis;
int n;

void dijkstra(int s){

    dis.clear();
    dis.resize(n + 1, MAX);
    dis[s] = 0;

    std::priority_queue<pii, vector<pii>, greater<>> pq;
    pq.push(mp(0, s));
    while(!pq.empty()){
        int now = pq.top().S, d = pq.top().F;
        pq.pop();
        if(d != dis[now]) continue;
        for(pii i : g[now]){
            if(d + i.S < dis[i.F]){
                dis[i.F] = d + i.S;
                pq.push(mp(d + i.S, i.F));
            }
        }
    }

}

int main(){
    StarBurstStream

    int m;
    cin >> n >> m;

    g.resize(n + 1);
    for(int i = 0; i < m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        g[u].eb(mp(v, c));
        g[v].eb(mp(u, c));
    }

    for(int i = 1; i <= n; i++){

        dijkstra(i);

        for(int u = 1; u <= n; u++){
            for(pii v : g[u]){
                if(dis[v.F] == dis[u] + v.S) e.insert(mp(min(u, v.F), max(u, v.F)));
            }
        }

    }

    cout << m - e.size() << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
char ch[1001][1001];
int h,w;
int dp[1001][1001];
int call(int x, int y)
{
    if(x==h-1 and y==w-1) return 1;
    if(x>=h or y>=w) return 0;
    int &ret=dp[x][y];
    if(ret!=-1) return ret;
    int ans=0;
    if(ch[x+1][y]=='.') ans+=call(x+1,y);
    if(ch[x][y+1]=='.') ans+=call(x,y+1);
    return ret=ans%mod;

}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++) cin>>ch[i][j];
    }
    cout<<call(0,0)<<endl;
}


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

//降順
int des(const void *a, const void *b)
{
  return *(int *)b - *(int *)a;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i=0; i<n; i++)
    cin >> a[i];
  qsort(a, n, sizeof(int), des);
  long h = 0, w = 0, p = 0;
  for (int i=0; i<n; i++) {
    if (p != a[i]) {
      p = a[i];
      continue;
    }
    if (h == 0) {
      h = p;
      p = 0;
    } else {
      w = p;
      break;
    }
  }
  cout << h*w << '\n';
  return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y,z;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[500101];
int l[500111];
int j[201001];

long long x,y,z,mod=998244353;
string r;
//char r[2];

P u[500101];
priority_queue<int,vector<int>,greater<int> > q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v;


bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y>b.y;
}


int main()
{
  scanf("%d %d",&a,&b);
  for(int t=1;t<=a;t++)
  {
    scanf("%d %d",&n,&m);
    u[t]={n,m};
  }
  sort(u+1,u+a+1,as);
  for(int t=1;t<=a;t++)
  {
    q.push(u[t].y);
    if(q.size()>u[t].x)
    for(;q.size()>u[t].x;q.pop())
      o[q.top()]++;
    else e++;
    //printf("%d\n",q.size());
  }
  for(int t=0;t<=b;t++)
  {
    o[b-t+1]+=o[b-t+2];
    //printf("%d ",o[b-t+1]);
    for(;o[b-t+1]>c; o[b-t+1]--,k++);
    if(b-t+1>e+1) c++;
  }
  printf("%d",k);
}
//11




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

using namespace std;

int main() {
    long long N, res = 0;
    cin >> N;
    for(long long i = 1; i < N; ++i)
    {
        long long l = 1, r = N;
        while(l<=r)
        {
            long long m = (l+r)/2;
            if(m*i>=N){
                r = m-1;
            }
            else if(m*i < N)
            {
                l = m+1;
            }
        }
        res += l-1;
    }
    std::cout << res << std::endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string S, T; cin >> S >> T;
    int ans = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3912
loop do
    n, k, m = gets.split.map(&:to_i)
    break if n == 0 && k == 0 && m == 0
    a = Array.new(n)
    n.times do |i|
        a[i] = i + 1
    end
    m -= 1
    a.delete_at(m)
    while a.size > 1
        m = (m + k - 1) % a.size
        a.delete_at(m)
    end
    puts a[0]
end

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

/**
 * https://abc042.contest.atcoder.jp/tasks/abc042_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		String[] s = new String[N];
		for(int i=0; i<N; i++) s[i] = sc.next();
		sc.close();
		
		Arrays.sort(s);
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<N; i++){
			ans.append(s[i]);
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const int INF = 1e8;

int main(){
  int N;cin >> N;
  vector<pair<ll,ll>> robot(N);
  rep(i,N){
    ll x,l;
    cin >> x >> l;
    robot[i].first = x+l;
    robot[i].second = x-l;
  }
  ll ans = 0;
  sort(all(robot));
  ll cur = -1e9+5;
  for(int i=0;i<N;i++){
    if(cur <= robot[i].second){
      ans++;
      cur = robot[i].first;
    }
  }
  cout << ans << endl;
} 

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

def f(s):
    return 'Yes' if (s.find('AC') != -1) else 'No'

def test():
    assert f('BACD') == 'Yes'
    assert f('ABCD') == 'No'
    assert f('CABD') == 'No'
    assert f('ACACA') == 'Yes'
    assert f('XX') == 'No'


def main():
    print(f(input()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
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 c = sc.nextInt();
        int d = sc.nextInt();
        int min = 0;
        if(a <= b){
            min += a;
        }
        else{
            min += b;
        }
        if(c <= d){
            min += c;
        }
        else{
            min += d;
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main() {
    int N;
    char S;
    bool flg = false;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> S;
        if (S == 'Y')flg = true;
    }
    if (flg)cout << "Four" << endl;
    else cout << "Three" << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int>a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int total = accumulate(a.begin(), a.end(), 0);
    bool check = true;
    for (int i = 0; i < m; ++i) {
        if ((double)a[i] < (double)((double)total * 1 / (4 * m))) {
            check = false;
            break;
        }
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int a,b,k;
  cin>>a>>b>>k;
  int n=max(a,b);
  vector<int> x(n);
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(a%i==0&&b%i==0){
      x.at(cnt)=i;cnt++;
    }
  }
  
  cout<<endl;
  cout<<x.at(cnt-k)<<endl;

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define maxn 300019
#define maxn2 600019
#define pii pair<int, int>
#define fi first
#define se second
#define lowbit(x) (x & (-x))
#define ll long long int 
using namespace std;

int n, m, v, p;
int a[maxn];
/*pii pro[maxn];
int cp = 0;

int c[maxn2];
void add(int x, int v){
	while (x){
		c[x] += v;
		x -= lowbit(x);
	}
}
int get(int x){
	int ans = 0;
	while (x < maxn2) {
		ans += c[x];
		x += lowbit(x);
	}
	return ans;
}

int lis[maxn2];
int cs = 0;*/

int num[maxn2];
bool judge(int x){
	int sum = x;
	int pos = upper_bound(a + 1, a + 1 + n, a[x] + m) - a;
	if (n + 1 - pos >= p) return false;
	sum += p - 1;
	if (sum >= v) return true;
	//if (sum >= m) return true;
	//sper(i, pos - 1, x) b[i] = a[i];
	//rep(i, 1, n) num[i] = 0; 
	//int suf = 0, acc = 0;
	ll acc = 0;
	sper(i, n - p + 1, x){
		//num[i] = a[x] + m - 1 - a[i] - suf;
		//acc += num[i];
		//suf = suf + num[i] - num[i + v - sum - 1];
		acc += a[x] + m - a[i];
	}
	return acc >= (ll)m * (v - sum);
}
int solve(int l, int r){
	while (l < r){
		int mid = ((r - l) >> 1) + l;
		if (judge(mid)) r = mid;
		else l = mid + 1;
	}
	return l;
}

int main(){
	//#ifndef ONLINE_JUDGE
	//	freopen("B.in", "r", stdin);
	//#endif
	scanf("%d%d%d%d", &n, &m, &v, &p);
	rep(i, 1, n) scanf("%d", &a[i]);
	//rep(i, 1, n) lis[++cs] = a[i], lis[++cs] = a[i] + m;
	//sort(lis + 1, lis + 1 + cs);
	//cs = unique(lis + 1, lis + 1 + cs) - lis - 1;
	sort(a + 1, a + 1 + n);
	//rep(i, 1, n) printf("%d ", a[i]); printf("\n");
	//printf("%d\n", solve(1, n));
	printf("%d", n - solve(1, n) + 1);
	
	/*srep(i, 1, v) add(lower_bound(lis + 1, lis + 1 + cs, a[i] + m) - lis, 1);
	rep(i, v, n) add(lower_bound(lis + 1, lis + 1 + cs, a[i]) - lis, 1);
	int ans = 0;
	add(lower_bound(lis + 1, lis + 1 + cs, a[v]) - lis, -1);
	add(lower_bound(lis + 1, lis + 1 + cs, a[v] + m) - lis, 1);
	srep(i, 1, v) if (get(lower_bound(lis + 1, lis + 1 + cs, a[i] + m) - lis + 1) < p) ans++; 
	add(lower_bound(lis + 1, lis + 1 + cs, a[v]) - lis, 1);
	add(lower_bound(lis + 1, lis + 1 + cs, a[v] + m) - lis, -1);
	rep(i, v, n) if (get(lower_bound(lis + 1, lis + 1 + cs, a[i] + m) - lis + 1) < p) ans++;
	printf("%d", ans);
	//rep(i, 1, n) b[i] = a[i];
	//srep(i, 1, v) b[i] += m;
	//sort(b + 1, b + 1 + n);
	//int ans = 0;
	//rep(i, v, n) ans += ((1 + b + 1 + n - upper_bound(b + 1, b + 1 + n, a[i] + m)) <= p) ? 1 : 0; 
	
	/*rep(i, 1, n){
		int now = a[i], _i = i;
		while (i <= n && a[i] == now) i++;
		pro[++cp] = pii(now, i - _i);
		i--;
	}
	int sum = 0, ans = 0;
	per(i, cp, 1){
		if (sum < p) sum += pro[i].se, ans += pro[i].se;
		else {
			
		}
	}*/
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Table {
  int indent;
  string name;
  string value;
  map<string, Table*> child;
  Table() {;}
  Table(int indent) : indent(indent) {;}
  Table(int indent, string name, string value) : indent(indent), name(name), value(value) {;}
};

int CountIndent(string &str) {
  int ret = 0;
  FORIT(it, str) {
    if (*it != ' ') { break; }
    ret++;
  }
  str = str.substr(ret);
  return ret;
}

string GetKey(string &str) {
  string ret;
  FORIT(it, str) {
    if (*it == ':') { break; }
    ret += *it;
  }
  str = str.substr(ret.size() + 1);
  return ret;
}

string GetValue(string &str) {
  if (str.size() == 0) { return ""; }
  str = str.substr(1);
  return str;
}

string line;
int m;
Table tables[50000];

int main() {
  string query;
  while (getline(cin, query)) {
    m = 0;
    vector<string> queries;
    {
      FORIT(it, query) {
        if (*it == '.') { *it = ' '; }
      }
      stringstream sin(query);
      string str;
      while (sin >> str) {
        queries.push_back(str);
      }
    }
    stack<Table*> st;
    tables[m++] = Table(-1);
    st.push(tables);
    while (getline(cin, line)) {
      int indent = CountIndent(line);
      string key = GetKey(line);
      string value = GetValue(line);
      //cout << st.top()->indent << " " << indent << endl;
      while (st.top()->indent >= indent) {
        st.pop();
      }
      //cout << st.top()->name << endl;
      tables[m++] = Table(indent, key, value);
      st.top()->child[key] = tables + m - 1;
      st.push(tables + m - 1);
    }
    while (st.top()->indent >= 0) { st.pop(); }
    Table *t = st.top();
    FORIT(it, queries) {
      if (!t->child.count(*it)) { goto error; }
      t = t->child[*it];
    }
    if (t->value == "") {
      puts("object");
    } else {
      printf("string \"%s\"\n", t->value.c_str());
    }
    continue;
error:
    puts("no such property");
  }
}

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

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

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3640
#include <stdio.h>
int main() {
	int n,m,c,a,sum=0,ans=0;
	int b[20]={};
	scanf("%d%d%d", &n,&m,&c);
	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++) {
		sum=c;
		for (int i = 0; i < m; i++) {
			scanf("%d", &a);
			sum+=a*b[i];
		}
		if(sum>0){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
X, K, D = list(map(int, input().split()))

syou = abs(X) // D


if (K > syou):
    K = K - syou
    if ((K % 2) == 0):
        print(abs(abs(X) - D * syou))
    else:
        print(abs(abs(X)-D*(syou+1)))
else:
    print(abs(abs(X)-D*K))


Measured memory_bytes: 61848
def main():
	# a,b,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	c = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n-1)]
	# s = list(s)
	ans = 0
	for i in range(n):
		ans += b[ a[i]-1 ]
		# print("i = {}".format(i))
		# print("ans = {}".format(ans))
		if i > 0 and a[i] - (a[i-1]) == 1:
			ans += c[ a[i]-2 ]
			# print("ans + c = {}".format(ans))
	print(ans)
 

 
	
 
 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long

using namespace std;

string lcs(string s, string t)
{
	int n = s.size(), m = t.size(), i, j;
    int d[n+1][m+1];
    for(i=0 ; i<=n ; i++)
    	for(j=0 ; j<=m ; j++)
    		d[i][j] = 0;
    for(i=1 ; i<=n ; i++)
    {
    	for(j=1 ; j<=m ; j++)
		{
			d[i][j] = max(d[i-1][j] , d[i][j-1]);
			if(s[i-1] == t[j-1])
				d[i][j] = max(d[i][j] , d[i-1][j-1]+1);
		}
    }
    int x=n, y=m;
    string ans;
    while(x>0 && y>0)
    {
    	if(x==0 || y==0) break;
    	while(d[x][y-1] == d[x][y] && y>0)//go left till end
    		y = y-1;
    	while(d[x-1][y] == d[x][y] && x>0)//go up
    		x = x-1;
    	if(x<=0 || y<=0) break;
    	if(d[x][y] == 0) break;
    	ans.push_back(s[x-1]);
    	x = x-1;
    	y = y-1;
    }
    reverse(ans.begin() , ans.end());
    return ans;
}

signed main()
{
    string s,t;
    cin >> s >> t;
    string ans = lcs(s, t);
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 70656
/**
*    created: 08.05.2020 09:17:01
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int k;
vector<ll> B,C;


void lunlun(vector<ll> &A){
    C.push_back(A.back());
    if(A.back()>=10000000000ll){
        return;
    }    
    for (int i = -1; i < 2; i++)
    {
        int vv = i + A.back()%10;
        if(vv>-1&&vv<10)
        {
            
            ll x = A.back() * 10 + vv;
            A.push_back(x);
            //↑次のノードへの遷移
            lunlun(A);            
            //再帰呼び出し
            A.pop_back();
        }
    }
    
}

int main() {
    cin >> k;
    
    for (int i = 1; i <= 9;i++)
    {
        B.push_back(i);
        lunlun(B);

    }
    sort(C.begin(), C.end());
    cout << C[k-1] << endl;
}

Measured memory_bytes: 10604
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int sum;
    void solve()
    {
        cin>>n;
        fo(i,1,n+1)
        fo(j,1,n+1)
        {
            fo(k,1,n+1)
            {
                
                sum+=__gcd(i,__gcd(j,k));
            }
        }
        cout<<sum<<endl;

    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3648
#include<iostream>
#include<cstdlib>
using namespace std;
struct node {
  int key;
  node *parent, *left, *right;
};
node *NIL, *root;
void insert(int x) {
  node *n, *r = root, *m = NIL;
  n = (node *)malloc(sizeof(node));
  n->key = x; n->left = NIL; n->right = NIL;
  while (r != NIL) {
    m = r;
    if (n->key<r->key) r = r->left;
    else r = r->right;
  }
  n->parent = m;
  if (m == NIL) root = n;
  else {
    if (n->key<m->key) m->left = n;
    else m->right = n;
  }
}

void inorder(node *p) {
  if (p != NIL) {
    inorder(p->left);
    cout << " " << p->key;
    inorder(p->right);
  }
}
void preorder(node *p) {
  if (p != NIL) {
    cout << " " << p->key;
    preorder(p->left);
    preorder(p->right);
  }
}
node *find(int x) {
  node *r = root;
  while (r != NIL) {
    if (r->key == x) return r;
    if (r->key<x) r = r->right;
    else r = r->left;
  }
  return r;
}
void deletekey(node *x) {
  node *ch=NIL, *y;
  if (x->left == NIL || x->right == NIL) {
    y = x;
    if (x->left != NIL) ch = x->left;
    if (x->right != NIL) ch = x->right;
    if(ch!=NIL) ch->parent = x->parent;
  }
  else{
    y = x->right;
    while (y->left != NIL) y = y->left;
    x->key = y->key;
    ch = y->right;
  }
  if (y->parent->left == y) y->parent->left = ch;
  else y->parent->right = ch;
  free(y);
}
int main() {
  int n, x;
  char s[7]; cin >> n;
  for (int i = 0; i<n; ++i) {
    cin >> s;
    if (s[0] == 'i') {
      cin >> x;
      insert(x);
    }
    else if (s[0] == 'p') {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
    else if(s[0]=='f'){
      cin >> x;
      if (find(x)!=NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else{
      cin >> x;
      deletekey(find(x));
    }
  }
  return 0;
}



Measured memory_bytes: 21860
#include<iostream>

using namespace std;

int bubbleSort(int A[], int N){ 
    int sw = 0;
    bool flag = 1;

    for (int i = 0; flag; i++){
        flag = 0;
        for (int j = N - 1; j >= i + 1; j--){
            if (A[j] < A[j - 1]){
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }   

        }   
    }   
    return sw; 
}

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

    sw = bubbleSort(A, N); 

    for (int i= 0; i < N; i++){
        if (i) cout << " ";
        cout << A[i];
    }   
    cout << endl;
    cout << sw << endl;
    
    return 0;
}

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

#define MOD		1000000007
#define ll		long long int
#define pll		pair<ll, ll>
#define pb		push_back
#define endl	"\n"
#define f 		first
#define s 		second
#define fastio 	ios_base::sync_with_stdio(false);cin.tie(NULL)

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

bool comp(const pll& p1, const pll& p2) {
    if(p1.f == p2.f) {
        return p2.s > p1.s;
    }
    return p2.f > p1.f;
}

int main() {
	ll h, w, m;
	cin >> h >> w >> m;
	ll row[h + 1];
	ll col[w + 1];
	memset(row, 0, sizeof(row));
	memset(col, 0, sizeof(col));

	map<pll, bool> mp;
	int k = 0;

	for(int i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        row[x]++;
        col[y]++;
        mp[{x, y}] = 1;
	}

	priority_queue<pll> pq_row, pq_col;

	for(int i = 1; i <= h; i++) {
        pq_row.push({row[i], i});
	}
	for(int i = 1; i <= w; i++) {
        pq_col.push({col[i], i});
	}

	ll ans = pq_row.top().f + pq_col.top().f;
	ll rowMax = pq_row.top().f;
	ll colMax = pq_col.top().f;

	vector<ll> xes, yes;
	while(!pq_row.empty() && pq_row.top().f == rowMax) {
        xes.pb(pq_row.top().s);
        pq_row.pop();
	}

	while(!pq_col.empty() && pq_col.top().f == colMax) {
        yes.pb(pq_col.top().s);
        pq_col.pop();
	}

	//debug(xes);
	//debug(yes);

	bool found = false;

	for(int i = 0; i < xes.size(); i++) {
        for(int j = 0; j < yes.size(); j++) {
            if(!mp[{xes[i], yes[j]}]) {
                found = true;
                break;
            }
        }
	}

	if(!found) {
        cout << ans - 1 << endl;
	} else {
        cout << ans << endl;
	}

	//debug(v);

}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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


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

	writeln(min(n*a,b));
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n;
    ll res = 1;
    cin >> n;
    FOR(i,2,n) res = res * i % base;
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    H, W = map(int, readline().split())
    S = list(readline().decode('utf-8').strip() for _ in range(H))
    dp = [[INF] * (W) for _ in range(H)]
    if S[0][0]=='#':
        dp[0][0]=1
    else:
        dp[0][0]=0
    for i in range(H):
        for j in range(W):
            if i==H-1 and j == W-1:
                break
            if j==W-1:
                if S[i][j]=='.' and S[i+1][j]=='#':
                    dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1)
                else:
                    dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            elif i == H-1:
                if S[i][j]=='.' and S[i][j+1]=='#':
                    dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1)
                else:
                    dp[i][j+1] = min(dp[i][j+1],dp[i][j])
            else:
                if S[i][j]=='.' and S[i+1][j]=='#':
                    dp[i+1][j] = min(dp[i+1][j],dp[i][j]+1)
                else:
                    dp[i+1][j] = min(dp[i+1][j],dp[i][j])
                if S[i][j]=='.' and S[i][j+1]=='#':
                    dp[i][j+1] = min(dp[i][j+1],dp[i][j]+1)
                else:
                    dp[i][j+1] = min(dp[i][j+1],dp[i][j])


    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()

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

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

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

  int mint = 1000000000;
  for(int l = 1; l <= n - k + 1; l++){
    int r = l + k -1;
    mint = min(x[r] - x[l] + min(abs(x[r]), abs(x[l])), mint);
  }

  cout << mint << endl;

  return 0;

}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; ++i) for (int j = 0; j < D; ++j) cin >> X.at(i).at(j);


  vector<double> ans;
  int cnt = 0;
  int dist = 0;
  for (int i = 0; i < N; ++i) {
    for (int k = i + 1; k < N; ++k) {
      dist = 0;
      for (int j = 0; j < D; ++j) {
          dist += (X.at(i).at(j) - X.at(k).at(j)) * (X.at(i).at(j) - X.at(k).at(j));
      }
      ans.push_back(dist);
    }
  }


  for (int i = 0; i < ans.size(); ++i) {
    int pow2 = 1;
    while (pow2 * pow2 <= ans.at(i)) {
      if (pow2 * pow2 == ans.at(i)) {
        cnt++;
        break;
      }
      pow2++;
    }
    // cout << pow2 * pow2  << " " << ans.at(i) << endl;
  }

  cout << cnt << endl;
  return 0;
}


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

using namespace std;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 21;
const int M = 1e6 + 500;

int cnt[N];
int n,a[N],sol = 0;

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%d",a+i);
        cnt[a[i]+1]++;
        cnt[a[i]]++;
        cnt[a[i]+2]++;
    }
    for(int i = 0;i<N;i++){
        sol = max(sol,cnt[i]);
    }
    printf("%d\n",sol);
}


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

int che[10]={1};
int res[11][331];

void dfs(int bit,int sum,int num){
	res[num][sum]++;
	if(num<10){
		for(int i=0,B,S;i<10;i++){
			B=bit;
			S=sum;
			if(!(B&che[i])){
				S+=(num+1)*i;
				B=B|che[i];
				dfs(B,S,num+1);
			}
		}
	}
	
}

int main(){
	for(int i=1;i<10;i++)che[i]=che[i-1]*2;
	dfs(0,0,0);
	for(int n,s;cin>>n>>s;){
		if(s>330)cout<<0<<endl;
		else cout<<res[n][s]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1172
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k=map(int,input().split())
A=list(map(int,input().split()))
dp = [False]*(k+1)
for left in range(k+1):
  for i, ai in enumerate(A):
    if left - ai >= 0:dp[left] |= not dp[left-ai]
print("First"if dp[k] else "Second")

    


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

int read()
{
	int ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10+ch-'0';
	if(flag)ans=-ans;
	return ans;
}

long long rell()
{
	long long ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10ll+(long long)(ch-'0');
	if(flag)ans=-ans;
	return ans;
}

void writ(int n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}

void wrll(long long n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10ll)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}
const int N=1<<18,big=0x3f3f3f3f;
int a[N];
set<int>se;

struct node
{
	int l,r,f;
	pair<int,int> m[3];
}p[N*5];

void dn(int i)
{
	if(p[i].f==-1)return;
	p[i].m[2]=p[i].m[p[i].f];
	if(~p[i].f && p[i].l<p[i].r-1)p[i*2].f=p[i*2+1].f=p[i].f;
	p[i].f=-1;
}

void up(int i)
{
	for(int j=0;j<3;j++)p[i].m[j]=min(p[i*2].m[j],p[i*2+1].m[j]);
}

void build(int i,int l,int r)
{
	int m=(l+r)>>1;
	p[i].l=l;
	p[i].r=r;
	p[i].f=0;
	if(l==r-1)
	{
		p[i].m[l&1]=make_pair(a[l],l);
		p[i].m[(~l)&1]=make_pair(big,0);
		p[i].m[2]=p[i].m[0];
	}
	else
	{
		build(i*2,l,m);
		build(i*2+1,m,r);
		up(i);
	}
	//printf("i=%d %d %d2=%d %d\n",i,l,r,p[i].m[2].first,p[i].m[2].second);
}

void edit(int i,int l,int r)
{
	int m=(p[i].l+p[i].r)>>1;
	dn(i);
	if(l<=p[i].l && r>=p[i].r)
	{
		p[i].m[2]=p[i].m[p[i].f=(~l)&1];
		//printf("i=%d l&1=%d p[i].m[2]=%d %d\n",i,l&1,p[i].m[2].second,p[i].m[2].first);
		return;
	}
	if(l<m)edit(i*2,l,r);
	if(r>m)edit(i*2+1,l,r);
	dn(i*2);
	dn(i*2+1);
	up(i);
	//printf("i=%d l=%d r=%d pl=%d pr=%d pm0=%d pm1=%d pm2=%d\n",i,l,r,p[i].l,p[i].r,p[i].m[0].second,p[i].m[1].second,p[i].m[2].second);
}

pair<int,int> query(int i,int l,int r)
{
	int m=(p[i].l+p[i].r)>>1;
	dn(i);
	if(l<=p[i].l && r>=p[i].r)return p[i].m[2];
	pair<int,int> ans=make_pair(big,0);
	if(l<m)ans=min(ans,query(i*2,l,r));
	if(r>m)ans=min(ans,query(i*2+1,l,r));
	//printf("i=%d ans=%d %d\n",i,ans.first,ans.second);
	return ans;
}

int main()
{
	int n=read();
	for(int i=0;i<n;i++)
	{
		a[i]=read()-1;
	}
	build(1,0,n);
	se.clear();
	se.insert(n);
	for(int i=0;i*2<n;i++)
	{
		int x=p[1].m[2].second;
		int k=*se.lower_bound(x);
		//printf("i=%d x=%d k=%d\n",i,x,k);
		se.insert(x);
		edit(1,x,k);
		//printf("k=%d\n",k);
		int y=query(1,x,k).second;
		se.insert(y);
		edit(1,y,k);
		//printf("x=%d y=%d\n",x,y);
		printf("%d %d ",a[x]+1,a[y]+1);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 57984
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int a;
	cin>>a;
	if(a>=400 && a<=599)	
		cout<<8;
	else if(a>=600 && a<=799)
		cout<<7;
	else if(a>=800 && a<=999)
		cout<<6;
	else if(a>=1000 && a<=1199)
		cout<<5;
	else if(a>=1200 && a<=1399)
		cout<<4;
	else if(a>=1400 && a<=1599)	
		cout<<3;
	else if(a>=1600 && a<=1799)
		cout<<2;
	else
		cout<<1;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int x,a;
    cin>>x>>a;
    if(x<a)
    cout<<"0";
    else
    cout<<"10";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}



int main(){
    ll a[101000];
    ll x[101000];
    fill(x, x+101000, 0);
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    ll res = 1;
    ll zeroNum = 0;
    for(int i = 0; i < N; i++){
        x[a[i]]++;
        if(a[i] == 0){
            zeroNum++;
            continue;
        }
        res = mul(res, x[a[i]-1]);
        if(x[a[i]-1] > 0){
            x[a[i]-1]--;
        }
    }

    if(zeroNum == 1){
        res = mul(res, 3);
    }
    else if(zeroNum == 2 || zeroNum == 3){
        res = mul(res, 6);
    }
    else{
        res = 0;
    }

    cout << res << endl;


    return 0;
}




Measured memory_bytes: 1792
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}




Measured memory_bytes: 3604
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    x1, y1, x2, y2 = map(int, input().split())
    dx = x2 - x1
    dy = y2 - y1

    x3 = x2 - dy
    y3 = y2 + dx
    x4 = x1 - dy
    y4 = y1 + dx

    print(x3, y3, x4, y4)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
S = input()
A = S[0]+S[1]
B = S[2]+S[3]
L = ['01','02','03','04','05','06','07','08','09','10','11','12']
if (A in L) and (B in L):
  print('AMBIGUOUS')
elif A not in L:
  if B not in L:
    print('NA')
  else:
    print('YYMM')
else:
  print('MMYY')

Measured memory_bytes: 3064
n = int(input())
k, m=0, 0
p = []
for i in range(n):
    l = int(input())
    if l > m:
        m = l
        k = i
    p.append(l)
p.remove(p[k])
j = 0
for i in p:
    if i > j:
        j = i
for i in range(n):
    if i == k:
        print(j)
    else:
        print(m)

Measured memory_bytes: 12520
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long int f,n,r,p,s,k,ans = 0;
  string s1;
  cin >> n >> k >> r >> s >> p;
  cin >> s1;
  for (int i =0; i < s1.size(); i++) {
    if (s1[i] == 'r') f = p;
    if (s1[i] == 'p') f = s;
    if (s1[i] == 's') f = r;
    if(i >= k && s1[i-k] == s1[i]){
      f = 0;
      s1[i] = '0';
    }
    ans += f;
  }
    cout << ans << "\n";
   return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll k; cin >> k;
    cout << ((k%2 == 0) ? (k/2*k/2) : (k/2*(k/2+1))) << endl;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var bs []byte
    fmt.Scan(&bs)
    if bs[0] == bs[1] && bs[1] == bs[2] || bs[1] == bs[2] && bs[1] == bs[3] {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }       
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc165/tasks/abc165_f
// 木 + 最長増加部分列
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "

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

#define MAX_N 200005
int n;
int a[MAX_N];
vector<int> edge[MAX_N];
int lis[MAX_N]; // longest increasing sequence
const int INF = 1e9;
int dp[MAX_N];

void dfs(int i,int from=-1){
	int pos = lower_bound(dp, dp + n, a[i])-dp; //dp[pos-1]<a[i]<dp[pos]
	int tmp = dp[pos];
	dp[pos] = a[i];
	lis[i] = pos+1;
	if(from!=-1)lis[i] = max(lis[i],lis[from]);
	rep(j,edge[i].size()){
		if(edge[i][j]==from)continue;
		dfs(edge[i][j],i);
	}
	dp[pos]=tmp;
}

int main() {
	cin >> n;
	rep(i,n)cin >> a[i];
	rep(i,n-1){
		int b,c;
		cin >> b >> c;
		b--;c--;
		edge[b].push_back(c);
		edge[c].push_back(b);
	}
	rep(i,n)dp[i]=INF;
	dfs(0);
	rep(i,n)outl(lis[i]);
    return 0;
}



Measured memory_bytes: 31080
var
 ans,i,max,a,k,t:longint;
begin
 read(k);
 readln(t);
 for i := 1 to t do
  begin
   read(a);
   if max<a then max:=a;
  end;
 ans:=(max-(k-max)-1);
 if 0<ans then writeln(ans)
          else writeln(0);
end.

Measured memory_bytes: 128