akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n, x, y; cin >> n>> x>> y;
        map<int, int> mp;
        for (int i= 1; i< n; i++) {
                for (int j= i+ 1; j<= n; j++) {
                        if (j- i== 1) mp[1]++;
                        else {
                                int f= j- i;
                                int s= abs(x- i) + 1+ abs(y- j);
                                int t= abs(y- i)+ 1+ abs(x- j);
                                mp[min(f, min(s, t))]++;
                        }
                }
        }
        for (int i= 1; i< n; i++) {
                cout << mp[i]<< "\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}




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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

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

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}



int main()
{
    fast;
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
			ll n,a;
			cin>>n>>a;
			ll sum=0;
			for(int i=0;i<a;i++){
				ll k;
				cin>>k;
				sum+=k;
			}
			if(sum>=n)
				cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
    }
    return 0;
}


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


int main() {
	int A = 0;
	int B = 0;

	std::cin >> A;
	std::cin >> B;

	if ((B % A) == 0) {
		std::cout << A + B << std::endl;
	}
	else {
		std::cout << B - A << std::endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            int h = scanner.nextInt();
            int w = scanner.nextInt();
            if (h == 0 && w == 0) break;
            StringBuilder outW = new StringBuilder();
            for(int a = 0; a < w; a++){
                outW.append("#");
            }
            for(int a = 0; a < h; a++) {
                System.out.println(outW);
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 27568
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
long long gcd(long long a,long long b){
  if(b == 0) return a;
  return gcd(b,a%b);
}

long long lcm(long long a,long long b){
  long long g = gcd(a,b);
  return a/g*b;
}

int main(){
  
  long long int a,b,c,d;
  cin >>a >> b;
  
  if(a%2019 == 0){
    cout << '0' << endl;
    
    return 0;
  }
  c = 1e9;
  
  if(b-a < 2019){
    for(long long int i=a;i<b;i++){
      for(long long int j = i+1;j<=b;j++){
      c = min(c,i*j%2019);
    }
  }
    cout << c << endl;
  }
  
 else if(b-a >=2019){
    

  cout << "0" << endl;
  
}
}
  
    


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    int n, r;
 int tmp[64];
 int p, c;
    while(1){
      scanf("%d %d", &n, &r);
      if(!n && !r)
      break;
        int card[64];
        int i;
 
        for (i = 0; i < n; i++){
            card[i] = n-i; 
        }
 
        while (r-- > 0){
            //int p, c;
            //int tmp[64];
 
            scanf("%d %d", &p, &c);
            for (i = p - 1; i < p + c - 1; i++){               
                tmp[i - p + 1] = card[i];
            }
            for (i = p - 1 + c - 1; i-c+1 > 0 ; i--){ 
                card[i] = card[i - c];
            }
            int j = 0;
            for (i = 0; i < c; i++){
                card[i] = tmp[j];
                j++;
            }
        }
 
        printf("%d\n", card[0]);
    
    }
    return 0;
}

Measured memory_bytes: 600
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [None]*(n-k)
for i in range(n-k):
    if a[i]<a[k+i]:
        ans[i] = "Yes"
    else:
        ans[i] = "No"
write("\n".join(map(str, ans)))

Measured memory_bytes: 107304
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(void) {
	string a;
	while (cin >> a && a != "0") {
		int sum = 0;
		for (int i = 0; i < a.length(); i++) {
			sum += a[i] - '0';
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3180
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

#define ll long long
const ll MAXN= 105;
const int INF=0x7fffffff;

int a[MAXN*MAXN]; 

int h,w;

int main()
{
	
	cin>>h>>w;
	int n,x,cnt=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		while(x--){
			a[cnt++]=i;
		}
	}
	int row=1;
	int left=1,right=w;
	while(row<=h){
		for(int i=left;i<=right;i++){//从左往右输出 
			cout<<a[i]<<" ";
		}
		cout<<endl;
		row++;
		left+=w;
		right+=w;
		if(row>h)
			break;
		for(int i=right;i>=left;i--){
			cout<<a[i]<<" ";
		} 
		cout<<endl;
		row++;
		left+=w,right+=w;
	}
    return 0;
}


Measured memory_bytes: 384
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
[N,M] = inpl()
bulblist = [None]*M
for i in range(M):
    temp = inpl()
    k = temp[0]
    bulblist[i] = temp[1:]

plist = inpl()

for bit in range(1<<N):
    flag = 1
    for i in range(M):
        numon = 0
        for l in bulblist[i]:
            numon += (bit >> (l-1) & 1)
        if numon % 2 != plist[i]: flag = 0
    if flag: ans += 1

print(ans)

Measured memory_bytes: 12472
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main() 
{
	 llt n,ans=0;
	 cin >> n;
	 unordered_map<llt,llt> mp;
	 llt arr[n+1];
	 arr[n] = 0;
	 for(int i=0;i<n;i++){
	 	cin >> arr[i];
	}
	 sort(arr, arr+n);
	 for(int i=0;i<n;i++)
	 {
	 	bool flag = true;
	 	if(arr[i]==arr[i+1])
	 	{
	 		mp[arr[i]] = 1;
	 		continue;
	 	}
	 	for(int j=1;j*j<=arr[i];j++)
	 	{
	 		if(arr[i]%j==0)
	 		{
				bool numfound=true;
	 			if(mp.find(j)!=mp.end())
	 			{
	 				mp[arr[i]] = 1;
	 				flag = false;
	 				break;
	 			}
	 			if(mp.find(arr[i]/j)!=mp.end())
	 			{
					bool ojwod=true;
	 				mp[arr[i]] = 1;
	 				flag = false;
	 				break;
	 			}
	 			int nsjs=12;
	 		}
	 	}
	 	if(flag)
	 	{
	 		ans++;
	 		mp[arr[i]] = 1;
	 	}
	 }
	 cout << ans<<endl;
	return 0;
}


Measured memory_bytes: 12956
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    Q = int(input())
    BC = [[int(x) for x in input().split()] for _ in range(Q)]

    cnt = collections.Counter(A)

    ans = sum(A)

    for b, c in BC:
        ans -= cnt[b] * b
        cnt[c] += cnt[b]
        ans += cnt[b] * c
        cnt[b] = 0

        print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 38920
N = int(input())
L = list(map(int, input().split()))
cnt = 0
L.sort()
for i in range(N):
    for j in range(i+1, N):
        if L[j] == L[i]:
                continue
        for k in range(j+1, N):
            if L[j] == L[k]:
                continue
            if L[i] + L[j] > L[k]:
                cnt += 1
print(cnt)



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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  vector< int64 > A(N + 1), B(N);
  cin >> A >> B;

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    int64 sub = min(B[i], A[i]);
    ret += sub;
    A[i] -= sub;
    B[i] -= sub;

    sub = min(B[i], A[i + 1]);
    ret += sub;
    A[i + 1] -= sub;
    B[i] -= sub;
  }
  cout << ret << endl;
}







Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,m,s[1000][1000],len[100005];
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=(x<<3)+(x<<1)+ch-48,ch=getchar();
	return x;
}
int main(){
//	freopen("text.in","r",stdin);
//	freopen("text.out","w",stdout);
	n=read();m=n<<1;int k=1;
	while(k*(k-1)<m)++k;
	if(k*(k-1)==m){
		printf("Yes\n");int t=0;
		for(int i=1;i<=k;++i)for(int j=i+1;j<=k;++j)s[i][++len[i]]=s[j][++len[j]]=++t;
		printf("%d\n",k);for(int i=1;i<=k;i++){
			printf("%d ",len[i]);
			for(int j=1;j<=len[i];j++) printf("%d%c",s[i][j],j==len[t]?'\n':' ');
		}
	}else printf("No\n");
}

Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
using namespace std;
int N[100005];
int main()
{
	int n;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> N[i];
	}
	sort(N, N + n);
	if (N[(n / 2) - 1] == N[n / 2]) cout << "0" << '\n';
	else cout << N[n / 2] - N[(n / 2) - 1] << '\n';
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    string s;
    cin >> s;
    int len = s.length();
    if(s[0] == 'o' && s[len-1] == 'o'){
        cout << "o" << endl;
    }else if(s[0] == 'x' && s[len-1] == 'x'){
        cout << 'x' << endl;
    }else{
        cout << "o" << endl;
    }

    return 0;
}


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

