akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

int n,D1,D2,id[650][650],col[400000][3];

vector <pair <int,int>> d[3];

inline void dfs(int u,int c)
{
	int x=(u-1)/(2*n)+1,y=(u-1)%(2*n)+1;
	//cout << x << " " << y << endl;
	for (int i=0;i<d[c].size();i++)
	{
		pair <int,int> rhs=d[c][i];
		int nx=x+rhs.first,ny=y+rhs.second;
		if (nx>=1 && nx<=2*n && ny>=1 && ny<=2*n)
		{
			int rid=id[nx][ny];
			if (!col[rid][c])
			{
				col[rid][c]=col[u][c]==1?2:1;
				dfs(rid,c);
			}
		}
	}
}

int main()
{
	n=read(),D1=read(),D2=read();
	for (int i=0;i<=D1;i++)
	{
		int j=sqrt(D1-i*i);
		if (i*i+j*j==D1)
		{
			d[1].push_back({i,j});
			d[1].push_back({-i,j});
			d[1].push_back({i,-j});
			d[1].push_back({-i,-j});
			//if (i!=0)
			//	break;
		}
	}
	for (int i=0;i<=D2;i++)
	{
		int j=sqrt(D2-i*i);
		if (i*i+j*j==D2)
		{
			d[2].push_back({i,j});
			d[2].push_back({-i,j});
			d[2].push_back({i,-j});
			d[2].push_back({-i,-j});
			//if (i!=0)
			//	break;
		}
	}
	for (int i=1;i<=n*2;i++)
	{
		for (int j=1;j<=n*2;j++)
			id[i][j]=(i-1)*2*n+j;
	}
	for (int i=1;i<=n*2;i++)
	{
		for (int j=1;j<=n*2;j++)
		{
			int rhs=id[i][j];
			if (!col[rhs][1])
			{
				col[rhs][1]=1;
				dfs(rhs,1);
			}
			if (!col[rhs][2])
			{
				col[rhs][2]=1;
				dfs(rhs,2);
			}
		}
	}
	int cnt=0;
	for (int i=1;i<=n*2;i++)
	{
		for (int j=1;j<=n*2;j++)
		{
			int rid=id[i][j];
			if (col[rid][1]==1 && col[rid][2]==1)
			{
				cout << i-1 << " " << j-1 << endl;
				cnt++;
			}
			if (cnt==n*n)
				return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 19328
#include<stdio.h>
int n,A[20+1];
int Exhaustive(int i,int key){
    int a;
    if(key==0)return 1;
    if(i>=n)return 0;

    if(Exhaustive(i+1,key)){
        a=1;
        //a=Exhaustive(i+1,key);
    }else if(Exhaustive(i+1,key-A[i])){
        a=1;
        //a=Exhaustive(i+1,key-A[i]);
    }else return 0;
    return a;
}
int main(){
    int q,m;
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&m);
        if(Exhaustive(0,m)){
        printf("yes\n");
        }else printf("no\n");
     }
    return 0;
}


Measured memory_bytes: 2104
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int N, X, T;
	cin>>N>>X>>T;
	ll ans = (N/X)*T + (N%X == 0 ? 0 : T);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)

using namespace std;

ll r = 0LL;

bool vale(ll num)
{
    bitset < 10 > f;

    while(num)
    {
        f[num % 10] = true;

        num /= 10;
    }

    return (f[3] && f[5] && f[7]);
}

void rec(ll n, ll v)
{
    r += ((v > 100) && (v <= n) && vale(v));

    if(v >= n)
        return;

    rec(n, ((v * 10) + 3));
    rec(n, ((v * 10) + 5));
    rec(n, ((v * 10) + 7));
}

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

    ll n;

    cin >> n;

    rec(n, 0);

    cout << r << "\n";

    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = []

for i in range(n):
    l.append(int(input()))

def has_duplicates(seq):
    return sorted(seq)[len(seq)-1] == sorted(seq)[len(seq)-2]

x = max(l)

if has_duplicates(l):
    for i in l:
        print(x)
else:
    for i in l:
        if i != x:
            print(x)
        else:
            print(sorted(l)[n-2])

