akhauriyash/Code-Regression huggingface dataset:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

def min_range(A):
    smaller = [[0, -1]]
    ret = []
    for i, a in enumerate(A):
        while smaller[-1][0] > a:
            smaller.pop()
        ret.append(i-smaller[-1][1])
        smaller.append([a, i])
    return ret

B = min_range(A)
C = min_range(A[::-1])[::-1]

answer = 0
for i in range(N):
    answer += A[i] * B[i] * C[i]

print(answer)



Measured memory_bytes: 50792
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;
typedef unsigned long long ll;

map<string, int>ma;
vector<pair<int, string> >vec;

struct sortVec{
    bool operator()(string m1, string m2){
        return ma[m1]<ma[m2];
    }
}sv;

int main(){
    int n,p;
    while(cin>>n,n){
        ma.clear();
        vec.clear();
        string s;
        for(int i=0;i<n;i++){
            int day,time;
            cin>>s>>day>>time;
            time=(time/100)*60+time%100+day*24*60;
            ma[s]=time;
            vec.push_back(make_pair(time,s));
        }
        sort(vec.begin(),vec.end());
        cin>>p;
        set<string>fav;
        for(int i=0;i<p;i++){
            cin>>s;
            fav.insert(s);
        }
        int p=-100000;
        bool m=false;
        int c=0;
        for(int i=0;i<n;i++){
            if(p+30>vec[i].first){
                if(fav.count(vec[i].second)){
                    if(m){
                        c=-1;
                        break;
                    }else{
                        m=true;
                        p=vec[i].first;
                    }
                }
            }else{
                c++;
                p=vec[i].first;
                m=fav.count(vec[i].second);
            }
        }
        cout<<c<<endl;
//        vector<string>fav;
//        for(int i=0;i<p;i++){
//            cin>>s;
//            fav.push_back(s);
//        }
//        sort(fav.begin(),fav.end(),sv);
//        vector<string>res;
//        res.push_back(fav[0]);
//        bool nex=false;
//        for(int i=1;i<fav.size();i++){
//            if(ma[fav[i]]%10080<(ma[fav[i-1]]+30)%10080){
//                cout<<-1<<endl;
//                nex=true;
//                break;
//            }
//            res.push_back(fav[i]);
//        }
//        if(nex){
//            continue;
//        }
//        for(int i=0;i<vec.size();i++){
//            int start=vec[i].first;
//            int resi=0;
//            while(resi<res.size()&&(ma[res[resi]]+30)%10080<=start%10080){
//                resi++;
//            }
//            if(resi==res.size()||(start+30)%10080<=ma[res[resi]]){
//                if(resi>0&&ma[res[resi-1]]+30>start){
//                    continue;
//                }
//                res.push_back(vec[i].second);
//                sort(res.begin(),res.end(),sv);
//            }
//        }
//        cout<<res.size()<<endl;
    ne:;
    }
    return 0;
}

Measured memory_bytes: 1304
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    while True:
        n = int(input())
        w = list(map(int, input().split()))
        if n==0:
            break
        else:
            dp = [[0]*(n+1) for _ in range(n+2)]
            # 幅
            for i in range(2, n+1):
                for l in range(n-i+1):
                    r = l+i
                    if dp[l+1][r-1] == i-2:
                        if abs(w[l]-w[r-1])<=1:
                            dp[l][r] = i
                        else:
                            dp[l][r] = i-2
                    for j in range(l, r):
                        if dp[l][j] + dp[j][r] > dp[l][r]:
                            dp[l][r] = dp[l][j] + dp[j][r]

            print(dp[0][-1])        

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 7124
import java.util.*;
import java.lang.*;

public class Main {
    