using ll = long long;
using P = pair<int, int>;

const ll INF = 1e9;

int main() {
  int N;
  cin >> N;
  ll a[N+1];
  for (int i = 1; i <= N; i++) cin >> a[i];

  map<ll, ll> mp1;
  map<ll, ll> mp2;
  for (int i = 1; i <= N; i++) {
    mp1[i-a[i]+INF]++;
    mp2[i+a[i]+INF]++;
  }

  ll ans = 0;
  for (auto i = mp1.begin(); i != mp1.end(); i++) {
    ans += i -> second * mp2[i->first];
  }

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

Measured memory_bytes: 39460
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;




// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M=0;
    scanf("%lld",&M);
    
    long long ans1=0,ans2=0;
    int list[100000]={};
    unordered_map<int, bool> mp;

    rep(i,M){
        long long p;
        string tmp;
        cin>>p>>tmp;
        p--;
        if(mp[p]==false){
            if(tmp=="WA"){
                list[p]++;
            }else{
                ans1++;
                ans2+=list[p];
                mp[p]=true;
            }
        }
        
    }
    cout<<ans1<<" "<<ans2<<endl;
    
    return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;


int main() {
	int n,m;
    cin >> n >> m;
    vector<int> a(m+1);
    for(int i=0; i<m; i++){
        cin >> a.at(i);
    }

    vector<in> dp(n+1);
    for(int i=0; i<=n; i++){
        dp.at(i) = 0;
    }
    dp.at(0) = 1;
    int mindex=0;
    if(a.at(mindex)==1){
        mindex++;
        dp.at(1)=0;
    }else{
        dp.at(1)=1;
    }
    for(int i=2; i<=n; i++){
        if(i==a.at(mindex)){
            dp.at(i) = 0;
            mindex++;
        }else{
            dp.at(i) = (dp.at(i-1) + dp.at(i-2)) % 1000000007;
        }
    }
    long ans = dp.at(n) % 1000000007;
    cout << ans << endl;
        return 0;
    
}


Measured memory_bytes: 1408
while True:
	n = int(input())
	if n == 0: break
	score = list(map(int,input().split()))
	score.sort()
	ans = max(score)
	for i in range(1,n):
		aa = abs(score[i] - score[i-1])
		if ans > aa:
			ans = aa
	print(ans)


Measured memory_bytes: 5620
class Heap:
    def __init__(self,n):
        self.sz = 0
        self.list = []
    def push(self,x): #xを追加
        i = self.sz
        self.list.append(x)
        self.sz += 1
        while i > 0 :
            p = int((i-1)/2)
            if self.list[p] < x :
                self.list[i] = self.list[p]
                i = p
            else :
                break
        self.list[i] = x
    def pop2(self):
        ret = self.list[0]
        x = self.list[-1]
        self.list.pop()
        self.sz -= 1

        i = 0
        while (i*2)+1 < self.sz :
            a = 2 * i + 1
            b = 2 * i + 2
            if b < self.sz and self.list[a] < self.list[b]:
                a = b
            if self.list[a] <= x :
                break
            self.list[i] = self.list[a]
            i = a
        self.list[i] = x
        return ret


N ,M = map(int,input().split())
a = [int(i) for i in input().split()]
heap = Heap(N)
for i in range(N):
    heap.push(a[i])
for i in range(M):
    if len(heap.list) == 1 :
        heap.push(0)
    p = heap.pop2()
    heap.push(int(p/2))
print(sum(heap.list))

Measured memory_bytes: 14436
N = int(input())
S = input()

def solve(SS):
	n = len(SS)
	Z = [0] * n
	Z[0] = n
	i, j = 1, 0
	while i < n:
		while (i + j < n) and (SS[j] == SS[i + j]):
			j += 1
		Z[i] = j
		if j == 0:
			i += 1
			continue
		else:
			k = 1
			while (i + k < n) and (k + Z[k] < j):
				Z[i + k] = Z[k]
				k += 1
			i += k
			j -= k

	out = 0
	for i in range(n):
		tmp = min(Z[i], i)
		out = max(out, tmp)
	return out

ans = 0
for i in range(N):
	ans = max(ans, solve(S[i:]))

print(ans)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{

	int N, K;
	cin >> N >> K;
	if(K==1){
		ce(0)
	}
	else {
		ce(max(0, N - K))
	}
	
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnts;
int main(){
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int x; cin >> x; 
		cnts[x]++;
	}
	vector<int> vals;
	for (auto a: cnts){
		if ((a.second * 3) % n != 0){
			cout << "No" << endl;
			return 0;
		}
		for (int i = 0; i < (a.second * 3) / n; i++){
			vals.push_back(a.first);
		}
	}
	if ((vals[0] ^ vals[1] ^ vals[2]) == 0){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0; 
}


Measured memory_bytes: 3840
A=input()

for i in range(2**3):
  tmp=['-','-','-']
  for j in range(3):
    if ((i>>j)&1):
      tmp[j]='+'
  if eval(A[0]+tmp[0]+A[1]+tmp[1]+A[2]+tmp[2]+A[3])==7:
    print(A[0]+tmp[0]+A[1]+tmp[1]+A[2]+tmp[2]+A[3]+"=7")
    exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        cout<<modpow(n,3,1e10+9)<<endl;
    }

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

using namespace std;


int main() {
    int n,p;
    scanf("%d%d",&n,&p);
    int ji=0,ou=0;
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x&1) ji++;
        else ou++;
    }
    long long ans=0,num=1;
    for(int i=0;i<=ji;i++)
    {
        if((i&1)&&(p&1)){
            ans=ans+num;//printf("s1\n");
        }
        else if(((i&1)==0)&&((p&1)==0)){
            ans=ans+num;//printf("s2 %d\n\n",i);
        }
        num=num*(ji-i)/(i+1);
    }
    //printf("%lld\n",ans);
    ans=ans*(1LL<<ou);
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

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

	string s, t;
	cin >> s >> t;
	// t is substring of s
	int count = 0, ans = INF;
	for (int i = 0; i < s.size() - t.size() + 1; i++) {
		count = 0;
		for (int j = i; j < i + t.size(); j++) {
			if (s[j] != t[j - i]) count++;
		}
		ans = min(ans, count);
	}
	cout << ans;
}
	




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=5009;
int treasure,key,tre,a[N],coast[N],k,l,dp[N][N];
int f(int i,int total)
{
    if (i==key)
    {
        if (total==tre)
            return 0;
        return 1e9;
    }
    else if (dp[i][total]!=-1)
        return dp[i][total];
    return dp[i][total]=min(f(i+1,total),f(i+1,total|a[i])+coast[i]);
}
int main()
{
    FASTINOUT;
    cin>>treasure>>key;
    for (int i=0; i<treasure; i++)
    {
        tre=tre|(1<<i);
    }
    for (int i=0; i<key; i++)
    {
        cin>>coast[i]>>k;
        for (int j=0; j<k; j++)
        {
            cin>>l;
            l--;
            a[i]=a[i]|(1<<l);
        }
    }
    memset(dp,-1,sizeof dp);
    int ans=f(0,0);
    cout<<(ans==1e9?-1:ans);
    return 0;
}