Measured memory_bytes: 19212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n,m;
  cin>>n>>m;
  vector<int>l(m),r(m);
  rep(i,m) cin>>l[i]>>r[i];
  sort(rall(l));
  sort(all(r));
  int ans=r[0]-l[0]+1;
  if(ans<0)
    cout<<0<<endl;
  else
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  string str1,str2;
  cin>>str1;
  cin>>str2;
  int flag=1;
  for(int i=0;i<3;i++){
    if(str1[i]!=str2[2-i])
      flag=0;
  }
  if(flag)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
inline int read()
{
    int s=0,w=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch<='9'&&ch>='0')s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    return s*w;
}
int a[100010]={};
int top=0;
int ans=0;
bool cmp(int x,int y){return x<y;}
int main()
{
    n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    sort(a+1,a+n+1,cmp);
    // for(int i=1;i<=n;++i)printf("%d ",a[i]);
    // puts("");
    for(int i=1;i<=n;++i)
    {
        int x=a[i];
        for(int j=i-1;j>=1;--j)
         {
            for(int k=i+1;k<=n;++k)
              if(a[j]+x>a[k])
              {
                      ++ans;
              }
              else break;
         }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
using System;

namespace _1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] r = new int[n];
            for(int i=0;i<n;i++)
            {
                r[i] = int.Parse(Console.ReadLine());
            }
            int minv = r[0];
            int maxv = r[1] - r[0];
            for(int i=1;i<n;i++)
            {
                if(maxv<r[i]-minv)
                {
                    maxv = r[i] - minv;
                }
                if(minv>r[i])
                {
                    minv = r[i];
                }
            }
            Console.WriteLine(maxv);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10876
#include<iostream>
#include<cstring>

using namespace std;
const int INF=1e9;

int d, g, p[12], c[12];

int main(){
    int mn=INF;
    cin >> d >> g;
    g/=100;
    for(int i=1;i<=d;i++){
        cin >> p[i] >> c[i];
        c[i]/=100;
    }
    for(int i=0;i<1<<d;i++){
        int tmp = g, cnt=0;
        for(int j=0;j<d;j++){
            if(i&(1<<j)){
                tmp-=p[j+1]*(j+1)+c[j+1];
                cnt+= p[j+1];
            }
        }
        if(tmp<=0){
            mn = min(mn, cnt);
            continue;
        }
        for(int j=d-1;j>=0;j--){
            if(~i&(1<<j)){
                if(p[j+1]*(j+1)>=tmp){
                    cnt += tmp/(j+1);
                    if(tmp%(j+1)!=0)cnt++;
                    mn = min(mn, cnt);
                }
                break;
            }
        }
    }
    cout << mn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int d,n;
	cin>>d>>n;
	if(d==2){
	long long ans=n*pow(100,d);
	if(n!=100)
	cout<<ans;
	else
	cout<<ans+10000;
	}
	else if(d==1){
		if(n!=100){
			cout<<n*100;
		}
		else
		cout<<n*100+100;
	}
	else if(d==0){
		if(n<100){
			cout<<n;
		}
		else
		cout<<101;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<random>
#include<stdio.h>
using namespace std;

typedef long long int ll;


#define INF 1e+9
#define MAX_V 300

struct edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

ll V;
ll L;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF*(L+1)+L);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll cost=p.first;
        ll v = p.second;
        if (d[v] < cost) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            ll a=d[e.to];
            ll nokori=L-cost%(L+1);
            ll n;
            if (nokori>=e.cost){
                n=cost+e.cost;
            }
            else{
                n=(cost/(L+1)+1)*(L+1)+e.cost;
            }
            if (d[e.to] > n) {
                d[e.to] = n;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    cin>>V;
    ll E;
    cin>>E;
    cin>>L;
    for (int i=0;i<E;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        if (L>=c){
            edge e={b-1,c};
            edge f={a-1,c};
            G[a-1].push_back(e);
            G[b-1].push_back(f);
        }
    }
    vector<vector<ll>> ans(V,vector<ll>(V));
    for (ll i=0;i<V;i++){
        fill(d, d+V, INF*(L+1)+L);
        dijkstra(i);
        for (ll j=0;j<V;j++){
            ans[i][j]=d[j];
        }
    }
    ll Q;
    cin>>Q;
    for (ll i=0;i<Q;i++){
        ll s,t;
        cin>>s>>t;
        ll test=ans[s-1][t-1];
        if (test!=INF*(L+1)+L){
            cout<<test/(L+1)<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
 
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
 
int n;
string s;
 
signed main(){
  cin>>s;
  int a=(s[0]-'0')*10+(s[1]-'0');
  int b=(s[2]-'0')*10+(s[3]-'0');

  if(!a && !b)cout<<"NA"<<endl;
  else if(!a && b&&b<=12)cout<<"YYMM"<<endl;
  else if( a &&a<=12 && !b)cout<<"MMYY"<<endl;
  else if(!a && b>12)cout<<"NA"<<endl;
  else if(a>12 && !b)cout<<"NA"<<endl;
  else if(a>12 && b>12)cout<<"NA"<<endl;
  else if(a<=12 && b<=12)cout<<"AMBIGUOUS"<<endl;
  else if(a<=12)cout<<"MMYY"<<endl;
  else cout<<"YYMM"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String b = sc.nextLine();
    
    switch (b) {
      case "A":
        System.out.println('T');
        break;
      case "C":
        System.out.println('G');
        break;
      case "T":
        System.out.println('A');
        break;
      case "G":
        System.out.println('C');
        break;
    }
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	string S; cin >> S;
	S[3] = '8';
	cout << S << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vi p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    sort(rall(p));
    sort(rall(q));
    vi s;
    rep(i, x) s.push_back(p[i]);
    rep(i, y) s.push_back(q[i]);
    rep(i, c) s.push_back(r[i]);
    sort(rall(s));
    ll ans = 0;
    rep(i, x+y) ans += s[i];
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N = 5;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (X.at(i) == 0) return cout << i + 1 << "\n", 0;
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
bool bo[9];
int n,m;
int a[30],b[30];
int d[9][9];
int dfs(int s,int c){
  if(bo[s])return 0;
  if(c==n)return 1;
  
  bo[s]=true;
  int ret=0;
  for(int i=1;i<=n;i++){
    if(d[s][i]==1){
      ret+=dfs(i,c+1);
    }
  }
  bo[s]=false;
  return ret;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<9;i++)for(int j=0;j<9;j++)d[i][j]=0;
  for(int i=0;i<9;i++)bo[i]=false;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    d[a[i]][b[i]]=1;
    d[b[i]][a[i]]=1;
  }
  cout<<dfs(1,1)<<endl;
}
  
  

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

signed main() {
  ios::sync_with_stdio(false);
  int n, k;
  string s;
  cin >> n >> k >> s;
  vector<ll> lft;
  vector<ll> lft1;
  if(s[0] == '0') {
    lft.push_back(0);
  }
  lft1.push_back(0);
  REP_FROM(i, 1, n) {
    if(s[i] == '0' && s[i-1] == '1') {
      lft.push_back(i);
    }
    if(s[i] == '1' && s[i-1] == '0') {
      lft1.push_back(i);
    }
  }
  lft.push_back(n);
  if(lft.size() <= k) {
    cout << n << endl; 
    return 0;
  }
  ll ans = 0;
  REP(i, lft.size() - k) {
    ans = max(ans, lft[i+k] - lft1[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1372
'use strict';
(function(stdin) {
  var inputs  = stdin.toString();
  var S = parseInt(inputs.split('\n')[0],10);
  var h = Math.floor(S/3600);
  var s = S%60;
  var m = Math.floor(S%3600/60);
  console.log(h+':'+m+':'+s); 
  
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b, c, x, y = na()

ans = 0
while x or y:
    if x and y:
        if a + b > c * 2:
            x -= 1
            y -= 1
            ans += c * 2
        else:
            x -= 1
            y -= 1
            ans += a + b
    else:
        q = c * 2 * (x + y)
        if q <= a * x + b * y:
            ans += c * 2 * (x + y)
            x = 0
            y = 0
        if x:
            ans += a * x
            x = 0
        if y:
            ans += b * y
            y = 0

print(ans)

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int A, B;
  cin >> A >> B;
  if (B == 1)
    cout << 0 << endl;
  else if (A >= B)
    cout << 1 << endl;
  else
  {
    int ans = 0;
    int num = 1;
    while (num < B)
    {
      num += A - 1;
      ans++;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>//???????§????????????????
//???????????????????????????????????°?????? G=(V,E) ???????????????
//???????§????????????????????????????????±???????????????°????????????????????????????????????
//G ????????? 0 ????§??????¨??????0 ??????????????? v ???????????????
//??????????????????????????????????????? d[v] ?????????????????????????????? 
#define N 2000
#define A 101
#define NIL -1

void Prim();

static const int MAX=500;
static const int INFTY=(1<<21);

int M[A][A], p[A], S[A], d[A], n;

main(){
  int i, j, u, k, v, c;
  scanf("%d", &n);  //??????????????? G ???????????° n ????????????????????????
                    //?¶???? n ?????§????????? u ?????£??\??????????????\????????¢?????§????????????????????? 
  for (i=0; i<n; i++)
    for (j=0; j<n; j++){
      M[i][j]=INFTY;
    }
  
  for (i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    for (j=0; j<k; j++){
      scanf("%d %d", &v, &c);
      M[u][v]=c;
    }
  }
  Prim();       //?????????????????? v ??¨?????¢ d[v] ?????????????????????????????§???????????????????????????????????? 
  for (i=0; i<n; i++) printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  
  return 0;
}

void Prim(){
  int i, v, u, k[A];
  for(u=0;u<n;u++){
    k[u]=INFTY;
    p[u]=NIL;
    d[u]=INFTY;
  }
  
  k[0]=0;
  
  while(1){
    int minv=INFTY;
    u=NIL;
    for(i=0; i<n; i++)
      if(k[i]<minv && p[i]==NIL){
	u=i;
	minv=k[i];
      }
    
    if(u==NIL) break;
    p[u]=1;
    d[u]=k[u];
    for(v=0;v<n;v++) if(p[v]!=1 && k[u]+M[u][v]<k[v]) k[v]=k[u]+M[u][v];
  }
}

Measured memory_bytes: 640
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
cin >> s;
ll n = s.size();
ll cnt_s = 0;
ll cnt_t = 0;
rep(i,n){
    if(s[i] == 'S')
        cnt_s++;
    if(s[i] == 'T' && cnt_t < cnt_s)
        cnt_t++;
}
cout << n - min(cnt_s,cnt_t) * 2 << endl;
}

Measured memory_bytes: 720
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  (x, a, b) <- getInput
  print $ solve x a b

getInput :: IO (Int, Int, Int)
getInput = do
  x <- readLn
  a <- readLn
  b <- readLn
  return (x, a, b)

solve :: Int -> Int -> Int -> Int
solve x a b = (x - a) `mod` b


Measured memory_bytes: 508
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void put_str(char *str) { while(*str) putchar_unlocked(*str++); }

typedef struct MaxHeap {
    int A[2000001];
    size_t len;
} MaxHeap;
void maxheap_init(MaxHeap *H) { H->len = 0; }
void maxheap(MaxHeap *H, const int i) {
    const size_t N = H->len;
    int l = i * 2;
    int r = i * 2 + 1;
    int max = i;
    if(l <= N && H->A[l] > H->A[max]) max = l;
    if(r <= N && H->A[r] > H->A[max]) max = r;
    if(max != i) {
        int tmp = H->A[i];
        H->A[i] = H->A[max];
        H->A[max] = tmp;
        maxheap(H, max);
    }
}
void maxheap_insert(MaxHeap *H, int key) {
    size_t i = ++H->len;
    H->A[i] = key;
    while(i > 1 && H->A[i / 2] < H->A[i]) {
        int tmp = H->A[i/2];
        H->A[i/2] = H->A[i];
        H->A[i] = tmp;
        i /= 2;
    }
}
int maxheap_pop(MaxHeap *H) {
    if(!H->len) return -1;
    int max = H->A[1];
    H->A[1] = H->A[H->len--];
    maxheap(H, 1);
    return max;
}
int main(int argc, char **argv) {
    int key;
    char c[8];
    MaxHeap H;
    maxheap_init(&H);
    while(1) {
        get_str(c);
        if(*c == 'e') {
            if(c[1] == 'n') break;
            put_uint(maxheap_pop(&H));
            putchar_unlocked('\n');
        } else {
            key = get_uint();
            maxheap_insert(&H, key);
        }
    }
    return 0;
}



Measured memory_bytes: 5356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
    static void Main(string[] args) {
        //入力
        string s = Console.ReadLine();
        int r = int.Parse(s.Split(' ')[0]);
        int D = int.Parse(s.Split(' ')[1]);
        int X2000 = int.Parse(s.Split(' ')[2]);

        //現在の数
        int X_newest = X2000;

        //for文で回す
        for (int i = 0; i < 10; i++) {
            X_newest = r * X_newest - D;
            Console.WriteLine(X_newest);
        }
    }
}

Measured memory_bytes: 11092
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 998244353
#define ciN cin
#define X INT_MAX
#define N INT_MIN
////////////////////////////////////////////////////////////////

void jabru() {
	string s; cin >> s;
	int x = s.size();

	cout << s;
	if (s[x - 1] != 's') {
		cout << 's';
	}
	else
		cout << "es";
	cout << endl;
}

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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	t = 1;

	//cin >> t;
	while (t--)
		jabru();


	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???


Measured memory_bytes: 3664
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll a,b,c,x,y;

  cin >> a >> b >> c >> x >> y;

  ll ab_val = a * x + b * y;

  ll c_val = 0;

  if(x > y)
  {
    ll buf = x - y;
    c_val = 2 * y * c + buf * a;
  }
  else
  {
    ll buf = y - x;
    c_val = 2 *x * c + buf * b;
  }

  ll cc_val = max(x,y) * c * 2;

  ll ans = min(cc_val,min(c_val,ab_val));

  cout << ans << endl; 


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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(){

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

	int N; cin >> N;
	vector<vector<int>> D(N, vector<int>(2,0));
	rep(i,N){
		cin >> D[i][0] >> D[i][1];
	}

	int count = 0;
	bool ans = false;
	rep(i,N){
		if (D[i][0] == D[i][1]){
			count++;
		}
		else{
			count = 0;
		}
		if (count >= 3){
			ans = true;
		}
	}

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3660
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
  if a[i] >= b[i]:
    ans += b[i]
  else:
    if a[i] + a[i+1] <= b[i]:
      ans += a[i] + a[i+1]
      a[i+1] = 0
    else:
      ans += b[i]
      a[i+1] -= b[i] - a[i]
print(ans)

Measured memory_bytes: 19116
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll D;
    cin >> D; //=365
    vec c(26);
    loop(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    loop(i, D)
    {
        loop(j, 26) cin >> s[i][j];
    }
    vec t(D);
    loop(i, D) cin >> t[i];
    //score計算
    ll score = 0;
    vector<ll> before(26); //直近で何日前に開催したか？
    loop(i, D)
    {
        score += s[i][t[i] - 1];
        before[t[i] - 1] = i + 1; //リセット
        //スコア減点
        loop(j, 26)
        {
            score -= c[j] * ((i + 1) - before[j]);
        }
        putout(score);
    }
    return 0;
}


Measured memory_bytes: 3736
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int n, k;

int dfs(int x, int p){
    int sum = 0;
    
    bool f1 = false, f2 = false, f3 = false;
    for(int i = x; i > 0; i /= 10){
        if(i % 10 == 3){
            f1 = true;
        }
        else if(i % 10 == 5){
            f2 = true;
        }
        else if(i % 10 == 7){
            f3 = true;
        }
    }
    if(f1 && f2 && f3){
        sum = 1;
    }
    
    if(p == k){
        if(x > n) sum = 0;
        return sum;
    }
    
    sum += dfs(x * 10 + 3, p + 1) + dfs(x * 10 + 5, p + 1) + dfs(x * 10 + 7, p + 1);
    return sum;
}

int main() {
    string s;
    cin >> s;
    n = stoi(s);
    k = s.size();
    cout << dfs(0, 0) << endl;
}


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

const long long INF = 1e18+9;

int main(){
    int n,w;
    cin>>n>>w;
    
    int arr[n][2];
    int sum = 0;
    for(int i=0;i<n;i++){
        cin>>arr[i][0];
        cin>>arr[i][1];
        sum+=arr[i][1];
    }
    
    vector<long long> dp(sum+1, INF);
    dp[0]=0;
    for(int i=n-1;i>=0;i--){
        for(int j=sum;j>=0;j--){
            if(j-arr[i][1]>=0){
                dp[j]=min(dp[j-arr[i][1]]+arr[i][0], dp[j]);
            }
        }
    }
    
    for(int i=sum;i>=0;i--){
        if(dp[i]<=w){
            cout<<i;
            return 0;
        }
    }
}

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

using namespace std;

int main(void) {
    string s;
    cin >> s;
    bool ans = true;
    if (s.length() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < s.length(); i++) {
        ans &= (i % 2 == 0 && s[i] == 'h') || (i % 2 == 1 && s[i] == 'i');
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)

int main()
{
    int n,t,x;
    long long sum = 0;
    scanf("%d %d",&n,&t);
    for(int i = 0;i<t;i++){
        cin>>x;
        sum+=x;
    }
    if(sum>n)cout<<-1<<endl;
    else cout<<n-sum<<endl;
	return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int A, B;
    cin >> A >> B;
    string s;
    int count = 0;
    bool f = true;
    for (int i = A; i <= B; i++)
    {
        s = to_string(i);
        for (int j = 0; j < s.length(); j++)
        {
            if (s[j] != s[s.length() - 1 - j])
            {
                f = false;
            }
        }
        if (f == true)
        {
            count++;
        }
        else
        {
            f = true;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
p = 0
q = W
r = 0
s = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    p = max(p, x)
  elif a == 2:
    q = min(q, x)
  elif a == 3:
    r = max(r, y)
  else:
    s = min(s, y)
print(max(q - p, 0) * max(s - r, 0))

Measured memory_bytes: 62468
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

// int main(int argc, char *argv[]){
//     int n;
//     string s;
//     cin >> n >> s;
//     int m = INF;
//     int sum[330000];
//     rep(i, n){
//         int cnt = 0;
//         rep(j, n){
//             if(i == j) continue;
//             if(s[i] != s[j]) cnt++;
//         }
//         m = min(m, cnt);
//     }
//     cout << m << endl;
//     return 0;
// }
int n;
string s;
ll sum[303030];
 
int main() {
    cin >> n >> s;
    rep(i, n) {
        if (i) {
            sum[i] = sum[i - 1] + (s[i] == 'E');
        }
        else {
            if (s[i] == 'E')sum[i] = 1;
        }
    }
    sum[n] = sum[n - 1];
    ll ans = INF;
    rep(i, n) {
        if (i == 0) {
            ans = min(ans, sum[n] - sum[i]);
        }
        else {
            ans = min(ans, i - sum[i - 1] + sum[n] - sum[i]);
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;

const int N = 55;

int n, A;
int a[N];

ll mem[N][N][N * N];

ll dp(int i, int cnt, int sum) {
	if (i == n) {
		if (cnt == 0)return 0;

		if ((sum / cnt == A) && (sum % cnt == 0))return 1;
		return 0;
	}

	ll& ret = mem[i][cnt][sum];
	if (ret != -1)return ret;

	return ret = dp(i + 1, cnt, sum) + dp(i + 1, cnt + 1, sum + a[i]);
}

int main() {
	cin >> n >> A;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	memset(mem, -1, sizeof mem);

	cout << dp(0, 0, 0) << endl;

	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

LL MOD=1000000007;

int main()
{
    LL n,c,k;
    cin>>n>>c>>k;
    vector<LL> t(n);
    REP(i,n)
        cin>>t[i];
    
    sort(ALL(t));
    LL ans=0;
    LL cnt=0,tim=-1;

    if(c==1)
    {
        cout<<n<<endl;
        return 0;
    }

    REP(i,n)
    {
        if(cnt==0)
        {
            tim=t[i]+k;
            cnt++;
            ans++;
        }
        else
        {
            if(t[i]<=tim)
            {
                cnt++;
                if(cnt>=c)
                {
                    cnt=0;
                }
            }
            else
            {
                cnt=1;
                tim=t[i]+k;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 1024
import math

def main():
    N,D=map(int,input().split())
    res=0
    for i in range(N):
        x,y=map(int,input().split())
        if math.sqrt(pow(x,2)+pow(y,2))<=D:
            res+=1
    print(res)
if __name__=="__main__":
    main()

Measured memory_bytes: 70004
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll N,K;cin>>N>>K;
    ll sum=0;
    vector<vector<ll>>a(N,vector<ll>(2));
    rep(i,N)cin>>a[i][0]>>a[i][1];
    sort(a.begin(),a.end());
    rep(i,N){
        sum+=a[i][1];
        if(sum>=K){
            cout<<a[i][0]<<endl;
            return 0;
        }
    }

}


Measured memory_bytes: 5760
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

()
|> readIntArray
|> fun [| a; b; k |] ->
    seq { 100 .. -1 .. 1 }
    |> Seq.filter (fun x -> a % x = 0 && b % x = 0)
    |> Seq.take k
    |> Seq.rev
    |> Seq.head
|> printfn "%d"


Measured memory_bytes: 29936
N=int(input())
*V,=map(int,input().split())

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>V2:
    if K1==K2:
        V2=C2[-2][1]
elif V2>V1:
    if K1==K2:
        V1=C1[-2][1]
else:
    if K1==K2:
        if len(set(V))==1:
            V2=0
        else:
            V2=max(C1[-2][1],C2[-2][1])

print(N-V1-V2)

Measured memory_bytes: 25272
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
typedef long long int lld;
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define Error(x) cout<< #x << " = " << (x) <<endl;
#define Error2(a,b) cout<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cout<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll
 
typedef pair<lld,lld> PA;
 
lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}
 
bool bitSet(lld n,lld i){
    if((n&(1LL<<i))!=0) return true;
    else return false;
}
 
lld findGcd(lld a,lld b){
    if(a==0) return b;
    else return findGcd(b%a,a);
}
 
#define lim 500010
#define lim2 200003
#define qqqqqq 210
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];
// vector<lld> V[lim];
// int X[lim],Y[lim],C[lim];
// string S[lim];
lld A[lim],B[lim];
// map<lld,lld> M;

int main(){
    lld T,i,n,m,p,j,l,e,r,b,c,k,q,a,d,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,indicator;
    sc2(n,p);
    a = b = 0;
    rep(i,1,n){
        sc(k);
        if(k&1) a++;
        else b++;
    }
    ans = 1LL<<b;
    if(a==0){
        ans *= (p==0);
    }
    else ans *= 1LL<<(a-1);
    prL(ans);
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
n,x=map(int,input().split())
l=[0]*(n+1)
c=[0]*(n+1)
c[0]=l[0]=1
for i in range(1,n+1):
  l[i]=l[i-1]*2+3
  c[i]=c[i-1]*2+1
def check(r,t):
  if r==0 and t>0:
    return 1
  elif r==0:
    return 0
  elif t<=l[r-1]+1:
    return check(r-1,t-1)
  else:
    return check(r-1,t-l[r-1]-2)+c[r-1]+1
print(check(n,x))

Measured memory_bytes: 3064
while True:
    try:
        a=list(map(int, input().split()))
        #print("a",a)
        b=list(map(int, input().split()))
        #print("b",b)
        hit=0
        blow=0
        for i in range(len(b)):
            if b[i] in a:
                if b[i]==a[i]:
                    hit+=1
                else:
                    blow+=1
        print(hit,blow,)
    except:
        break




Measured memory_bytes: 5596
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    print(sum(1 for i in range(len(S)-1) if S[i] != S[i+1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 73280
import sys
import heapq
import copy
import numpy as np
from collections import deque

n=int(input())
x=list(map(int,input().split()))

cnt=10**10

for p in range(min(x),max(x)+1):
    curcnt=0
    for xx in x:
        curcnt+=(xx-p)**2
    cnt=min(cnt,curcnt)
print(cnt)

Measured memory_bytes: 21648
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;int k;cin>>n>>k;
    if (n.size()<k) {
        cout << 0 << endl;
        return 0;
    }
    if (n=="10"&&k==2 || n.size()==3&&stoi(n)<=110&&k==3) {
        cout << 0 << endl;
        return 0;
    }
    ll ns = n.size();
    ll cur = 0;
    ll res = 0;
    while(k>0&&cur<ns) {
        if (n[cur]=='0') {
            cur++;
            continue;
        }
        ll digit = n[cur]-'0', rem=ns-1-cur;
        if (k==3) {
            res += (digit-1) * 9*9*rem*(rem-1)/2;
            res += 9*9*9*rem*(rem-1)*(rem-2)/6;
        }
        else if(k==2) {
            res += (digit-1) * rem * 9;
            res += 9*9*rem*(rem-1)/2;
        }
        else {
            res += digit;
            res += 9*rem;
        }
        k--;
        cur++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 
int main(void){
  int n,k,i,j,tmp;
  scanf("%d%d",&n,&k);
  int p[n],sum=0;
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(p[i]>p[j]){
        tmp=p[i];
        p[i]=p[j];
        p[j]=tmp;
      }
    }
  }
  for(i=0;i<k;i++)
    sum+=p[i];
  printf("%d",sum);
  return 0;
}

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


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

    int N,M;
    cin >> N >> M;
    int A[M];
    rep(i,M) cin >> A[i];
    int ans=0;
    int sum=0;
    rep(i,M) sum+=A[i];
    if(N<sum) ans=-1;
    else ans=N-sum;
    cout << ans<< endl;


}

Measured memory_bytes: 3696
#include <iostream>
#include <string.h>
using namespace std;

int n, wt;
int v[100], w[100];
int a[101][10001];

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

	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];

	memset(a, 0, sizeof(a));

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= wt; j++) {
			a[i][j] = a[i - 1][j];
			if (j >= w[i - 1]) {
				if (a[i - 1][j - w[i - 1]] + v[i - 1] > a[i][j])
					a[i][j] = a[i - 1][j - w[i - 1]] + v[i - 1];
			}
		}
	}

	cout << a[n][wt] << endl;

	return 0;
}


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

int digitSum(int n){
  if(n==n%10){
    return n;
  }
  else{
    return digitSum(n/10)+n%10;
  }
}
int main(){
  
  int n;
  cin >>n;
  int dsum=digitSum(n);
  if(n%dsum==0)puts("Yes");
  else puts("No");
  
  return 0;
}

Measured memory_bytes: 256
N, K=map(int, input().split())
S=input()
A=[]
tmp=1
for i in range(1,N):
    if S[i-1]==S[i]:
        tmp+=1
    else:
        A.append(tmp)
        tmp=1
A.append(tmp)
 
ans=sum(A)-len(A)+(K)*2
 
if ans<N-1:
    print(ans)
else: print(N-1)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,m,Mx,p,ans,F[MAXN],Sum[MAXN];char s[MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),scanf("%s",s+1),Mx=m,p=m+1;
	Rep(i,1,m)if(s[i]!=s[1]){Mx=i-1,p=i;break;}
	if(Mx==m){
		F[0]=Sum[0]=ans=1;
		Rep(i,0,n)(i>=2?F[i]=Sum[i-2]:0),(i?Sum[i]=(Sum[i-1]+F[i])%Mod:0),(n-i>=2?ans=(ans+1ll*F[i]*(n-i))%Mod:0);
		cout<<ans<<'\n';return 0;
	}if(n&1)return puts("0"),0;if(!(Mx&1))Mx++;
	for(int t=0,i=p;i<=m;i++)if(s[i]==s[1])t++;else (t&1?Mx=min(Mx,t):0),t=0;
	n/=2,Mx=(Mx+1)/2,F[0]=Sum[0]=1;
	Rep(i,0,n){
		if(i)F[i]=(Sum[i-1]-(i-Mx-1>=0?Sum[i-Mx-1]:0)+Mod)%Mod,Sum[i]=(Sum[i-1]+F[i])%Mod;
		if(n-i<=Mx)ans=(ans+1ll*F[i]*(n-i)*2)%Mod;
	}cout<<ans<<'\n';
	return 0;
}




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

ll w[105], v[105], dp[100005];
ll n,k;

ll solve(ll n, ll k)
{
    for(int i=1; i<=n; i++)
    {
        for(int j=k; j>=w[i]; j--)
        {
            dp[j]=max(dp[j], dp[j-w[i]]+v[i]);
        }
    }
    return dp[k];
}

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

    for(int i=1; i<=n; i++)
        cin>>w[i]>>v[i];

    cout<< solve(n,k) <<endl;
}


Measured memory_bytes: 4352