    public static void main (String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        
        int ans = 0;
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            if (a[i] >= h && b[i] >= w) {
                ans ++;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 25448
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    A = [input().strip() for _ in range(H)]

    c = collections.Counter()
    for a in A:
        for aa in a:
            c[aa] += 1

    four_cnt = (H // 2) * (W // 2)
    two_cnt = (H % 2) * (W // 2) + (W % 2) * (H // 2)
    one_cnt = (H % 2) * (W % 2)

    for k in c.keys():
        if c[k] >= 4:
            q, r = divmod(c[k], 4)
            mi = min(four_cnt, q)
            c[k] -= mi * 4
            four_cnt -= mi

    for k in c.keys():
        if c[k] >= 2:
            q, r = divmod(c[k], 2)
            mi = min(two_cnt, q)
            c[k] -= mi * 2
            two_cnt -= mi

    for k in c.keys():
        if c[k] >= 1:
            q, r = divmod(c[k], 1)
            mi = min(one_cnt, q)
            c[k] -= mi * 1
            one_cnt -= mi

    if sum([four_cnt, two_cnt, one_cnt]) == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

string add(string out, int r, char a){
  stringstream ss;
  ss << r;
  out += ss.str();
  out += a;
  return out;
}

int main(){
  int n;
  string origin;
  while(scanf("%d", &n) && n){
    cin >> origin;
    rep(i, n){
      string out = "";
      char a = origin[0];
      int r = 0;
      rep(j, origin.size()){
	if(a == origin[j]) r++;
	else{
	  out = add(out, r, a);
	  r = 1;
	  a = origin[j];
	}
      }
      out = add(out, r, a);
      origin = out;
      //      cout << origin << endl;
    }
    cout << origin << endl;
  }
  return 0;
}

Measured memory_bytes: 1568
#include<iostream>
using namespace std;
int a[105];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	for(int i=0;i<n-1;++i){						//4.原来没打 
		cout<<a[i]<<' ';						//4.					 
	}											//4.					
	cout<<a[n-1]<<endl;							//4.
	for(int i=1;i<n;++i){
		int t=a[i];
		int j=i-1;
		while(j>=0&&a[j]>t){					//3.升序是">",降序是"<" 
			a[j+1]=a[j];						 
			--j;
		}
		a[j+1]=t;								//1.后一位（原打成a[j]） 
		for(int i=0;i<n-1;++i){					//2.此循原来写外面了 
			cout<<a[i]<<' ';					//2. 
		}										//2.
		cout<<a[n-1]<<endl;						//2.
	}
	return 0;
} 


Measured memory_bytes: 3116
#include<stdio.h>
int search(int A[],int n,int key){
 int i=0;
 A[n]=key;
 while(A[i]!=key)i++;
 return i!=n;
}
int main(){
 int i,n,A[10000+1],q,key,sum=0;
 scanf("%d",&n);
 for(i=0;i<n;i++)scanf("%d",&A[i]);
 scanf("%d",&q);
 for(i=0;i<q;i++){
  scanf("%d",&key);
  if(search(A,n,key))sum++;
 }
 printf("%d\n",sum);
 return 0;
}


Measured memory_bytes: 2724
#include <stdio.h>
#include <string.h>

int dp[1024][1024];

int max(int a, int b) {
  return a > b ? a : b;
}

int main() {
  int q;
  scanf("%d", &q);
  while(q--) {
    char X[1024], Y[1024];
    int lenx, leny;
    int i, j;

    scanf("%s %s", X, Y);
    lenx = strlen(X);
    leny = strlen(Y);

    memset(dp, 0, sizeof(dp));
    for(i = 1; i <= lenx; i++) {
      for(j = 1; j <= leny; j++) {
	dp[i][j] = max(dp[i-1][j], max(dp[i][j-1], dp[i-1][j-1]+(X[i-1]==Y[j-1])));
      }
    }

    printf("%d\n", dp[lenx][leny]);
  }

  return 0;
}

Measured memory_bytes: 4704
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

long long fac[maxn],inv[maxn];

long long poww(long long a,long long b)
{
	long long res=1,base=a;
	while(b)
	{
		if(b&1)
			res=(res*base)%mod;
		base=(base*base)%mod;
		b>>=1;
	}
	return res;
}

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

long long c(long long n,long long m) //c(n,m)
{
	return fac[n]*inv[n-m]%mod*inv[m]%mod;
}

int n;
long long cost[maxn];
long long ans;
long long tmp[maxn];

int main()
{
	//freopen("1.in","r",stdin);
	init();
	tmp[0]=1;
	for(int i=1;i<maxn;i++)
		tmp[i]=(i*poww(2,i-1)%mod+poww(2,i))%mod;

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&cost[i]);
	sort(cost+1,cost+1+n);

	for(int i=1;i<=n;i++)
	{
		long long k=n-i;
		ans=(ans+cost[i]*2*poww(4,n-k-1)%mod*poww(2,k)%mod*(tmp[k])%mod)%mod;		
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6528
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<cstdio>

int v[1500001];
char s[1500001],t[500002];
void Zalgorithm(int N){
  int i=1,j=0,k=0;
  while(i<N){
    while(i+j<N&&s[i+j]==s[j])++j;
    v[i]=j;
    if(!j){
      ++i;
      continue;
    }
    k=1;
    while(v[k]+k<j){
      v[i+k]=v[k];
      ++k;
    }
    i+=k;
    j-=k;
  }
}
int i,j,K,que[500001],bf,ans,size;
int main(){
  int N,ng=500001,mid;
  std::fgets(t,1000000,stdin);
  std::fgets(s,1000000,stdin);
  while(ng-K>1){
    mid=(ng+K)>>1;
    (s[mid]?K:ng)=mid;
  }
  while(t[i]!='\n'){
    s[K+i]=t[i];++i;
  }
  N=i;
  i+=K;
  int M=N+(K<<1);
  while(i<M){
    s[i++]=t[j++];
    j*=j<N;
  }
  Zalgorithm(M);
  for(i=0;i<N;++i){
    if(v[i+K]<K)que[size++]=(i+K)%N;
  }
  for(i=0;i<N;++i){
    if(i==size){
      puts("-1");
      return 0;
    }
    if(v[que[i]+=K]>=K){
      que[size++]=que[i]%N;
      if(bf<=i){
        bf=size-1;
        ++ans;
      }
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n,z;

int main(){
	fast_io();
	int n,k;
	cin >> n >> k;
	vector<int> weights(n + 1);
	fu(i,1,n){
		ll val = i;
		ll cnt = 0;
		while(val < k){
			++cnt;
			val<<=1;
		}
		weights[i] = cnt;
	}
	double ans = 0;
	fu(i,1,n){
		ans += (double)1/(1 << weights[i]);
	}
	ans/=n;
	cout.precision(13);
	cout << ans << '\n';
}


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

void input(vector<string>& rvsGrid)
{
  int nHigh, nWide;
  cin >> nHigh >> nWide;

  rvsGrid.resize(nHigh);
  for (int ny = 0; ny < nHigh; ny++)
    cin >> rvsGrid[ny];
}

int repaintCell(int ny, int nx, const vector<string>& cnrvsGrid)
{
  if (   ny >= 0  && ny < cnrvsGrid.size()
      && nx >= 0  && nx < cnrvsGrid[ny].size())
    if (cnrvsGrid[ny][nx] == '#')
      return 1;
    else;

  return 0;
}

int canAchive(const vector<string>& cnrvsGrid)
{
  const vector<int> cnvnDy = {-1,  0,  1,  0};
  const vector<int> cnvnDx = { 0, -1,  0,  1};

  for (int ny = 0; ny < cnrvsGrid.size(); ny++)
    for (int nx = 0; nx < cnrvsGrid[ny].size(); nx++)
      if (cnrvsGrid[ny][nx] == '#')
      {
        bool bReslt = false;
        for (int i = 0; i < cnvnDy.size(); i++)
          if (repaintCell(ny + cnvnDy[i], nx + cnvnDx[i], cnrvsGrid))
            bReslt = true;

        if (!bReslt)  return 0;
      }

  return 1;
}

int main()
{
  vector<string> vsGrid;

  input(vsGrid);
  if (canAchive(vsGrid))  cout << "Yes" << endl;
  else                        cout << "No"  << endl;

  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    if (n >= 64)
    {
        cout << 64 << endl;
    }
    else if (n >= 32)
    {
        cout <<32 << endl;
    }
    else if (n >= 16)
    {
        cout << 16 << endl;
    }
    else if (n >= 8)
    {
        cout << 8 << endl;
    }
    else if (n >= 4)
    {
        cout << 4 << endl;
    }
    else if (n >= 2)
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 384
n,d=map(int,input().split())
x=[[0]*1]*n
for i in range(n):
    x[i]=list(map(int,input().split()))
#print(x)
ans=0
for k in range(n):
    for t in range(k+1,n):
        dis=0
        for kai in range(d):
            dis+=(x[k][kai]-x[t][kai])**2
        #print(dis**(1/2))
        if(dis**(1/2)%1==0.0):
            ans+=1
print(ans)

Measured memory_bytes: 3064
# abc136 D:

import sys
import re

S = input()
field = [0 for i in range(len(S))]

def roundup(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return int(n // 2 + 1)
def rounddown(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return int(n // 2)

mode = 0
child = 0
for i in range(len(field)):
    #print("i, mode, S[i]:", i,mode,S[i])
    if mode == 0:
        if S[i] == 'R':
            child += 1
        elif S[i] == 'L':
            field[i-1] += roundup(child)
            field[i] += rounddown(child)
            child = 1
            mode = 1
            j = i
    elif mode == 1:
        if S[i] == 'R':
            field[j] += roundup(child)
            field[j-1] += rounddown(child)
            child = 1
            mode = 0
        elif S[i] == 'L':
            child += 1
if mode == 1:
    field[j] += roundup(child)
    field[j-1] += rounddown(child)

print(" ".join(map(str,field)))


Measured memory_bytes: 10740
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
//	int t;
//	cin>>t;
//	while(t--)
//	{
		ll i,j,k,n;
		cin >> n;
		vector < pair<ll,ll> > vec(n) ;
		vector < pair<ll,ll> > sum1,sum2 ;
		ll ans = 0;
		f(i,0,n)
		{
			cin >> j >> k;
			vec[i] = {j,k} ;
			sum1.pb(mp(j+k,i)) ; sum2.pb(mp(j-k,i)) ;
		}
		sort(all(sum1)) ; sort(all(sum2)) ;
		i = sum1[n-1].F ; j = sum1[n-1].S ;//x+y , ind
		for(k=0;k<sum1.size();++k)
		{
			ll x = sum1[k].S ;
			if(vec[j].F >= vec[x].F && vec[j].S >= vec[x].S)
				ans = max(ans,i - sum1[k].F) ;
		}
		i = sum2[n-1].F ; j = sum2[n-1].S ;//x+y , ind
		for(k=0;k<sum2.size();++k)
		{
			ll x = sum2[k].S ;
			if(vec[j].F >= vec[x].F && vec[j].S <= vec[x].S)
				ans = max(ans,i - sum2[k].F) ;
		} 
		cout << ans endl ;
//	}
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 12928
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include <functional>
using namespace std;
static const int MAX = 100000;
typedef long long llong;

int n, m;
vector<int> v;

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

    int x;
    for (int i = 0; i < n;i++){
        scanf("%d", &x);
        v.push_back(x);
    }
    sort(v.begin(), v.end());

    int z;
    for (int i = 0; i < m; i++){
        z = v.back() / 2;
        //v[0]を二分探索で挿入
        v.insert(lower_bound(v.begin(), v.end(), z), z);
        v.pop_back();
    }

    llong ans = 0;
    for (int i = 0; i < v.size(); i++){
        ans += v[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

int K;
int main(void){
    cin >> K;
    ll total = 0;
    for(int a=1;a<=K;a++)
        for(int b=1;b<=K;b++)
            for(int c=1;c<=K;c++) {
        total += gcd(a, gcd(b, c));
    }
    cout << total << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

ll k;

string s;

vector<pair<int,int> > v;

int main()
{
	cin >> s >> k;
	bool allsame = 1;
	for (int i = 0;i + 1 < s.size();i++)
		if (s[i] != s[i + 1])
			allsame = 0;
	if (allsame)
	{
		printf("%lld\n",(long long)(s.size() * k) / 2);
		return 0;
	}
	for (int i = 0;i < s.size();i++)
	{
		if (!v.size() || v.back().first != s[i])
			v.push_back(make_pair(s[i],1));
		else
			v.back().second++;
	}
	if (s[0] == s[s.size() - 1])
	{
		ll ans = 0;
		for (int i = 1;i + 1 < v.size();i++)
			ans += v[i].second / 2;
		ans *= k;
		ll tot = v[0].second + v.back().second;
		ans += (k - 1) * (tot / 2);
		ans += v[0].second / 2 + v.back().second / 2;
		printf("%lld\n",ans);
	}
	else
	{
		ll ans = 0;
		for (int i = 0;i < v.size();i++)
			ans += v[i].second / 2;
		ans *= k;
		printf("%lld\n",ans);
		return 0;
	}
	return 0;
}

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



Measured memory_bytes: 2796
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n,m;
  cin >> n>>m;
  
  int ans=0;

  map<int,int> h;  
  rep(i,n) {
    int x;
    cin >> x;
    h[i+1]=x;
  }
  
  vector<bool> p(n,true);
  
  rep(i,m) {
  int x,y;
  cin >> x >> y;
    if(h.at(x)>=h.at(y)) p[y-1]=false;
    if(h.at(x)<=h.at(y)) p[x-1]=false;
  }
 
  rep(i,n){
    if(p[i])ans++;
  }
 
  cout << ans << endl;    
  
  
}



Measured memory_bytes: 8256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i) cin >> d[i];
	sort(d.begin(), d.end());
	cout << d[n / 2] - d[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
bool operator>(const pair<ll, ll> a, const pair<ll, ll> b) {
  return a.first > b.first;
};
int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n;
  cin >> n;
  // map<ll, ll> ba;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> ba;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ba.push({b, a});
  }

  ll now = 0;
  while (SIZE(ba) > 0) {
    pair<ll, ll> i = ba.top();
    ba.pop();
    now += i.S;
    if (now > i.F) {
      PNO return 0;
    }
  }
  PYES

      return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long int
#define pb push_back
int main(){
    string tar;
    getline (cin, tar);
    if (tar[tar.length()-1]=='s') cout<<tar<<"es"<<endl;
    else cout<<tar<<"s"<<endl;
}

Measured memory_bytes: 3624
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#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;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
#define ld long double
#define ar array
#define read(A) scanf("%lld",&A);
const ll maxN=1e5+5;
ll n ;
string s ;
vector<pair<string , ll>> ans(4);
void solve(){
	cin>> n ;
	map<string,ll>mp;
	for(ll i=0;i<n ;i++){
		string s ;
		cin>> s ;
		mp[s]++;
	}
	ans[0].f="AC" , ans[1].f="WA" ,ans[2].f="TLE" , ans[3].f="RE";
	for(auto x: mp){
		if(x.f=="AC")ans[0].f=x.f , ans[0].s=x.s;
		if(x.f=="WA")ans[1].f=x.f , ans[1].s=x.s;
		if(x.f=="TLE")ans[2].f=x.f , ans[2].s=x.s;
		if(x.f=="RE")ans[3].f=x.f , ans[3].s=x.s;
	}
	for(auto x: ans)cout<<x.f<<" x "<<x.s<<endl;

}
int main(){
//	mahakal(),fast;
	ll t =1 ;
	// cin>> t ;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include<bits/stdc++.h>
using namespace std;
char s[105];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++){
		if(s[i]=='C'){
			for(int j=len-1;j>i;j--){
				if(s[j]=='F'){
					printf("Yes");
					return 0;}}}}
	printf("No");return 0;}

Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		int n=s.nextInt();

		System.out.println(INTS(n).distinct().count()==n?"YES":"NO");
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

Measured memory_bytes: 71768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  ll n,m;
  cin >> n >> m;
  vector<int> v[n];
  rep(i,m){
    int a,b; cin >> a >> b; a--; b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }

  vector<int> d(n,-1);
  d[0]=0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(auto it:v[p]){
      if(d[it] != -1){
        if(d[it]%2 == d[p]%2){
          cout << n*(n-1)/2-m << endl; return 0;
        }
      } else {
        d[it] = d[p]+1;
        q.emplace(it);
      }
    }
  }
  ll b=0,w=0;
  rep(i,n){
    if(d[i]%2){b++;}else{w++;}
  }
  cout << b*w-m << endl;
  return 0;
}

Measured memory_bytes: 6144
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
typedef pair<int, int> P;

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N;
int A[220000], B[220000];

signed main() {
    cin >> N;
    int hik = LLONG_MAX;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        if (A[i] > B[i]) hik = min(hik, B[i]);
        sum += A[i];
    }
    if (hik==LLONG_MAX)cout << 0 << endl;
    else cout << sum - hik << endl;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()

	fmt.Fprintln(stdout, n/1000*1000+b2i(n%1000 > 0)*1000-n)
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;

void Fast_Read_Out()
{
	// for fast read and out cin/cout
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
}

void Random()
{
	// it is srand(time(0)), but a little bit better
	unsigned int seed;
	asm("rdtsc" : "=A" (seed));
	srand(seed);        
}

unsigned int Time()
{
	 unsigned int time = clock() / 1000.00;
	 return time;
}

const int inf = int(1e9) + 123;

int a[101];

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif 
	Random();
	Fast_Read_Out();
	// code begins here
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	int Alice = 0, Bob = 0;
	for(int i = 1; i <= n; i++)
	{
		if(i & 1) Alice += a[i];
		else Bob += a[i];
	}
	cout << Alice - Bob << endl;
	// program execution time
	#ifdef JUDGE
//		cout << Time() << endl;
	#endif
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m,c,i,j,ans=0,s=0;
  cin>>n>>m>>c;
 int a[n][m],b[m];
  for(i=0;i<m;i++){
       cin>>b[i];
  }
  for(i=0;i<n;i++){
     for(j=0;j<m;j++){
       cin>>a[i][j];
     }
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      s+=b[j]*a[i][j];
    }
    s+=c;

    if(s>0) ans++;
    s=0;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int n;
    long long dp[410][410];
    vector<long long> v;
    
    cin>>n;
    v.resize(n+1, 0);
    
    for(int i=1;i<=n;i++)
        cin>>v[i];
    
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            dp[i][j] = 1e17;
    for(int i=1;i<=n;i++)
        dp[i][i] = 0, v[i] += v[i-1];
    
    for(int i=1;i<n;i++)
        for(int j=1;j+i<=n;j++)
            for(int u=0;u<i;u++)
                dp[j][j+i] = min(dp[j][j+i], dp[j][j+u] + dp[j+u+1][j+i] + v[j+i] - v[j-1]);
    /*
    for(int i=0;i<n;i++)
        for(int j=1;j+i<=n;j++)
            cout<<dp[j][j+i]<<" \n"[j+i == n];
    */
    cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<char, int> P;
int cnt[100001];
int sum[100001];
int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	vector<P> vec;
	char ch = S[0];
	int len = 1;
	for (int i = 1; i < N; i++) {
		if (ch != S[i]) {
			vec.emplace_back(ch, len);
			ch = S[i];
			len = 1;
		}
		else {
			len++;
		}
	}
	vec.emplace_back(ch, len);
	int M = vec.size();
	cnt[0] = (vec[0].first == '1');
	sum[0] = vec[0].second;
	for (int i = 1; i < M; i++) {
		cnt[i] = cnt[i - 1] + (vec[i].first == '1');
		sum[i] = sum[i - 1] + vec[i].second;
	}
	sum[M] = sum[M - 1];
	int ans = 0;
	for (int i = 0; i < M; i++) {
		int j = lower_bound(cnt, cnt + M, cnt[i] + K) - cnt;
		int tmp = sum[j];
		if (i > 0) tmp -= sum[i - 1];
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  vector<int> m(N);
  cin >> N >> X;
  int sum = 0;
  int mini = 1000000000;
  for(int i = 0; i < N; i++){
    cin >> m.at(i);
  }
  for(int i = 0; i < N; i++){
    sum += m.at(i);
    mini = min(mini, m.at(i));
  }
  cout << N + (X - sum)/mini << endl;
}
    
    

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll n,i,j,l,m,h,w,c,q,f,k,need,cur,a,b,ans;
    	cin>>n;
    	h=(n/500)*1000;
    	n=n-(n/500)*500;
    	h+=(n/5)*5;
    	cout<<h;
    	
    	
    	
    	
    	
    	
	}
	return 0;
}

Measured memory_bytes: 256
{
  const run = (input: string) => {
    let split = input.trim().split("\n")
    const n: number = parseInt(split[0])
    const stones: string[] = split[1].split("")

    const whites = []
    stones.forEach((v: string, i: number) => {
      if (v === 'W') whites.push(i)
    })

    let count = 0
    for (let i = 1; i <= n; i++) {
      if (stones[n - i] === 'R') {
        const v = whites.shift()
        if (v != null && v < n - i) {
          stones[v] = 'R'
          count++
        }
      }
    }

    return count
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


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

int main() {
    int N;
    cin >> N;
    int count = 0;
    int memo = 1;
    for(int i = 1; i <= N; i++) {
        int val = i;
        int times = 0;
        while(true) {
            if(val % 2 == 0) {
                val /= 2;
                times++;
            } else {
                break;
            }
        }
        if(times > count) {
            count = times;
            memo = i;
        }
    }
    cout << memo << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        ll n, m, k;
        cin>>n>>m>>k;
        string s[n];
        ifr(i, 0, n) cin>>s[i];
        ll ans = 0, cnt = 0;
        for(int i=0; i<(1ll<<n);i++) {
            for(int j=0; j<(1ll<<m);j++) {
                cnt = 0;
                ifr(xi, 0, n) {
                    if((i>>xi)&1) continue;
                    ifr(xj, 0, m) {
                        if((j>>xj)&1) continue;
                        cnt+=(s[xi][xj]=='#');
                    }
                }
                if(cnt == k) ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	llong sum=0;
	REP(i,n){
		int num=i+1;
		if(num%3 and num%5) sum+=num;
	}
	
	cout<<sum<<endl;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

UnionFind uf;

int main() {
	int n,m;
	cin >> n >> m;
	int p[n];
	uf.init(n);
	ll ans = 0;
	for (int i = 0;i < n;i++) {
		cin >> p[i];
	}
	for (int i = 0;i < m;i++) {
		int x,y;cin >> x >> y;
		uf.unite(x-1,y-1);
	}
	for (int i = 0;i < n;i++) {
		if (uf.same(i,p[i]-1)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, x;
	cin >> n >> x;
	int mn = 1e9;
	rep(i, n){
		int m;
		cin >> m;
		mn = min(mn, m);
		x -= m;
	}
	cout << n + (x / mn) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

using namespace std;

int f(int n)
{
  return n % 2 == 0 ? n / 2 : 3 * n + 1;
}

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

  vector<int> tmp;

  tmp.push_back(s);

  int i = 1;
  for(;;)
  {
    tmp.push_back(f(tmp[i-1]));

    for(int j = i-1; j >= 0; j--)
    {
      if (tmp[i] == tmp[j]) goto END;
    }
    i++;
  }
END:
  cout << i+1 << endl;
  return 0;
}


Measured memory_bytes: 256