Measured memory_bytes: 101704
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 40005


// Driver code to test above functions
int32_t main()
{
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;
    cin >> s;

    int n = s.size();

    reverse(s.begin(), s.end());
    int val = 0;
    int pre[n], a[n];

    int pow = 1;
    for(int i=0;i<n;i++)
    {
        a[i] = ((int)(s[i]-'0')*pow*1LL)%2019;
        pow*=10;

        if(pow>=2019)
            pow %= 2019;
    }

    pre[0] = a[0];
    for(int i=1;i<n;i++)
        pre[i] = (pre[i-1] + a[i])%2019;

    map<int, int> mp;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(pre[i]==0)
            ans++;

        ans += mp[pre[i]];
        mp[pre[i]]++;
    }

    cout << ans;



    return 0;
} 


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y

using namespace std;
typedef pair<int, int> P;

ll MAX_DAY=5000000000000000;

int main() {
	FAST;
	string s;
	ll k;
	cin >> s >> k;

	k -= 1;
	if (s[0] != '1') {
		cout << s[0] << "\n";
		return 0;
	}
	int idx=0;
	while (s[idx] == '1') {
		idx++;
	}
	if (k<idx) {
		cout << s[k] << "\n";
	}
	else {
		cout << s[idx] << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

void printPile(deque<int>* pile,int n){
	for(int i=1;i<=n;i++){
		printf("%d:",i);
		for(int j=0;j<pile[i].size();j++){
			printf("%3d",pile[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		deque<int> pile[101];
		for(int i=1;i<=n;i++){
			pile[i].push_back(i);
		}
		while(1){
			int from,to;
			scanf("%d %d",&from,&to);

			if(from == 0 && to == 0) break;

			if(from == to) continue;

			int fNum=0,fPos=0;
			int tNum=0,tPos=0;

			//search pick up cube pos
			for(int j=1;j<=n;j++){
				for(int k=0;k<pile[j].size();k++){
					if(pile[j][k] == from){
						fNum = j;
						fPos = k;
					}

					if(pile[j][k] == to){
						tNum = j;
						tPos = k;
					}
				}
			}

			if(tNum == fNum){
				if(fPos < tPos) continue;
			}

			if(to == 0 && fPos == pile[fNum].size() -1) continue;

			//pick up
			vector<int> tmp;
			for(int j=0;j<fPos;j++){
				tmp.push_back(pile[fNum][j]);
			}
			reverse(tmp.begin(),tmp.end());


			pile[fNum].erase(pile[fNum].begin(),pile[fNum].begin() + fPos + 1);
			
			for(int j=0;j<tmp.size();j++){
				pile[tmp[j]].push_front(tmp[j]);
			}

			for(int j=1;j<=n;j++){
				for(int k=0;k<pile[j].size();k++){
					if(pile[j][k] == to){
						tNum = j;
						tPos = k;
					}
				}
			}

			if(tNum == 0){
				tNum = from;
			}

			pile[tNum].push_front(from);

			//printPile(pile,n);
		}

		vector<int> h;
		for(int i=1;i<=n;i++){
			if(pile[i].size() >= 1) h.push_back(pile[i].size());
		}

		sort(h.begin(),h.end());

		for(int i=0;i<h.size();i++){
			printf("%d\n",h[i]);
		}
		printf("end\n");
	}
}

Measured memory_bytes: 1344
import numpy as np
def main():
  N = int(input())
  A = list(map(int, input().split()))
  dic = {}
  for i in range(N):
    if not A[i] in dic:
      dic[A[i]]=1
    else:
      dic[A[i]]+=1
  ans = 0
  for i, j in dic.items():
    if i < j:
      ans += j-i
    if j < i:
      ans += j
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 39216
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
 
int main () {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
//  cin >> TT;
  while (TT--) {
    ll N,Q;
    cin >> N;
    vector<ll> A(N);
    for (auto& x : A) cin >> x;
    cin >> Q;
    vector<pair<ll,ll>> B(Q);
    for (auto& [a,b] : B) cin >> a >> b;
    vector<ll> ans;
    ll sum = 0;
    unordered_map<ll,ll> cnt;
    for (int i = 0; i < N; ++i) {
      ++cnt[A[i]];
      sum += A[i];
    }
    for (auto &[b,c] : B) {
      sum += (c-b)*cnt[b];
      cnt[c] += cnt[b];
      cnt[b] = 0;

      ans.emplace_back(sum);
    }
    for (auto& x : ans) cout << x << endl;
  }
}


Measured memory_bytes: 10424
#include <iostream>

using namespace std;

int main() {
    string S;
    cin >> S;
    if(S.substr(5,2) == "01" || S.substr(5,2) == "02" || S.substr(5,2) == "03" || S.substr(5,2) == "04"){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[20];
ll x[30][30],y[30][30];

main(){
  ll n,ans=0,tmp=0;
  cin>>n;
  rep(i,0,n){
    cin>>a[i];
    rep(j,0,a[i]){
      cin>>x[i][j]>>y[i][j];
      x[i][j]--;
    }
  }
  bool p=false;
  for(int mask = 0; mask < (1 << n); mask++){
      p=true;
      tmp=0;
      rep(i,0,n){
        if(mask&(1<<i)){
          rep(j,0,a[i]){
            if(mask&(1<<x[i][j])){
              if(y[i][j]==0)p=false;
            }
            else if(!(mask&(1<<x[i][j]))){
              if(y[i][j]==1)p=false;
            }
          }
        }
      }
      if(p){
        rep(i,0,n)if(mask&(1<<i))tmp++;
        ans=max(ans,tmp);
      } 
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;


string S;
int a, b, c;

int main() {
	cin.tie(0);
	cout.tie(0);

	ios::sync_with_stdio(false);

	cin >> S;
	int N = S.length();

	
	FOR(i, 0, N) {
		if (S[i] == 'a')a++;
		if (S[i] == 'b')b++;
		if (S[i] == 'c')c++;
	}

	if (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1)cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
 
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}
 
#define ALL(a) (a).begin(), (a).end()
 
vector<int> graph[200005];
int color[200005];
 
bool dfs(int v, int d) {
    color[v] = d;
 
    bool res = false;
    for (int to : graph[v]) {
        if (color[to] < 0) {
            res = res || dfs(to, d ^ 1);
        } else if (color[to] != (d ^ 1)) {
            res = true;
        }
    }
    return res;
}
 
int main() {
    ll N, M;
    cin >> N >> M;
 
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
 
    memset(color, -1, sizeof(color));
 
    if (dfs(0, 0)) {
        cout << (N * (N - 1)) / 2 - M << endl;
    } else {
        ll even = 0, odd = 0;
        for (int v = 0; v < N; v++) {
            if (color[v] == 0) even++;
            else odd++;
        }
        cout << even * odd - M << endl;
    }
 
    return 0;
}

Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    while(true){
	        int n = sc.nextInt();
	        int p = sc.nextInt();
	        if(n==0 && p==0) break;
	        int [] kouho = new int[n];
	        int stone = p;
	        int i=0;
	        while(true){
	        	if(stone>0){
	        		kouho[i]++;
	        		stone--;
	        	}else{
	        		stone = kouho[i];
	        		kouho[i] = 0;
	        	}
	        	boolean flag = false;
	        	if(stone == 0){
	        		if(kouho[i] == p){
	        			flag = true;
	        		}
	        		if(flag) break;
	        	}
	        	i=(i+1)%n;
	        }
	        System.out.println(i);
	    }
	}
}


Measured memory_bytes: 26836
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			
			int[] aArray = new int[n];
			Map<Integer, Integer> countMap = new HashMap<>();
			
			for(int i = 0 ; i < n ; i++ ) {
				aArray[i] = sc.nextInt();
				int current = aArray[i];
				if ( countMap.containsKey(current)) {
					countMap.put(current, countMap.get(current) + 1);
				}
				else {
					countMap.put(current, 1);
				}
			}
			
			Set<Integer> keys = countMap.keySet();
			
			//calc total first
			long total = 0;
			for(int key : keys) {
				long count = countMap.get(key);
				total += count * (count -1) / 2;
			}
			
			for(int i = 0 ; i < n ; i++ ) {
				int current = aArray[i];

				long count = countMap.get(current);
				
				//long ans = total - (count * (count-1) / 2) + ((count-1) * (count-2)/2);
				long ans = total - count + 1;
				
				System.out.println(ans);
			}
			
			
		}
	}

}

Measured memory_bytes: 109108
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int H = scan.nextInt();

        int W = scan.nextInt();

        int h = scan.nextInt();

        int w = scan.nextInt();

        scan.close();

        int allCell = H * W;

        int ans = allCell - (h*W) - (w*H - (h*w));

        System.out.print(ans);

    }
}

Measured memory_bytes: 23636
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<bits/stdc++.h>
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1000000007
#pragma GCC optimization ("O3")
using namespace std;
//const long long int mod = 100000007;
#define all(x) begin(x),end(x)
long long int dp[2005][2005];
long long int ncr(long long int n,long long int r)
{
  if(r == 1)
  {
    return n;
  }
  if(n == r || r == 0)
  {
    return 1;
  }
  if (dp[n][r] != -1)
  {
    return dp[n][r];
  }
  else
  {
    dp[n][r] = ((ncr(n-1,r)%mod)+(ncr(n-1,r-1)%mod)%mod);
    return dp[n][r];
  }
}
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  memset(dp,-1,sizeof(dp));
  long long int n,k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
  {
    long long int p = n-k+1;
    if(p>=i && k>= i)
      cout << ((ncr(p,i)%mod)*(ncr(k-1,i-1)%mod))%mod << endl;
    else
      cout << 0 << endl;
  } 
  return 0;
}


Measured memory_bytes: 31744
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N, K = map(int, input().split())

up = (N - 1) * (N - 2) // 2

if up < K:
    print(-1)
    exit()

res = []

for i in range(2, N+1):
    res.append((1, i))

K = up - K

for i in range(2, N):
    for j in range(i+1, N + 1):
        if K == 0:
            break
        res.append((i, j))
        K -= 1

    if K == 0:
        break

print(len(res))

for u, v in res:
    print(u, v)


Measured memory_bytes: 3992
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  double ans = 0.0;
  for(int i = 0; i < n; i++){
    ans += 1.0 / (a[i] + 0.0);
  }
  ans = 1.0 / ans;
  printf("%.12f\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s;
    cin >> s;
    set<char> kinds(s.begin(), s.end());
    for (auto elem : kinds) {
        if (count(ALL(s), elem) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			//[summary]B - ∵∴∵
			var o = Console.ReadLine();
			var e = Console.ReadLine();
			string password = "";

			for(int i = 0; i < o.Length; i++)
			{
				if(i < e.Length)
				{
					password += o[i].ToString() + e[i].ToString();
				}
				else
				{
					password += o[i].ToString();
				}
			}

			Console.WriteLine(password);
		}
	}
}

Measured memory_bytes: 13140
def bubbleSort(A):
    N = len(A)
    cnt = 0
    for i in range(N):
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                cnt += 1
                A[j], A[j - 1] = A[j - 1], A[j]
    print(*A)
    print(cnt)
N = int(input())
A = list(map(int, input().split()))
bubbleSort(A)

Measured memory_bytes: 7748
K = gets.to_i

def digitsum(num)
    ret = 0
    while num > 0
        ret += num % 10
        num /= 10
    end
    ret
end

last = 1
ans = [1]
while ans.length < K
    base = 1
    nextnum = nil
    min = 10**20
    while base <= last * 10
        d = (last / base) % 10
        (1..(9-d+1)).each do |add|
            cand = (last / base + add + 1) * base - 1
            cand_val = cand.to_f / digitsum(cand)
            if min > cand_val
                min = cand_val
                nextnum = cand
            end
        end
        base *= 10
    end
    last = nextnum
    ans.push(nextnum)
end
puts ans

Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
 
typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;
const int MAX=(1<<14)-1;
mouse Q[MAX+1];
int s,num;

mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;
 
main(){
  scanf("%d%d%d ",&h,&w,&n);
  short maxch[h][w];
  char ku[h][w];
  
  rep(i,h)fread(ku[i],1,w+1,stdin);
 
 
  rep(i,h)rep(j,w){
    if(ku[i][j]=='S')cx=i,cy=j;
    maxch[i][j]=-1;
  }
 
 
  Q[s+num++]=(mouse){cx,cy,0,0};
  maxch[cx][cy]=0;
 
  while(true){
    t=Q[s++&MAX];
    num--;
    cx=t.x,cy=t.y,cost=t.cost;
    ch=t.ch;
 
    rep(i,4){
      nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
      if(ku[nx][ny]=='X')continue;
      nch=ch;
      if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
        nch=ch+1;
      }
 
      if(maxch[nx][ny]>=nch)continue;
      if(nch==n){
        printf("%d\n",cost+1);
        return 0;
      }
      maxch[nx][ny]=nch;
      Q[s+num++&MAX]=(mouse){nx,ny,cost+1,nch};
    }
  }
}

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

