akhauriyash/Code-Regression huggingface dataset:
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
string s,t;
cin>>s>>t;
int a,b;
cin>>a>>b;
string u;
cin>>u;
if(u==s)
	cout<<a-1<<" "<<b;
else
	cout<<a<<" "<<b-1;
}
int main()
{
//code
	
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);
    const int nums[] ={4,6,9,11};

    int xy[2]; cin >>xy[0]>>xy[1];
    int g[2];
    rep(i,2) {
        if (xy[i]==2) g[i]=3;
        else if (find(ALL(nums),xy[i])!=end(nums)) g[i]=2;
        else g[i]=1;
    }
    Yes(g[0]==g[1]);
}


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

const long long INF = 1000000000000;

int N, W;
int w[110], v[110];

long long dp[110][100100];

int main() {
    cin >> N >> W;
    for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < 100100; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 100100; j++) {
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + w[i]);
        }
    }

    int ans;
    for (int i = 100000; i >= 0; i--) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }

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

Measured memory_bytes: 80128
w, h = map(int, input().split())
p = [int(input()) for _ in range(w)]
q = [int(input()) for _ in range(h)]
ans = sum(p) + sum(q)
p.sort(reverse = True)
q.sort(reverse = True)
i = 0
for j in range(w):
    while True:
        if i == h:
            break
        if p[j] >= q[i]:
            break
        i += 1
    ans += i * p[j]
i = 0
for j in range(h):
    while True:
        if i == w:
            break
        if q[j] > p[i]:
            break
        i += 1
    ans += i * q[j]
print(ans)

Measured memory_bytes: 17328
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		String buf;
		buf=sc.nextLine();
		
		int a=Integer.parseInt(buf.split(" ")[0]);
		int b=Integer.parseInt(buf.split(" ")[1]);
		
		int x=0;
		
		if(a==0){
			x=1;
			if(b<100){
				System.out.println(b);
			}else{
				System.out.println(101);
			}
		}else if(a==1){
			x=100;
			if(b<100){
				System.out.println(x*b);
			}else{
				System.out.println(100*101);
			}
		}else if(a==2){
			x=10000;
			if(b<100){
				System.out.println(x*b);
			}else{
				System.out.println(1010000);
			}
		}
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <set>

using namespace std;

int main()
{
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    set<int> val;
    for (int i = 0; i < N; ++i) {
        val.insert(d[i]);
    }
    cout << val.size() << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
#define N 200002 
char a[N];
int ans;
int f[N][3];
int main()
{
	//freopen("divide.out","w",stdout);
    //freopen("divide.in","r",stdin);
    scanf("%s",a+1);
    int n=strlen(a+1),t=2;
    f[1][1]=1;
    f[1][2]=1;
    for(int i=2;i<=n;i++)
    {
    	if(a[i]!=a[i-1])f[i][1]=f[i-1][1]+1;
    	f[i][1]=max(f[i-2][2]+1,f[i][1]);
    	if(a[i]!=a[i-2]||a[i-1]!=a[i+1])f[i][2]=max(f[i][2],f[i-2][2]+1);
		f[i][2]=max(f[i][2],f[i-1][1]+1);
	}
	printf("%d",f[n][1]);
}

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

long long n,m,r;

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

    cin>>n>>m;
    if(n>=3&&m>=3)
        cout<<(n-2)*(m-2)<<endl;
    else if(n==2||m==2)
        cout<<0<<endl;
    else if(n==1&&m>2)
        cout<<m-2<<endl;
    else if(m==1&&n>2)
        cout<<n-2<<endl;
    else cout<<1<<endl;


    return 0;
}


Measured memory_bytes: 3544
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

struct segtree{
	int n;
	vector<ll> seg;

	segtree(int _n){ n = _n, seg.resize(n << 1); }

	void update(int i, ll v){
		for(ckmax(seg[i += n], v), i >>= 1; i; i >>= 1)
			seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
	}

	ll query(int l, int r){
		ll m = 0;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1) ckmax(m, seg[l++]);
			if(r & 1) ckmax(m, seg[--r]);
		}
		return m;
	}
};

