akhauriyash/Code-Regression huggingface dataset:
/*
 ------------------------------------------------------Read question very carefully------------------------------------------------------
 
                       In every question first approach must be basic, atleast give 15 mins for try to solve in basic approach
*/
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<vector>
 #include<utility>
 #include<stdlib.h>
 #include<limits.h>
 #include<cmath>
 #include<set>
 #include<initializer_list>
 #include<unordered_set>
 #include<unordered_map>
 #include<map>
 #include<iomanip>
 #include<algorithm>
 #include<queue>
 #include<stack>
#include <cstdint>
  
 #define sze 1000005
 #define ld long double
 //#define ll unsigned long long
 #define ll long long
 #define endl "\n"
 #define pb push_back
 #define mkp make_pair
 #define mod 1000000007
 #define ff first
 #define ss second
 #define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
 #define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
 #define all(c) (c).begin(),(c).end()
 #define pi                   pair<int,int>
 #define pll                  pair<ll,ll>
 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
 using namespace std;

//cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
 //const ll inf=1ll<<60;
 //const double pi = 3.14159265358979323846;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res%mod * a%mod)%mod;
        a = (a%mod * a%mod)%mod;
        b >>= 1;
    }
    return res;
}
const ll int  N=2e5+5;
/*vector<ll> adj[N];
vector<ll> vis(N,0);
*/
//int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll n,k;
ll arr[N];
ll helper(ll x,ll curr)
{
    ll ans=0;
    F(i,1,n)
    {
        if(!curr)
        {
            ans++;
            curr^=1;
        }
        else
        {
            if(arr[i]<=x)
            {
                ans++;
                curr^=1;
            }
        }
    }
    return ans>=k;
}

 int main()
 {
     IOS;
     //int tc; cin>>tc;
     //while(tc--)
     //{
         ll n; cin>>n;
     string str;
         while(n>0)
         {
             n--;
             ll val = n%26;
             //cout<<(char)(val+'a');
             str = str +(char)(val+'a');
             n=n/26;
         }
     reverse(str.begin(),str.end());
     cout<<str<<endl;
         
     //}
 }



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{string s;
cin>>s;
int i,j,flag=1;
for(i=0;i<s.size();i++)
{if(s[i]!='h'&&s[i]!='i')
flag=0;

}
for(i=0;i<s.size()-1;i++)
{
	if(s[i]=='h'&&s[i+1]!='i')flag=0;
    if(s[i]=='i'&&s[i+1]!='h')flag=0;
}
if(s[s.size()-1]!='i')flag=0;
if(s[0]!='h')flag=0;
if(!flag)cout<<"No"<<endl;
else
cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >>n >> s;

    vector<vector<int> > dp(n, vector<int>(n, 0));
    for(int i=0; i<n; i++){
        for (int j = 0; j < n; j++){
            if(i==0 or j==0){
                if(s[i]==s[j]){
                    dp[i][j] = 1;
                }
                else {
                    dp[i][j] = 0;
                }
                continue;
            }
            if(s[i]==s[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = 0;
            }
        }
    }
    int ma = 0;
    for(int i=0; i<n; i++){
        for (int j = 0; j < n; j++){
            if(i>=j) continue;
            int now = min(dp[i][j], j-i);
            chmax(ma, now);
        }
    }
    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 98176
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main(){
	ll l, r;
	cin >> l >> r;
	r = min(r, l + 2 * 2019);
	ll ans = inf;
	for (ll i = l; i < r; i++)
	{
		for (ll j = i + 1; j <= r; j++)
		{
			ans = min(ans, (i * j) % 2019);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int strflag = 1;
  int length = s.length();
  int divnum = 0;
  for (int i = 0; i < length; i++) {
    if (i && strflag == 1 && s[i] == s[i - 1]) {
      strflag = 3;
    } else {
      divnum += 1;
      if (strflag > 1) {
        strflag -= 1;
      }
    }
  }
  cout << divnum << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    cin >> c;
    if ( c == 'a'|| c =='e'|| c == 'i'|| c =='o'|| c == 'u')
    {
        cout << "vowel" << endl;
    }  
    else
    {
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x;
	cin>>x;
	long long y=x/11;
	y=y*2;
	x=x%11;
	if(x>6)y++;
	if(x>0)y++;
	cout<<y<<endl;
	return 0;
}

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

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    int na = 0,nb = -1,nc = -1;
    char now = a[0];
    bool flag = true;
    while(flag){
        if(now == 'a') na++;
        else if(now == 'b') nb++;
        else nc++;
        if(na == a.size()){
            cout << "A" << endl;
            flag = false;
        }else if(nb == b.size()){
            cout << "B" << endl;
            flag = false;
        }else if(nc == c.size()){
            cout << "C" << endl;
            flag = false;
        }
        if(now == 'a') now = a[na];
        else if(now == 'b') now = b[nb];
        else if(now == 'c') now = c[nc];
    }

}


Measured memory_bytes: 256
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		long D = sc.nextInt();
		long X = sc.nextInt();
		
		for(int i = 0; i < 10; i++) {
			X = X * r - D;
			System.out.println(X);
		}	
	}
}

Measured memory_bytes: 21716
S = input()

flag = 0#0:r,1:l
distance = 0
ans = [0 for _ in range(len(S))]
for i in range(len(S)):
  if flag:# L mode
    if S[i] == 'R':
      r = distance//2
      l = distance -r
      ans[i-distance] += l
      ans[i-distance-1] += r
      distance = 1
      flag= 1-flag
    else:
      distance += 1
  else:# R mode
    if S[i] =='R':
      distance += 1
    else:
      r = distance//2
      l = distance -r
      ans[i-1] += l
      ans[i] += r
      distance = 1
      flag= 1-flag
else:
  ans[-1-distance] += distance//2
  ans[-distance] += distance- (distance//2)
      
print(*ans)

Measured memory_bytes: 47776
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    int h[100100];

    cin >> n;
    rep(i, n) cin >> h[i];
    h[n] = h[n + 1] = 0;

    int dp[100100];
    fill(begin(dp), end(dp), INF);
    dp[0] = 0;
    rep(i, n) {
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    }
    print(dp[n - 1]);


    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
	//return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow
	//return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));

int main() {
	ll N, M, X, ans = 1e13+7;cin >> N >> M >> X;
	vector<ll>C(N);
	vector<ll>sum(M);
	ll mon = 0;
	vector<vector<ll>> A(N, vector<ll>(M));
	for (ll i = 0;i < N;i++) {
		cin >> C[i];
		for (ll j = 0;j < M;j++) {
			cin >> A[i][j];
		}
	}
	bool ok;
	for (ll bit = 0;bit < (1 << N);bit++) {
		ok = true;
		mon = 0;
		for (ll o = 0;o < M;o++)sum[o] = 0;
		for (ll i = 0; i < N;i++) {
			if (bit & (1 << i)) {
				for (ll j = 0;j < M;j++) {
					sum[j] += A[i][j];
				}
				mon += C[i];
			}
		}
		for (ll o = 0;o < M;o++)if (sum[o] < X)ok = false;
		if (ok)ans = min(ans, mon);
	}
	if (ans == 1e13 + 7)cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int myMin(int num[], int length);

int main() {
	char S[15];
	scanf("%s", &S);

	const int N = 753;

	int absS[15];
	for (int i = 0; i < strlen(S) - 2; i++) {
		absS[i] = abs(((int)S[i]-48)*100 + ((int)S[i + 1]-48)*10 + (int)S[i + 2]-48 - N);
	}

	printf("%d", myMin(absS, strlen(S) - 2));
	
}

//---配列の最小値を求める---
int myMin(int num[], int length) {
	int temp = c_INF;
	for (int i = 0; i < length; i++) {
		temp = min(temp, num[i]);
	}
	return temp;
}



/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
bool map[8][8];
int dx[12]={-3,-2,-1,0,0,0,0,0,0,1,2,3};
int dy[12]={0,0,0,-3,-2,-1,1,2,3,0,0,0};
void BOM(int y,int x){
	map[y][x]=false;
	for(int i=0;i<12;i++)if(y+dy[i]>=0&&y+dy[i]<8&&x+dx[i]>=0&&x+dx[i]<8)if(map[y+dy[i]][x+dx[i]]==true)BOM(y+dy[i],x+dx[i]);
}
int main(){
	int v,a,b;
	char z;
	cin>>v;
	for(int u=0;u<v;u++){
		for(int i=0;i<8;i++){for(int j=0;j<8;j++){cin>>z;if(z=='0')map[i][j]=false;else map[i][j]=true;}}
		cin>>a>>b;
		BOM(b-1,a-1);
		cout<<"Data "<<u+1<<":"<<endl;
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++)cout<<map[i][j];
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 ll N;
  cin >>N;
  ll M;
  cin >>M;
  
  vl a(M);
  vl b(M);
  rep(i,M) {
    cin >>a.at(i)>>b.at(i);
  }
  vector<pl> vec(M);
  rep(i,M) {
    vec.at(i).first=a.at(i);
    vec.at(i).second=b.at(i);
  }
  
  
  sort(all(vec));
  vector<bool> B1(N);
  vector<bool> B2(N);
  rep(i,N) {
    B1.at(i)=false;
    B2.at(i)=false;
  }
  
  
  rep(i,M) {
    if(vec.at(i).first==1) {
      B1.at(vec.at(i).second-1)=true;
    }
    if(vec.at(i).second==N) {
      B2.at(vec.at(i).first-1)=true;
    }
  }
  
  ll c=0;
  rep(i,N) {
    if(B1.at(i)&&B2.at(i)) {
      cout<<"POSSIBLE"<<endl;
      c++;
      break;
    }
    
  }
  if(c==0) {
    cout<<"IMPOSSIBLE"<<endl;
  }
  
}
  
 

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#define int long long
using namespace std;
signed main() {
	int a[10];
	a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 5; a[5] = 7; a[6] = 8; a[7] = 9;
	int n;
	while (cin >> n, n) {
		string ans;
		int m = n;
		while (m > 0) {
			ans = (char)(a[m % 8] + '0') + ans;
			m /= 8;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3176
N,D = map(int,input().split())
X =[[int(i)for i in input().split()]for _ in range(N)]


def len(i,j):
    foo = 0
    for n in range(D):
        foo += (X[i][n]-X[j][n])**2
    return foo
ans = 0
for i in range(N):
    for j in range(i+1,N):
        len2 = len(i,j)
        if int(len2**0.5)**2 == len2:
            ans += 1
print(ans)


Measured memory_bytes: 3188
N = int(input())

class Position():
    def __init__(self, x, y, h):
        self.x = x
        self.y = y
        self.h = h

    def hamming_distance(self, x, y):
        return abs(self.x - x) + abs(self.y - y)

    def original_height(self, x, y):
        height = self.h + self.hamming_distance(x, y)
        if self.h == 0:
            return False, height
        else:
            return True, height

position_list = []
for _ in range(N):
    x, y, h = map(int, input().split())
    position_list.append(Position(x, y, h))

pos = [[x, y] for x in range(101) for y in range(101)]
for x, y in pos:
    H = 0
    for position in position_list:
        is_safe, h = position.original_height(x, y)
        if is_safe:
            H = h
            break
    if H < 1:
        continue
    is_correct = True
    for position in position_list:
        hamming = position.hamming_distance(x, y)
        if hamming > H and position.h == 0:
            continue
        _, original_height = position.original_height(x, y)
        if original_height != H:
            is_correct = False
            break
    if is_correct:
        print("{0} {1} {2}".format(x, y, H))
        break


Measured memory_bytes: 49264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define F first
#define S second
#define fori(l, n) for(int i = l; i < n; i++)
#define forj(k, m) for(int j = k; j < m; j++)
#define revi(h) for(int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout<<"DEBUGGING --- "<<x<<endl;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);
signed main(){
    fastio;
	// input_from_file; 
	// output_to_file;
    int n, W;
    cin>>n>>W;
    vector<ip>items(n + 1);
    fori(1, n + 1){
        int w, v;
        cin>>w>>v;
        items[i].F = w;
        items[i].S = v;
    }
    sort(all(items));
    vector<vector<int>>DP(n + 1, vector<int>(W + 1, 0));
    fori(1, n + 1)
        forj(1, W + 1){
            int w = items[i].F;
            int v = items[i].S;
            if(j >= w) DP[i][j] = max(DP[i - 1][j - w] + v, DP[i - 1][j]);
            else DP[i][j] = DP[i - 1][j];
        }
    cout<<DP[n][W]<<endl;    
} 

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;
const int N = 51 , mod = 1e9 + 7;

ll tot[N] , p[N];

ll ans(int n , ll x)
{
    if (n == 0)
        return 1;
    if (x == 1)
        return 0;
    if (x <= tot[n]/2)
        return ans(n-1 , x-1);
    if (x == tot[n]/2 + 1)
        return 1 + ans(n-1 , x-2);
    return p[n-1] + 1 + ans(n-1 , x - tot[n-1] - 2);
}

int main()
{
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n , x; cin >> n >> x;
    p[0] = 1 , tot[0] = 1;
    for (int i=1; i<N; i++)
        tot[i] = 2 * tot[i-1] + 3 , p[i] = 2 * p[i-1] + 1;
    cout << ans(n , x);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    jaldi
    int h,n;
    cin>>h>>n;
    vector<int> v(n);
    ll sum=0;
    for(int &x:v) cin>>x,sum+=x;
    sum>=h ? cout<<"Yes":cout<<"No";
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var t = input.ReadLine();

        var li = new List<string>();

        for(int i=0; i<s.Length; i++) {
            if (s.Length - i < t.Length) break;

            var ok = true;
            var sb = new StringBuilder(s);
            for(int j=0; j<t.Length; j++) {
                var ss = s[i + j];
                var tt = t[j];
                ok &= ss == tt || ss == '?';
                sb[i + j] = tt;
            }

            if (ok) {
                li.Add(sb.Replace('?', 'a').ToString());
            }
        }

        return li.Count>0 ? li.Min() : "UNRESTORABLE";
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13268
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353

def solve():
    n,s = LI()
    a = LI()
    ans = 0
    f = [0]*(s+1)
    f[0] = 0
    for i in a:
        f[0] += 1
        for j in range(s+1)[::-1]:
            nj = j+i
            if nj > s:
                continue
            f[nj] += f[j]
            f[nj] %= mod
        ans += f[s]
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 40048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
 
double n;
double pi=3.14;
 
int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    double ans=2*pi*n;
    printf("%lf",ans);
 
    return 0;
}

Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] dp = new int[n + 2];

        dp[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            int power = 1;
            dp[i] = 100100;
            while(power <= i)
            {
                dp[i] = Math.Min(dp[i], dp[i - power] + 1);
                power *= 6;
            }
        }
        for (int i = 1; i <= n; i++)
        {
            int power = 1;
            while (power <= i)
            {
                dp[i] = Math.Min(dp[i], dp[i - power] + 1);
                power *= 9;
            }
        }
        Console.WriteLine(dp[n]);
    }
}


Measured memory_bytes: 11232
#include<cstdio>
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
typedef long long ll;
ll x,y;
int ans;
int main()
{
	scanf("%lld%lld",&x,&y);
	while(x<=y)++ans,x*=2;
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    int M, N, A, B, C;
    string s1, s2;
    cin >> A;
    cout << A + A* A +A *A *A << endl;
}

Measured memory_bytes: 3616
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	int n,q;
	string cad;
	cin >> n >> cad >> q;
	set<int> s[303];

	for(int i = 0; i < n; ++i){
		s[cad[i]].insert(i);
	}

	while(q--){
		int t,l,r;
		char ch;
		cin >> t;
		if(t == 1){
			cin >> l >> ch;
			l--;
			s[cad[l]].erase(l);
			cad[l] = ch;
			s[cad[l]].insert(l);
		}else{
			cin >> l >> r;
			l--;
			int ans = 0;
			for(char ch = 'a'; ch <= 'z'; ++ch){
				auto it = s[ch].lower_bound(l);
				if(it != s[ch].end() && *it < r) ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 24220
n=int(input())
from collections import deque
queue=deque(input())
#print(queue)
#C=[0]*n
s=0
while len(queue)>1:
    a=queue.popleft()
    b=queue.pop()
    if a=='W' and b=='R':
        s+=1
        #print(s)
    elif a=='W' and b=='W':
        while queue and b=='W':
            b=queue.pop()
        if b=='R':
            s+=1
    elif a=='R' and b=='R':
        while queue and a=='R':
            a=queue.popleft()
        if a=='W':
            s+=1                
print(s)

Measured memory_bytes: 87944
import java.util.*;
import java.lang.Math.*;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int num[] = new int[3];
    int maxNum = 0;
    int sum = 0;
    int remain = 0;
    for(int i=0;i<3;i++){
      num[i] = sc.nextInt(); 
      sum += num[i];
      
      if(maxNum < num[i]){
        maxNum = num[i]; 
      }
    }

    remain = sum - maxNum;
    if(maxNum == remain){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21332
N,A,B,C,D = [int(x) for x in input().split()]
S = input()
if('##'in S[min(A,B)-1:max(C,D)]):
    print('No')
else:
    flag = False
    if((B-A)*(D-C)<0):
        if('...'in S[max(A,B)-2:min(C,D)+1]):
            flag = True
    else:
        flag = True
    if(flag):
        print('Yes')
    else:
        print('No')


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

int main() {
    string s;
    cin >> s;
    int count = 0;
    string s2 = "CODEFESTIVAL2016";
    for (int i = 0; i < 16; i++) {
        if (s[i]!=s2[i]) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import collections

def func(n, q, task):
    L = collections.deque()
    for i in reversed(task): L.appendleft(i)
    exetime = 0
    while L:
        x = L.popleft()
        if int(x[1]) > q:
            exetime += q
            x[1] = int(x[1]) - q
            L.append(x)
        else:
            exetime += int(x[1])
            print (x[0] + " " + str(exetime))

n, q = map(int, input().split(" "))
task = [input().split(" ") for _ in range(n)]
func(n, q, task)


Measured memory_bytes: 17552
s = input()
t = input()

def compare(a, b):
    dict = {}
    flag = 1
    for i in range(len(a)):
        if a[i] in dict:
            dict[a[i]].append(i)
        else:
            dict[a[i]] = [i]
    for list in dict.values():
        bvals = [b[i] for i in list]
        if bvals.count(bvals[0]) != len(bvals):
            flag = 0
            break
    return flag

res = compare(s, t) * compare(t, s)
if res:
    print("Yes")
else:
    print("No")


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

int main() {
	int n;
	while (cin >> n, n /= 4) {
		int sum = 0;
		rep(i, n) {
			int a; cin >> a;
			sum += a;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3076
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, k;

  std::cin >> N >> M;

  std::vector<std::vector<int>> s(M);

  for (int i = 0; i < M; i ++) {
    std::cin >> k;

    s[i].resize(k);
  
    for (int j = 0; j < k; j ++)
      std::cin >> s[i][j];
  }

  std::vector<int> p(M);

  for (int i = 0; i < M; i ++)
    std::cin >> p[i];

  std::vector<std::vector<int>> t(N);

  for (int i = 0; i < M; i ++)
    for (const auto& j : s[i])
      t[j - 1].push_back(i);

  int c = 0;

  for (int i = 0; i < (1 << N); i ++) {
    int x[11] = {0};
    
    for (int j = 0; j < N; j ++)
      if (i & (1 << j)) {	 // switch #i is on
        for (const auto& k : t[j])
          x[k] ++;
      }

    bool all = true;

    for (int j = 0; j < M; j ++)
      if (x[j] % 2 != p[j]) {
        all = false;

        break;
      }

    if (all)
      c ++;
  }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 504
def solve(n, m):
    ans = [-1] * n
    for _ in range(m):
        s, c = input().split()
        s = int(s) - 1
        if ans[s] == c:
            continue
        elif ans[s] == -1:
            ans[s] = c
        else:
            return -1

    if ans[0] == '0':
        if n == 1:
            return '0'
        else:
            return -1
    elif ans[0] == -1:
        if n == 1:
            return '0'
        else:
            ans[0] = '1'
    for i in range(1, n):
        if ans[i] == -1:
            ans[i] = '0'
    return ''.join(ans)

n, m = map(int, input().split())
print(solve(n, m))

Measured memory_bytes: 3064
A, B , M = map(int, input().split())
a = list(map(int, input().split()))
a_s = sorted(a)
b = list(map(int, input().split()))
b_s = sorted(b)

# cheapest
cheap = a_s[0] + b_s[0]

for i in range(M):

    # discount
    x, y, c = map(int, input().split())
    dis_cheap = a[x - 1] + b[y - 1] - c

    if cheap > dis_cheap:
        cheap = dis_cheap

print(cheap)



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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

string S;
int alph[3];

int main()
{
    cin >> S;
    REP(i, S.length()) {
        alph[S[i] - 'a']++;
    }
    int max_a = alph[0];
    int min_a = alph[0];
    REP(i, 3) {
        max_a = max(alph[i], max_a);
        min_a = min(alph[i], min_a);
    }
    if(max_a - min_a >= 2) {
        printf("NO\n");
    } else {
        printf("YES\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int niz[100005];

int b[1000005];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

	int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        cin >> niz[i];
    }
    sort(niz+1, niz+1+m);
    niz[0] = -100000000;
    for(int i=1; i<=m; i++){
        b[i] = niz[i] - niz[i-1];
    }
    ll sum = 0;
    for(int i=1; i<=m; i++){
        sum += b[i];
    }
    sort(b+1, b+1+m);
    reverse(b+1, b+1+m);
    for(int i=1; i<=n; i++){
        sum -= b[i];
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 2944
#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;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

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

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N;
    cin >> N;
    vector<ll> A(N, 0);
    REP(i, N-1){
        ll tmp;
        cin >> tmp;
        A[tmp]++;;
    }

    REP1(i, N){
        cout << A[i] << endl;
    }cout << 0 << endl;
}


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


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


int main(){
	int n,l;
	std::cin >>n>>l ;
	std::vector<string> s(n);
	for(int i = 0; i < (int)(n); i++)std::cin >> s[i];
	sort(s.begin(),s.end());
	for(int i = 0; i < (int)(n); i++)std::cout << s[i];
	std::cout << std::endl;
	
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#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> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int d=(h2-h1)*60+(m2-m1);
	cout<<max(0,d-k)<<"\n";
	return 0;
}

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

int main(){
    int D;
    cin >> D;
    if(D == 25) cout << "Christmas" << endl;
    if(D == 24) cout << "Christmas Eve" << endl;
    if(D == 23) cout << "Christmas Eve Eve" << endl;
    if(D == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_;i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define INF 10000000

int main(){
    int n,M,kotae=0;
    string s;
    cin >> n;
    map<string, int> m;
    map<string, int>::iterator ite;
    REP(i, n)
    {
        cin >> s;
        if (m.find(s) != m.end() ){
            m[s]++;
        }else{
            m.insert(make_pair(s, 1));
        }
    }
    cin >> M;
    REP(i, M)
    {
        cin >> s;
        if (m.find(s) != m.end())
        {
            m[s]--;
        }
        else
        {
            m.insert(make_pair(s, -1));
        }
    }

    for (ite = m.begin(); ite != m.end();ite++){
        kotae = max(kotae, ite->SE);
    }
    cout << kotae << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	int a,b;
	cin >> a >> b;
	int ret = max(0, a-2*b);
	cout << ret;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()) {
			String s = sc.next();
			if(s.equals("0")) {
				break;
			}
			int sum = 0;
			for(int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				int digit = c - '0';
				sum = sum + digit;
			}

			System.out.printf("%d\n", sum);
		}
	}
}


Measured memory_bytes: 26948
s=list(input())
s=s[::-1]
for i in range(len(s)):
    s[i]=int(s[i])
data=[0]
x=0
for i in range(len(s)):
    x=pow(10,i,2019)*s[i]+x
    x=x%2019
    data.append(x)
from collections import Counter
data=dict(Counter(data))
ans=0
for key in data.values():
    ans+=(key)*(key-1)//2
print(ans)

Measured memory_bytes: 103856
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=3e5+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}


int main()
{
    iosks;
    int n,ans=0;
    db len,x,y,l;
    cin>>n>>len;
    while(n--){
        cin>>x>>y;
        l=sqrt(x*x+y*y);
        if(l<len+0.000001) ans++;
    }
    cout<<ans<<endl;
    return 0;
}
/**
23
3 2 1
3 2 1

*/


Measured memory_bytes: 3832
n=int(input())
a=list(map(int,input().split()))
ans=[-1 for _ in range(n)]
for i in range(n):
  j=n-i
  if n//j<2:
    ans[j-1]=a[j-1]
  else:
    p=sum(ans[2*j-1::j])
    ans[j-1]=abs(a[j-1]-p)%2
b=[0 for _ in range(sum(ans))]
i=0
#print(ans)#######
m=sum(ans)
for j in range(n):
  if ans[j]!=1 and ans[j]!=0:
    print(-1)
    exit()
  if ans[j]==1:
    b[i]=j+1
    i+=1

print(m)
print(*b)


Measured memory_bytes: 14132
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
 
 struct Puzzle {
  int f[N2];
  int space;
  string path;
 
  bool operator < (const Puzzle &p) const {
    for(int i=0;i<N2;i++) {
      if(f[i]==p.f[i])continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};

bool isTarget(Puzzle p) {
  for(int i=0;i<N2;i++)
  if(p.f[i] != (i+1)) return false;
  return true;
}
 
string bfs(Puzzle s ) {
queue<Puzzle> Q;
map<Puzzle,bool> V;
Puzzle u,v;
s.path = "";
Q.push(s);
V[s] = true;
 
while(!Q.empty()) {
  u = Q.front();Q.pop();
  if(isTarget(u)) return u.path;
  int sx = u.space / N;
  int sy = u.space % N;
  for(int r = 0;r<4 ; r++) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0|| tx>=N || ty >= N) continue;
    v = u;
    swap(v.f[u.space], v.f[tx *N+ty]);
    v.space = tx * N + ty;
    if(!V[v]) {
      V[v] = true;
      v.path  += dir[r];
      Q.push(v);
    }
  }
}
return "unsolvable";
}
 
int main() {
  Puzzle in;
 
  for(int i=0;i<N2;i++) {
    cin >> in.f[i];
    if(in.f[i]==0) {
      in.f[i]=N2;
      in.space = i;
    }
  }
 
  string ans = bfs(in);
  cout << ans.size()<<endl;
 
  return 0;
}

Measured memory_bytes: 30540
import sys


def solve(inp):
    (K, X) = map(int, inp.readline().strip().split(' '))

    if 500 * K >= X:
        return "Yes"
    else:
        return "No"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    vector<ll> count(N + 1, 0);
    for (int x = 1; x * x < N; ++x) {
        for (int y = x; y * y < N; ++y) {
            for (int z = y; z * z < N; ++z) {
                ll val = x * x + y * y + z * z + x * y + y * z + z * x;
                // cout << x << " " << y << " " << z << " " << val << endl;
                if (val > N) continue;
                // 全部一緒
                if (x == y && y == z) {
                    count[val]++;
                }
                // 2つ一緒
                else if (
                    x == y && y != z ||
                    y == z && x != z ||
                    x == z && y != z
                ) {
                    count[val] += 3;
                }
                // 全て違う
                else {
                    count[val] += 6;
                }
            }
        }
    }

    for (int i = 1; i <= N; ++i) {
        cout << count[i] << endl;
    }
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		String s[] = new String[h];
		for (int i = 0; i < h; ++i) {
			s[i] = sc.next();
		}
		sc.close();
		for (int i = 0; i < h; ++i) {
			StringBuffer tmp = new StringBuffer();
			for (int j = 0; j < w; ++j) {
				char t = s[i].charAt(j);
				int bom = 0;
				if (t == '.') {
					for (int k = j - 1; k <= j + 1; ++k) {
						if (k < 0 || k > w - 1)
							continue;
						for (int l = i - 1; l <= i + 1; ++l) {
							if (l < 0 || l > h - 1)
								continue;
							if (s[l].charAt(k) == '#')
								bom++;
						}
					}
					tmp.append(String.valueOf(bom));
				}else {
					tmp.append(t);
				}
			}
			s[i] = tmp.toString();
		}
		for (String i : s)
			System.out.println(i);
	}
}


Measured memory_bytes: 20820
h,n=map(int,input().split())
magic=[list(map(int,input().split())) for _ in range(n)]
dp=[10**9]*(h+10**5)
#dp[i]:敵の体力をi減らすのに必要な魔力の最小値
dp[0]=0
for i in range(h):
    for damage,cost in magic:
        dp[i+damage]=min(dp[i+damage],dp[i]+cost)
ans=10**9
for i in range(10**5):
    ans=min(ans,dp[i+h])
print(ans)

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

int main() 
{
    int n , q;
    long long a , b , c , dec[100001] = {};
    long long ans = 0;
    
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> a;
        dec[a] ++;
        
        ans += a;
    }
    cin >> q;
    
    for(int i=0 ;i<q ;i++ ){
        cin >> b >> c;
        ans = ans - dec[b] * b + dec[b] * c;
        
        dec[c] += dec[b];
        dec[b] = 0;
        
        cout << ans << endl;
    }
    
    return (0);
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;



const ll MAX_V = 400;  // 最大頂点数(制約に従う)
ll d[MAX_V][MAX_V];  // 全体をINF、d[i][i]を0に初期化(d[i][j]:=iからjへの最短距離)
// 初期化
// FILL(d, INF);
// rep(i, V) d[i][i] = 0;  // V: 実際の頂点数


// 0-basedに注意
void warshall_floyd(ll V){  // 実際の頂点数
    // 経由頂点, 始点, 終点
    rep(k, V) rep(i, V) rep(j, V) chmin(d[i][j], d[i][k] + d[k][j]);
}



int main(){
    ll h, w; cin >> h >> w;
    ll V = h*w;
    vector<string> maze(h);
    rep(i, h) cin >> maze[i];
    FILL(d, INF);
    rep(i, V) d[i][i] = 0;
    rep(hi, h){
        rep(wi, w){
            if(maze[hi][wi] == '#') continue;
            rep(i, 4){
                ll nh = hi + dy[i], nw = wi + dx[i];
                if(0 <= nh && nh < h && 0 <= nw && nw < w && maze[nh][nw] == '.') d[hi*w + wi][nh*w + nw] = d[nh*w + nw][hi*w + wi] = 1;
            }
        }
    }
    warshall_floyd(V);
    ll ans = -1;
    rep(hi, h){
        rep(wi, w){
            if(maze[hi][wi] == '#') continue;
            ll cnt = -1;
            rep(i, h){
                rep(j, w){
                    if((hi == i && wi == j) || maze[i][j] == '#') continue;
                    chmax(cnt, d[hi*w + wi][i*w + j]);
                }
            }
            chmax(ans, cnt);
        }
    }
    cout << ans << endl;
}


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

map<int, int> s;

int main(void)
{
	//freopen("abc.in", "r", stdin);
	int n,a;
	bool flag=1;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a);
		if (flag&&!(a & 01)&& a % 5 && a % 3)
				flag = 0;
	}
	if (flag)
		printf("APPROVED");
	else
		printf("DENIED");
	
}

Measured memory_bytes: 256