int32_t main () {
    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n], b[n], c[n], dp[n+1][3];
        for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
        }
        cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    }
    return 0;
}


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

using namespace std;

int main(){
  int a[3];
  int x,y;
  int san=0,tyoku=0,ei=0,don=0;

  while(1){
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    x=a[0]*a[0]+a[1]*a[1];
    y=a[2]*a[2];

    if(a[0]+a[1] <= a[2])
      break;
    else if (x == y)
      tyoku++;
    else if(x > y)
      ei++;
    else if (x < y)
      don++;
  }

  san=tyoku+ei+don;
  cout<<san<<" "<<tyoku<<" "<<ei<<" "<<don<<endl;

  return 0;
}



Measured memory_bytes: 3168
import sys


def main():
    n, m, l = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [0] * m
    b = [0] * m
    c = [0] * m
    for i in range(m):
        a[i], b[i], c[i] = [int(s) for s in sys.stdin.readline().strip().split()]

    INF = float('inf')
    dist = [[INF] * n for _ in range(n)]
    for i in range(m):
        dist[a[i]-1][b[i]-1] = c[i]
        dist[b[i]-1][a[i]-1] = c[i]

    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

    ldist = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                ldist[i][j] = 1

    for i in range(n):
        for j in range(n):
            for k in range(n):
                ldist[j][k] = min(ldist[j][k], ldist[j][i] + ldist[i][k])

    q = int(sys.stdin.readline().strip())
    s = [0] * q
    t = [0] * q
    for i in range(q):
        s[i], t[i] = [int(s) for s in sys.stdin.readline().strip().split()]

    for i in range(q):
        s0, t0 = s[i] - 1, t[i] - 1
        if ldist[s0][t0] == INF:
            print(-1)
        else:
            print(ldist[s0][t0]-1)