namespace ioUtils {

    char vector_delimiter = ' ';

    template<typename T>
    istream& operator >>(istream&, vector<T>&);

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

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

    template<typename T>
    ostream& operator <<(ostream&, vector<T>&);

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

    template<typename T>
    ostream& operator <<(ostream& os, vector<T>& v){
        for(auto&& e : v) os << e << vector_delimiter;
        return os;   
    }   
}

using namespace ioUtils;

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    int N;
    cin >> N;
    vi h(N), a(N);
    cin >> h >> a;
    segtree dp(N);

   	rep3(i, N - 1, 0, -1) dp.update(h[i] - 1, a[i] + dp.query(h[i], N));

   	cout << dp.query(0, N) << '\n';

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


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

int main(){

    int N;
    cin >> N;
    vector<int>vec(N+1);
    int tmp = 1;
    for(int i=1; i<=N; i++){
        cin >> vec[i];
        if(abs(vec[i]) > abs(vec[tmp]))tmp = i;
    }
    cout << 2 * N - 1 << endl;
    for(int i=1; i<=N; i++){
        cout << tmp << " " << i << endl;
    }
    if(vec[tmp]>0){
        for(int i=1; i<N; i++){
            cout << i << " " << i+1 << endl;
        }
    }
    else{
        for(int i=N; i>1; i--){
            cout << i << " " << i-1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int A[n + 1];
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int k = 1; k <= m; k++)
    {
        for(int i = 0; i < n - 1; i++)
        {
            if(A[i] % k > A[i + 1] % k) swap(A[i], A[i + 1]);
        }
    }
    for(int i = 0; i < n; i++) cout << A[i] << endl;
    return 0;
}




Measured memory_bytes: 3172
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
main(){
  int n;
  while(cin>>n && n>=0){
    int ans =1150;
    int tmp=n;
    int val=n-10;
    if (n >=10){
      if (n>=20)ans+=10*125;
      else ans+=(n-10)*125;
    }
    if (n >=20){
      if (n>=30)ans+=10*140;
      else ans+=(n-20)*140;
    }
    if (n >= 30)ans+=(n-30)*160;
    cout << 4280-ans << endl;
  }
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int N;
	cin >> N;
	int odd = 0;
	rep(i, N) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			odd++;
		}
	}
	if (odd % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF INT_MAX
#define INFLL _I64_MAX
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	int ans=0;

	long long x, y, i, prev=1;

	cin>>x>>y;

	i=x;
	while(i<=y){
		if(i<=y) ans++;
		i=i<<1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
global S,ans

def check_at(i):
  global S,ans

  if ans[i] == "S":
    if (S[i] == "o" and ans[i-1] != ans[i+1]) or (S[i] == "x" and ans[i-1] == ans[i+1]):
      return True
  else:
    if (S[i] == "o" and ans[i-1] == ans[i+1]) or (S[i] == "x" and ans[i-1] != ans[i+1]):
      return True

N = int(input())
S = input()

opposite = {"S": "W",
            "W": "S"}

for ans in ["SS","SW","WS","WW"]:
  for i in range(1,N-1):
    if ans[i] == "S" and S[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and S[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "o":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "x":
      ans += ans[i-1]
  
  if (not check_at(-1)) and (not check_at(0)):
    print(ans)
    break
else:
  print(-1)

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

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << n * n * n;
	return 0;
}

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

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	int a[h][w];
	for(int i=0; i<h; i++){
		char s[w+1];
		scanf("%s", s);
		for(int j=0; j<w; j++) a[i][j] = (s[j]=='#');
	}

	bool skipr[h], skipc[w];
	memset(skipr, 0, sizeof(skipr));
	memset(skipc, 0, sizeof(skipc));

	for(int i=0; i<h; i++){
		bool skip = true;
		for(int j=0; j<w; j++){
			if(a[i][j]==1) skip = false;
		}
		if(skip) skipr[i] = true;
	}

	for(int j=0; j<w; j++){
		bool skip = true;
		for(int i=0; i<h; i++){
			if(a[i][j]==1) skip = false;
		}
		if(skip) skipc[j] = true;
	}
	
	for(int i=0; i<h; i++) if(!skipr[i]) {
		for(int j=0; j<w; j++) if(!skipc[j]) {
			if(a[i][j]) putchar('#');
			else putchar('.');
		}
		putchar('\n');
	}
	return 0;		
}


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

using namespace std;

typedef long long LL;

const int inf = 1 << 26;

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(b-a == c-b) puts("YES");
	else puts("NO");

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
  int D;
  scanf("%d\n",&D);
  if(D==25)
    printf("Christmas\n");
  else if(D==24)
    printf("Christmas Eve\n");
  else if(D==23)
    printf("Christmas Eve Eve\n");
  else if(D==22)
    printf("Christmas Eve Eve Eve\n");

	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> v(n);
  REP(i, n) {
    cin >> v.at(i);
    sum += v.at(i);
  }
  sort(v.begin(), v.end(), greater<int>());
  
  float lim = sum / (4.0 * m);
  int count = n;
  REP(i, n) {
    if (v.at(i) < lim) {
      count = i;
      break;
    }
  }
  
  if (count >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b

N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
cnt = [0]*N

for i in range(N):
    t = b[i]
    
    while t%2==0:
        cnt[i] += 1
        t //= 2
    
if cnt!=[cnt[0]]*N:
    print(0)
    exit()

L = 1

for bi in b:
    L = lcm(L, bi)

if L>M:
    print(0)
else:
    print((M-L)//(2*L)+1)

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


int main() {
    int N, A;
    cin >> N;
    map<int, int> mp;
    rep(i,N) {
        cin >> A;
        mp[A] = i + 1;
    }
    for (auto x : mp) {
        cout << x.second << " ";
    }
}


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

//関数
    //const long INF=1000000000000000;
    
//main関数
int main() {
    
    
    //入力
    long N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    
    
    
    //計算
    bool possible=false;
    
    for(int k=0;k<=N-1;k++){
        if(B-A+k*C-(N-1-k)*D<=0 && 0<=B-A+k*D-(N-1-k)*C){
            possible=true;
            //cout<<k<<endl;
        }
    }
    
    //出力
    if(possible){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
from collections import deque
n,m = map(int, input().split())
V = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)
ans = [-1]*(n+1)
q = deque()
q.append(1)
while len(q):
    p = q.popleft()
    for c in V[p]:
        if c > 1 and ans[c] < 0:
            ans[c] = p
            q.append(c)
print('Yes')
for i in range(2,n+1): print(ans[i])


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

int main(void) {
    long long N;
    cin >> N;
    vector< long long > B(N);
    for (int i = 0; i < N - 1; ++i) {
        cin >> B[i];
    }
    long long sum = B[0];
    for (int i = 1; i < N - 1; ++i) {
        sum += min(B[i], B[i - 1]);
    }
    sum += B[N - 2];
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
a = [list(map(str, list(input()))) for i in range(H)]

DP = [[0] * W for i in range(H)]

DP[0][0] = 1

Big = 1000000007

for i in range(H):
    for j in range(W):

        if DP[i][j] == 0 and a[i][j] == ".":
            up = 0
            le = 0

            if i > 0 and a[i - 1][j] == ".":
                up = DP[i - 1][j]
                
            if j > 0 and a[i][j - 1] == ".":
                le = DP[i][j - 1]

            DP[i][j] = ((up % Big) + (le % Big)) % Big           
            
print(DP[H-1][W-1])



Measured memory_bytes: 91612
data = input().split(" ")
n = int(data[0])
k = int(data[1]) 
a = list(map(int, input().split(" ")))
left = 0
right = 0
for i in range(0, n):
	for j in range(0, i):
		if a[j] < a[i]:
			left += 1
	for j in range(i+1, n):
		if a[j] < a[i]:
			right += 1

rt = ((k + 1) * k // 2) % 1000000007
lt = ((k - 1) * k // 2) % 1000000007
ans = (right * rt + left * lt) % 1000000007
print(ans)

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

long long n, a, b;
vector<long long> h;

long long solve();
bool ch(long long x);

int main() {
  cin >> n >> a >> b;
  a -= b;
  for(int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    h.push_back(x);
  }
  sort(h.begin(), h.end(), greater<long long>());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long l = 0, r = 1000000000, now = 0;
  while(r > l) {
    now = (r + l) / 2;
    if(r - l <= 1) {
      if(ch(l))
        now = l;
      else if(ch(r))
        now = r;
      else
        now = r + 1;
      break;
    }
    if(ch(now))
      r = now;
    else
      l = now;
  }
  return now;
}

bool ch(long long x) {
  long long cnt = 0;
  for(int i = 0; i < n; ++i) {
    long long at = h[i] - b * x;
    if(at > 0) cnt += (at + a - 1) / a;
    if(cnt > x) return 0;
  }
  return 1;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  vector<ll> B(N+1,-1);
  B[1]=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  ll mae=0;
  ll count=1;
  ll now=1;
  while(true){
    if(B[A[now-1]]>=0){
      mae=B[A[now-1]];
      count=count-B[A[now-1]];
      break;
    }
    B[A[now-1]]=count;
    now=A[now-1];
    count++;
  }
  if(K>mae){
    K=mae+((K-mae)%count);
  }
  if(K==0){
    cout << 1 << endl;
    return 0;
  }
  ll ans=1;
  for(int i=0;i<K;i++){
    ans=A[ans-1];
  }
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 6428
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;

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

	int n, m;
	cin >> n >> m;

	vector<int> p(m), y(m);
	FOR(i, 0, m) {
		cin >> p[i] >> y[i];
		p[i]--;
	}

	//cout << "p:" << endl;
	//FOR(i, 0, m) cout << p[i] << endl;
	//cout << endl;

	//cout << "y:" << endl;
	//FOR(i, 0, m) cout << y[i] << endl;
	//cout << endl;

	vector<vector<int>> vals(n);
	FOR(i, 0, m) vals[p[i]].push_back(y[i]);

	//cout << "vals:" << endl;
	//FOR(v, 0, n) {
	//	FOR(j,0,vals[v].size()) cout << vals[v][j] << ", ";
	//	cout << endl;
	//}
	//cout << endl;

	//各pに対してソート
	FOR(v, 0, n) {
		sort(vals[v].begin(), vals[v].end());

		//ダブリなくす(今回は不要)
		auto iter1 = unique(vals[v].begin(), vals[v].end());
		vals[v].erase(iter1, vals[v].end());
	}

	FOR(i, 0, m) {
		int v = p[i];

		//前半部
		printf("%06d", v + 1);

		//後半部
		//vals[v]の中からy[i]以上の値が出てくる最初のイテレータを返す
		auto iter2 = lower_bound(vals[v].begin(), vals[v].end(), y[i]);
		int id = iter2 - vals[v].begin();

		printf("%06d\n", id + 1);
	}

}

Measured memory_bytes: 7808
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	int cnta = 0, cntb = 0, cntc = 0, cntd = 0;
	char a[4];
	for (int i = 0; i < 4; i++)cin >> a[i];
	for (int i = 0; i < 4; i++) {
		if (a[i] == '1')cnta++;
		else if (a[i] == '9')cntb++;
		else if (a[i] == '7')cntc++;
		else if (a[i] == '4')cntd++;
	}
	if (cnta == 1 && cntb == 1 && cntc == 1 && cntd == 1)puts("YES");
	else puts("NO");
	ll
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

/**
 * @brief UnionFind Tree
 * @note O(α(N))
 */
struct UnionFind{
private:
  vector<int> par, rank, sizes;
public:
  UnionFind(int n) : par(n, -1), rank(n, 0), sizes(n, 1){}
  int find(int x) { return (par[x] < 0) ? x : (par[x] = find(par[x])); }
  bool unite(int x, int y){
    x = find(x), y = find(y);
    if(x==y) return false;
    else if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    } else if(rank[x]>rank[y]){
      par[y] = x;
      sizes[x] += sizes[y];
    } else{
      par[y] = x;
      rank[x] += 1;
      sizes[x] += sizes[y];
    }
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
};

int main() {
  int n, m; cin>>n>>m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b; cin>>a>>b;
    --a; --b;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n) {
    ans = max(ans, uf.size(i));
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 5572
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

ans=[[0]*W for _ in range(H)]
p=[0,0]
for i in range(N):
    cnt=a[i]
    while cnt>0:
        ans[p[0]][p[1]]=i+1
        if p[1]%2==0:
            if p[0]==H-1:
                p[1]+=1
            else:
                p[0]+=1
        else:
            if p[0]==0:
                p[1]+=1
            else:
                p[0]-=1
        cnt-=1

for i in range(H):
    print(*ans[i])

Measured memory_bytes: 3828
/*AOJ 0029*/

#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){

	vector<string> data;

	char str[35];

	while(cin>>str){
		data.push_back(str);
	}

	int max=0;
	int max1 = 0;
	int maxNum = 0;
	int maxNum1 = 0;
	int sum=0;

	for(int i=0;i<data.size();i++){
		sum = 0;
		for(int j=i+1;j<data.size();j++){
			if(data.at(i) == data.at(j)){
				sum++;
			}
		}
		if(max<=sum){
			max = sum;
			maxNum = i;
		}
	}

	max1 = 0;
	maxNum1 = 0;

	for(int i=0;i<data.size();i++){
		if(max1 <= data.at(i).size()){
			max1 = data.at(i).size();
			maxNum1 = i;
		}
	}



	cout<<data.at(maxNum)<<" "<<data.at(maxNum1)<<endl;

	return 0;
}

Measured memory_bytes: 0
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int dat[105];

int main(){
    int n; scanf("%d", &n);
    dat[1] = dat[n+1] = INF;
    REP(i,2,n) scanf("%d", dat+i);
    //
    int res = 0;
    REP(i,1,n) res += min(dat[i], dat[i+1]);
    //
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    var x = 1
    for (i in 1..n) {
        if (x < k) {
            x *= 2
        } else {
            x += k
        }
    }
    println(x)
}


Measured memory_bytes: 31864
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int A[1001];
	int num;
	for(int i=0;i<1001;i++){
		A[i] = 0;
	}

	cin >>num;
	
	for(int i=0;i<num;i++){
		scanf("%d",&A[i]);
	}
	void insertionSort(int* A,int N);//A[]はポインタ渡し
	insertionSort(A,num);

	return 0;
}

void insertionSort(int* A,int N){
	int v,j;

	for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;

	for(int i=1;i<N;i++){
		v = A[i];
		j = i -1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
	}
}

Measured memory_bytes: 1248
/*
  Vivek Rathi
  CSE 3rd Year
  MNNIT
  THUMB RULE - THINK FOR DP FIRST AND THEN GREEDY!!!
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define sz(x)	(ll)x.size()
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#define endl '\n'
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
//shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above-----------------------------------------------
vector<ll> v[200001];
ll visited[200001];
ll dfs(ll ver)
{	
	if(visited[ver]!=0)
		return 0;
	visited[ver]=1;
	ll ans=1;
	for(ll i=0;i<v[ver].size();i++)
	{
		ans+=dfs(v[ver][i]);
	}
	return ans;
}
int main()
{
	boost
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	ll maxi=0;
	for(ll i=1;i<=n;i++)
	{
		if(visited[i]==0)
		{
			maxi=max(maxi,dfs(i));
		}
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 22264
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include<iostream>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
  int N; cin >> N;
  int A[N];
  rep(i, N)cin >> A[i];
  map <int, int> num;
  rep(i, N){
    if (num.find(A[i]) == num.end()){
      num[A[i]] = 1;
    }
  }
  int ans = 0;
  int rest = 0;
  for (auto itr = num.begin(); itr != num.end(); itr++){
    ans ++;
  }
  if (ans % 2 == 0) ans-=1;
  cout << ans << endl;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

    // int N;
    // cin >> N;
    // vector<int> a(N);
    // REP(i, N){
    //     cin >> a[i];
    // }
    // string s;
    int count = 0;
    vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    // s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
    int K; cin >> K;
    // REP(i, s.length()){
    //     if(s[i] == ','){
    //         count++;
    //         // cout << count;
    //     }
    //     if(count == K){
    //         cout << s[i-1] - '0' << endl;
    //         break;
    //     }
    // }
    cout << s[K-1] << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000000;
ll INF=1e18;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     ll a,b,c,d;
     cin>>a>>b>>c>>d;
     ll ans=b*d;
     ans=max(ans,c*a);
     ans=max(ans,c*b);
     ans=max(ans,a*d);
     cout<<ans;
}

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


Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

long long int N,M,K,L,R,H,W;

const long long int MOD=1000000007;

int main(){
	while(cin>>N,N){
		M=0;
		for(int i=2;i<=N;i++){
			if((N*2)%i)continue;
			K=N*2/i;
			R=K+i-1;
			if(R&1)continue;
			R/=2;
			L=R-i+1;
			if(R+L==K&&L>=1)M++;
		}
		cout<<M<<endl;
	}
	
	return 0;
}


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

int main() {
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a >= 0) {
    if(d >= 0) {
      cout << b * d << endl;
    }
    else {
      cout << a * d << endl;
    }
  }
  else if(b >= 0) {
    if(c >= 0) {
      cout << b * d << endl;
    }
    else if(d >= 0) {
      cout << max(a * c, b * d) << endl;
    }
    else {
      cout << a * c << endl;
    }
  }
  else {
    if(c <= 0) {
      cout << a * c << endl;
    }
    else {
      cout << b * c << endl;
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main(){
  int x;
  cin>>x;
  int n=x%10;
  if(n==3)
    cout<<"bon"<<endl;
  else if(n==0||n==1||n==6||n==8)
    cout<<"pon"<<endl;
  else if(n==2||n==4||n==5||n==7||n==9)
    cout<<"hon"<<endl;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


void solve(){
    int n, Y;
    cin >> n >> Y;
    Y /= 1000;

    
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if ((n-i-j >=0) && (9*i+4*j+n == Y)) {
                cout << i << " " << j << " " << n-(i+j) << endl;
                return;
            }
        }
    }
    
    cout << -1 << " " << -1 << " " << -1 << endl;
    return;
    
}

int main(int argc, char const* argv[])
{
    solve();

    return 0;
}


Measured memory_bytes: 256
import copy
#n桁の二進数の作成

n = int(input())
def makebin(n):

  ans = []
  for i in reversed(range(2 ** n)):
    tmp = bin(i)
    ans.append(tmp[2:].zfill(n))
  return ans
binData = makebin(n)

#入力値処理

data = {}
for i in range(n):
  a = int(input())
  alist = []
  for j in range(a):
    #タプルの生成
    x,y = list(map(int,input().split()))
    alist.append((x,y))
  #data[i] == タプルのリスト
  data[i] = alist[:]

#2進データとの比較

#2進データの要素についてループ
answer = []
flag = 1
for i in binData: #binData:n桁のbinaryのリスト
  #binaryの情報をmemoにコピー
  memo = []
  for k in range(n):
    memo.append(i[k])
  flag = 1 #flag == 0 : そのbinaryリストは矛盾
  #n文字の2進数についてループ
  for j in range(n):
    
    
    s = i[j]
    t = memo[j]
    #j番目の人がkindであるとき i:n桁のbinaryリスト
    if i[j] == '1':
      #自分自身をkindとしてmemo
      memo[j] = '1'
      #データと照合してmemoに書き込み
      #証言に矛盾がないかの分岐 
      #j番目の証言に対してループ
      for test in data[j]:
        #矛盾が生じた場合
        if (memo[test[0]-1] == '1' and test[1] == 0 ) or \
          (memo[test[0]-1] == '0' and test[1] == 1):
          flag = 0
          memo = ['0'] * n
          break

        else:
          memo[test[0]-1] = str(test[1])
      if flag == 0:
        break
    #binaryリストに対して矛盾が生じなかった場合  
  if j == n-1:
    answer.append(memo.count('1'))
print(max(answer))









Measured memory_bytes: 6140
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> m;
#pragma endregion

int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

ll dp[10001];
int main() {
  cin >> H >> N;
  ll a[1000], b[1000];
  rep(i, N){
    cin >> a[i] >> b[i];
  }
  dp[0] = 0;
  rep(i, H){
    dp[i+1] = 10000000000ll;
  }
  for(int i=1;i<=H;i++){
    rep(j, N){
      dp[i] = min(dp[i], dp[max(0ll, i - a[j])] + b[j]);
    }
  }
  cout << dp[H];
}



Measured memory_bytes: 384
#include<iostream>
#include<cmath>

using namespace std;

int func(int num)
{
	int sum = 0;

	while(num > 0)
	{
		sum += num%10;
		num /= 10;
	}

	return sum; 
}

int main()
{
	int N;
	int ans = 100000;

	cin >> N;

	for(int i=1;i<N;i++)
	{
		ans = min(func(i)+func(N-i),ans);
	}

	cout << ans;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  string s;
  cin >> s;
  string t = "abcdefghijklmnopqrstuvwxyz";
  sort(s.begin(), s.end());
  char ans = ' ';
  bool ok;
  for (int i = 0; i < t.length(); ++i) {
    ok = true;
    for (int j = 0; j < s.length(); ++j) {
      if (t[i] == s[j]) ok = false;
    }
    if (ok) {
      ans = t[i];
      break;
    }
  }

  if (ok == false)
    cout << "None";
  else
    cout << ans;

  return 0;
}



Measured memory_bytes: 3716
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846

// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=b*d;
    ans=max(ans,b*c);
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    cout<<ans;
} 

Measured memory_bytes: 3652
# ALDS1_12_B: Single Source Shortest Path 1

class Graph
  def initialize(n_v)
    @n_v   = n_v
    @costs = Array.new(n_v) { Hash.new }
  end
 
  def connect(v_from, v_to, cost)
    @costs[v_from][v_to] = cost
  end
 
  def calc_min_costs_from(v_start)
    costs_from_start = Array.new @n_v, Float::INFINITY
    visiting = {}
    costs_from_start[v_start] = 0
    visiting[v_start] = 0
 
    while visiting.any?
      v_from, _ = visiting.min_by do |v, _|
        costs_from_start[v]
      end
      visiting.delete v_from

      @costs[v_from].each do |v_to, cost|
        through_cost = costs_from_start[v_from] + cost
        if through_cost < costs_from_start[v_to]
          costs_from_start[v_to] = through_cost
          visiting[v_to] = true
        end
      end
    end
    
    costs_from_start
  end
end
 
# Read input.
n_v   = gets.to_i
graph = Graph.new(n_v)
n_v.times do
  v_from, n_degs, *inputs = gets.split.map &:to_i
  1.step(n_degs * 2, 2) do |i|
    v_to, cost = inputs[i - 1], inputs[i]
    graph.connect v_from, v_to, cost
  end
end

graph.calc_min_costs_from(0).each_with_index do |cost, idx|
  puts "#{idx} #{cost}"
end

Measured memory_bytes: 8980
#pragma GCC optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#define INF 0x3f3f3f3f
#define NO 105
#define MO 10005
#define P 1000000007
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define lln putchar('\n')
typedef long long ll;
typedef double db;
using namespace std;
typedef pair<int, int> pii;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

//variable

void init()
{
	int a = read(), b = read();
    for (int i = b - a + 1; i <= b + a - 1; i++)
        cout << i << ' ';
    cout << endl;
}
//functions

int main()
{
	init();
	return 0;
}
//main

Measured memory_bytes: 256