main()


Measured memory_bytes: 126488
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#define N 200010
#define M 1000010
using namespace std;
vector<pair<int,int> >e[N+M];
vector<int> col[M];
vector<int> new_e[N+M]; 
int n,m,x,y,c;
int maxn;
int color[N+M];
int dis[N+M];
int vis[N+M];
int q[N+M],head,tail;
int now;
int main()
{
	scanf("%d%d",&n,&m);
	now=n;
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&c);
		e[y].push_back(make_pair(c,x));
		e[x].push_back(make_pair(c,y));
		col[c].push_back(x);
		col[c].push_back(y);
		maxn=max(maxn,c);
	}
	for (int i=1;i<=n;i++)
		sort(e[i].begin(),e[i].end());
	for (int i=1;i<=maxn;i++)
	{
		if (col[i].empty()) continue;
		for (int j=0;j<col[i].size();j++)
		{
			int x=col[i][j];
			if (color[x]==i) continue;
			color[x]=i;
			head=0;tail=0;
			q[++tail]=x;
			while (head<tail)
			{
				int x=q[++head];
				for (int k=vis[x];k<e[x].size();k++)
				{
					int y=e[x][k].second;
					if (e[x][k].first!=i) break;
					if (color[y]!=i)
					{
						q[++tail]=y;
						color[y]=i;
					}
					vis[x]++;
				}
			}
			now++;
			for (int k=1;k<=tail;k++)
			{
				new_e[now].push_back(q[k]);
				new_e[q[k]].push_back(now); 
				//cout<<i<<" "<<now<<" "<<q[k]<<endl;
			}
		}
	}
	head=0;tail=0;
	q[++tail]=1;
	for (int i=1;i<=now;i++)
		dis[i]=-1;
	dis[1]=0;
	while (head<tail)
	{
		int x=q[++head];
		for (int i=0;i<new_e[x].size();i++)
		{
			int y=new_e[x][i];
			if (dis[y]==-1)
			{
				q[++tail]=y;
				dis[y]=dis[x]+1;
			}
		}
	}
	if (dis[n]>0)printf("%d",dis[n]/2);
	else printf("-1");
}

Measured memory_bytes: 112896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 200005;
vector<int> a;
bool cmp(const int &a, const int &b) {
	return abs(a) > abs(b);
}
ll qpow(ll a, ll b) { //快速幂
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod; //可以换为快乘
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}
int main()
{
	int n, k, z = 0;
	cin >> n >> k;
	for (int i = 0, b; i < n; i++) {
		cin >> b;
		if (b == 0)z++;
		else a.push_back(b);
	}
	if (k > (int)a.size()) {
		cout << 0 << endl;
		return 0;
	}
	sort(a.begin(), a.end(), cmp);
	ll ans = 1;
	int zheng = inf, fu = inf;//最后一个正数/负数
	for (int i = 0; i < k; i++) {//前k个乘起来，存最后的正数和负数
		ans *= a[i];
		ans %= mod;
		if (a[i] > 0)zheng = a[i];
		else fu = a[i];
	}
	if (ans < 0) {
		int nzheng = inf, nfu = inf;//下一个正数和负数
		for (int i = k; i < (int)a.size(); i++)//k-后面里面找
			if (a[i] > 0 && nzheng == inf) nzheng = a[i];//只取最大的
			else if (a[i] < 0 && nfu == inf) nfu = a[i];
		if (nzheng == inf && nfu == inf) {//没有别的数
			if (z > 0)//出现0，答案变为0
				ans = 0;
		}
		else if (nzheng != inf && nfu == inf) {//后面只有正
			ans *= qpow(fu, mod - 2);//去掉最后一个最小的负数，乘上后面的正数
			ans %= mod;
			ans *= nzheng;
			ans %= mod;
		}
		else if (nzheng == inf && nfu != inf) {//后面只有负数
			if (zheng != inf) {//前面有正数
				ans *= qpow(zheng, mod - 2);//负数换正数
				ans %= mod;
				ans *= nfu;
				ans %= mod;
			}
			else {//前面也没有正数，全是负数
				if (z > 0) {
					ans = 0;
				}
				//全是负数，重新算答案
				else {
					ans = 1;
					for (int i = n - 1; i >= n - k; i--) {//后k个数乘起来
						ans *= a[i];
						ans %= mod;
					}
				}
			}
		}
		else {//后面有正有负
			if (zheng == inf) {//前面全是负数，正数换掉最小的负数
				ans *= qpow(fu, mod - 2);
				ans %= mod;
				ans *= nzheng;
				ans %= mod;
			}
			else if ((long double)1.0*abs(nfu)/zheng<(long double)1.0*nzheng/abs(fu)) {// 后正数/前负数<后负数/前正数
				ans *= qpow(fu, mod - 2);
				ans %= mod;
				ans *= nzheng;
				ans %= mod;
			}
			else {
				ans *= qpow(zheng, mod - 2);
				ans %= mod;
				ans *= nfu;
				ans %= mod;
			}
		}
	}
	cout << (ans % mod + mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 4292