akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


#include<unordered_map>
class HashVI {  // ???????????\??¢??°???????????§??????
public:
	size_t operator()(const vector<vector<int>> &x) const {
		size_t t = 0;
		int num = 1;
		int two;
		for (int i = 0; i != x.size(); ++i) {
			for (int j = 0; j < x[i].size(); ++j) {
				if (x[i][j] == 2) {
					two = i * 5 + j;
				}
				else {
					t = t + num*x[i][j];
				}
				num *= 2;
			}
		}
		t += num*two;
		return t;
	}
};

unordered_map<vector<vector<int>>, int,HashVI>mp;

struct aa {
	int nx;
	int ny;
	vector<vector<int>>afield;
	int time;
};
int N;
int dx[8] = { -1,-1,-1, 0, 1, 1, 1, 0 };
int dy[8] = { -1, 0, 1, 1, 1, 0,-1,-1 };
bool ok(int x, int y) {
	return x >= 0 && x < N&&y >= 0 && y < N;
}
int ans;
vector<vector<int>>update(int newx, int newy, const vector<vector<int>>& nowf) {
	vector<vector<int>>newf(N, vector<int>(N));
	bool aok = true;
	newf[newy][newx] = 2;
	for (int ay = 0; ay < N; ++ay) {
		for (int ax = 0; ax < N; ++ax) {
			if (ay == newy&&ax == newx) {
				continue;
			}else {
				int vnum = 0;
				for (int d = 0; d < 8; ++d) {
					int newax = ax + dx[d];
					int neway = ay + dy[d];
					if (ok(newax, neway) && (nowf[neway][newax]==1||newf[neway][newax]==2)) {
						vnum++;
					}
				}
				if (vnum == 2 && nowf[ay][ax] == 1) {
					newf[ay][ax] = 1;
					aok = false;
				}
				else if (vnum == 3) {
					newf[ay][ax] = 1;
					aok = false;
				}
				else {
					newf[ay][ax] = 0;
				}
			}
		}
	}
	if (aok) {
		throw(0);
	}
	return newf;
}
int main() {
	while (1) {
		ans = -1;
		mp.clear();
		cin >> N;
		int sx, sy;
		vector<vector<int>>field(N, vector<int>(N));
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			for (int j = 0; j < N; ++j) {
				if (st[j] == '@') {
					sx = j; sy = i;
					field[i][j] = 2;
				}
				else if (st[j] == '#')field[i][j] = 1;
			}
		}
		mp[field] = 0;
		bool aaok = true;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (field[i][j] == 1) {
					aaok = false;
				}
			}
		}
		if (aaok) {
			cout << 0 << endl;
			continue;
		}
		queue<aa>que;
		que.push({ sx,sy,field,0 });
		while (que.size()) {
			aa atop(que.front());
			que.pop();
			int nowx = atop.nx;
			int nowy = atop.ny;
			auto nowf = atop.afield;

			try {
				for (int i = 0; i < 8; ++i) {
				int newx = nowx + dx[i];
				int newy = nowy + dy[i];
				if (ok(newx, newy) && nowf[newy][newx]==0) {
						vector<vector<int>>newf(update(newx, newy, nowf));
						if (mp.find(newf) == mp.end()) {
							mp[newf] = atop.time + 1;
							que.push(aa{ newx,newy,newf,atop.time + 1 });
						}
					}
				}
			}
			catch (...) {
				ans = atop.time + 1;
				break;
			}
		}
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 6448
def sub():
    N = int(input())
    hs = [int(e) for e in input().split()]
    optimal_values = [None for _ in range(N)]
    optimal_values[0] = 0
    for i in range(1, N):
        if i > 1:
            a = optimal_values[i - 1] + abs(hs[i] - hs[i - 1])
            b = optimal_values[i - 2] + abs(hs[i] - hs[i - 2])
            optimal_values[i] = min(a, b)
        else:
            optimal_values[i] = optimal_values[i - 1] + abs(hs[i] - hs[i - 1])
    print(optimal_values[-1])


sub()


Measured memory_bytes: 13976
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int ans = getAnswer(A,B,C) ;
		System.out.println(ans);
	}

	public int getAnswer(int A, int B, int C) {
		int ans = 0 ;
		int amari = A - B ;

		if(amari < C) {
			ans = C - amari ;
		}else {
			ans = 0 ;
		}

		return ans ;
	}

}


Measured memory_bytes: 21844
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] bits = new int[n + 1];
        for(int i = 1; i <= n; i++){
            int sum = 0;
            for(int j = 0; j < 10; j++){
                sum *= 2;
                sum += sc.nextInt();
            }
            bits[i] = sum;
        }
        int[][] pro = new int[n + 1][11];
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= 10; j++){
                pro[i][j] = sc.nextInt();
            }
        }
        sc.close();
        int max = -1000000000;
        for(int i = 1; i < 1024; i++){
            int sum = 0;
            for(int j = 1; j <= n; j++){
                sum += pro[j][Integer.bitCount((i & bits[j]))];
            }
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 25684
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MOD (998244353)

ll mypow(ll n, ll k) {
	ll ret = 1;
	ll cur = n;
	while (k) {
		if (k & 1) {
			ret *= cur;
			ret %= MOD;
		}
		cur *= cur;
		cur %= MOD;
		k >>= 1;
	}
	return ret;
}

#define MAXN (1 << 20)

int a[MAXN], d[MAXN];
int n;


int main() {
	cin >> n;
	int mmax = 0;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[t]++;
		d[i] = t;
		mmax = max(mmax, t);
	}
	if ((a[0] != 1) || (d[0] != 0)) {
		cout << 0 << endl;
		return 0;
	}
	ll ret = 1;
	for (int i = 0; i < mmax; i++) {
//		cerr << a[i] << " " << a[i + 1] << endl;
		ret *= mypow(a[i], a[i + 1]);
		ret %= MOD;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4388
#include <set>
#include <string>
#include <iostream>

using namespace std;

int N, K; string D[10];

set<string> s;

void dfs(string S, bool ok[10], int k)
{
	if (k == K)
	{
		s.insert(S);
	}
	else
	{
		for (int i = 0; i < N; i++)
		{
			if (ok[i] == false)
			{
				bool ok2[10];

				for (int j = 0; j < 10; j++)
				{
					ok2[j] = ok[j];
				}

				ok2[i] = true;

				dfs(S + D[i], ok2, k + 1);
			}
		}
	}
}

int main()
{
	while (true)
	{
		s.clear();

		cin >> N >> K;

		if (N == 0) { break; }

		for (int i = 0; i < N; i++)
		{
			cin >> D[i];
		}

		bool ok_[10];

		for (int i = 0; i < 10; i++) { ok_[i] = false; }

		dfs("", ok_, 0);

		cout << s.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int n, m;
vector<set<int>> mp;
vecint dp;
int dfs(int a){
  if(dp[a] != -1) return dp[a];
  int res = 0;
  for(auto v:mp[a]){
    chmax(res, dfs(v) + 1);
  }
  return dp[a] = res;
}
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main()
{
  init();
  cin >> n >> m;
  mp.resize(n);
  REP(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    mp[a].insert(b);
  }
  dp.resize(n);
  REP(i,n) dp[i] = -1;
  int res = 0;
  REP(i,n) chmax(res, dfs(i));
  cout << res << endl;
}


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


int main(void){

	int N,Ma,Mb;
	cin>>N>>Ma>>Mb;

	//それぞれ物質Aの含有量,Bの含有量,値段の合計の最大値
	const int amax=400;
	const int bmax=400;
	const int pmax=100000;

	//リストを作成してすべてを最大値に初期化
	int list[N+1][amax+1][bmax+1];
	for(int i=0;i<N+1;i++){
		for(int a=0;a<amax+1;a++){
			for(int b=0;b<bmax+1;b++){
				list[i][a][b]=pmax;
			}
		}
	}

	//物質AもBもないのは何も買わず、コストも0
	for(int i=0;i<=N;i++){
		list[i][0][0]=0;
	}

	//動的計画法のメイン部分
	int a,b,p;
	for(int i=1;i<=N;i++){

		cin>>a>>b>>p;
		for(int anow=0;anow<=amax;anow++){
			for(int bnow=0;bnow<=bmax;bnow++){
				if(anow<a || bnow<b) list[i][anow][bnow]=list[i-1][anow][bnow];
				else list[i][anow][bnow]=min(list[i-1][anow-a][bnow-b]+p,list[i-1][anow][bnow]);
			}
		}


	}



	int cost=pmax;
	for(a=1;a<=bmax;a++){
		for(b=1;b<=bmax;b++){
			if(a*Mb==b*Ma&&list[N][a][b]<cost) cost=list[N][a][b];
		}
	}

	if(cost==pmax) cost=-1;
	cout<<cost<<endl;

	return 0;

}






Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  int m=1000005;
  vector<int>cnt(m);
  for(int x:a){
    if(cnt[x]!=0){
      cnt[x]=2;
      continue;
    }
    for(int i=x;i<m;i+=x){
      cnt[i]++;
    }
  }
  int ans=0;
  for(int x:a){
    if(cnt[x]==1){
      ans++;
    }
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 8012
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	const string s1 = "12651";//3
	const string s2 = "15621";//4
	const string s3 = "53245";//6
	const string s4 = "54235";//1
	const string s5 = "13641";//5
	const string s6 = "14631";//2

	int a[6];
	int n;
	vector<int> ans;

	for (int i = 0; i < 6; i++)
	{
		cin >> a[i];
	}

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int t, f;
		cin >> t >> f;

		string input;
		
		for (int i = 0; i < 6; i++)
		{
			if (a[i] == t)
			{
				input += to_string(i + 1);
			}
		}
		for (int i = 0; i < 6; i++)
		{
			if (a[i] == f)
			{
				input += to_string(i + 1);
			}
		}
		
		if (s1.find(input) != string::npos)
		{
			ans.push_back(2);
		}
		if (s2.find(input) != string::npos)
		{
			ans.push_back(3);
		}
		if (s3.find(input) != string::npos)
		{
			ans.push_back(5);
		}
		if (s4.find(input) != string::npos)
		{
			ans.push_back(0);
		}
		if (s5.find(input) != string::npos)
		{
			ans.push_back(4);
		}
		if (s6.find(input) != string::npos)
		{
			ans.push_back(1);
		}
	}

	for (auto& n : ans)
	{
		cout << a[n] << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void solve(long long N, long long K, std::string S) {
    S.erase(unique(S.begin(), S.end()), S.end());
    int m = S.size();

    while (K >= 1 && m >= 3) {
        m -= 2;
        K--;
    }
    while( K >= 1 && m >= 2 ){
        m -= 1;
        K--;
    }


    cout << N - m  << endl;




}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::string S;
    std::cin >> S;
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

set<string> ret;

void dfs(int N, string s, int x){
  if(s.size()==N){
    ret.insert(s);
    return;
  }
  rep(i,x+1){
    dfs(N, s + (char)('a'+i), (i==x?x+1:x));
  }
}


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

  dfs(N, "", 0);

  FOR(it,ret){
    cout << (*it) << endl;
  }
  
  return 0;
}


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

using namespace std;

const int MAXN = 100010;
const int INF = 1000000010;

int n;

int v[MAXN];
int dp[MAXN];

int main()
{
	scanf("%d",&n);

	for(int i = n ; i > 0 ; i--)
		scanf("%d",&v[i]);

	for(int i = 1 ; i <= n ; i++)
		dp[i] = INF;

	int ans = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		int ind = upper_bound( dp , dp + n + 1 , v[i] ) - dp;

		dp[ind] = v[i];
		ans = max( ans , ind );
	}

	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n + 5];
    for( int i = 1; i <= n; ++i ) cin >> a[i];
    int cnt = 0;
    for( int i = 1; i < n; ++i ) {
        if( a[i] != -1 && a[a[i]] == i ) {
            ++cnt;
            a[a[i]] = -1;
        }
    }

    cout << cnt << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int a;
	cin>> a;

	cout<< (1000-(a%1000))%1000 << endl;
 
	return 0;
}

Measured memory_bytes: 3632
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1100000000000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

int W[110][110],B[110][110];



int main(){
    ll X,Y;
    cin>>X>>Y;
    if(abs(X-Y)>1) cout<<"Alice"<<endl;
    else cout<<"Brown"<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n;
LL A[MX], B[MX], sum;

bool solve() {
    LL tot = (LL)(1 + n) * n / 2;
    if(sum % tot != 0) return 0;

    LL k = sum / tot, used = 0;
    for(int i = 1; i <= n; i++) {
        int last = i == 1 ? n : i - 1;
        B[i] = A[i] - A[last];

        if((k - B[i]) % n != 0 || (k - B[i]) < 0) {
            return 0;
        }
        used += (k - B[i]) / n;
    }
    return used == k;
}

int main() {
    // FIN;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &A[i]);
        sum += A[i];
    }
    printf("%s\n", solve() ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 1792
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i64>();
    let (a, b, c) = (line[0], line[1], line[2]);

    if c < a + b{
        println!("No");
        return;
    }

    if 4*a*b < (c - b - a)* (c - b - a){
        println!("Yes");
    }else{
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
  int n[4];

  for(int i = 0; i < 4; i++) {
    cin >> n[i];
  }

  bool a=false, b=false, c=false, d=false;
  for(int i = 0; i < 4; i++) {
    if(n[i] == 1) a = true;
    if(n[i] == 9) b = true;
    if(n[i] == 7) c = true;
    if(n[i] == 4) d = true;
  }


  if((a && b) && (c && d)) {
    cout << "YES" << endl;
  }else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import sys

ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

    count = 0
    for t in T:
        if linner_search(S, t):
            count += 1

    print(count)


def linner_search(li, key):
    li.append(key)
    i = 0
    while li[i] != key:
        i += 1

    return i != len(li) - 1


def get_input1():
    n = int(input())
    if n > 10000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(x)

    return li


def get_input2():
    n = int(input())
    if n > 500:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(x)

    return li


main()

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

const i64 MOD = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, S;
  cin >> N >> S;
  vector<i64> A(N);
  for (auto& x : A) cin >> x;

  vector<vector<mint>> dp(N + 1, vector<mint>(S + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    i64 a = A[i];
    REP(j, S + 1) { dp[i + 1][j] = dp[i][j] * 2; }
    for (int j = S - a; j >= 0; --j) {
      dp[i + 1][j + a] += dp[i][j];
    }
  }
  cout << dp[N][S] << endl;
}

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

struct item {
  long long v, p;
};

struct town {
  int x, y, l;
  vector<long long> weights, values;
};

long long n, m, w, t;
map<string, item> mp;
vector<town> towns;
vector<long long> memot, memov;

long long solve();

int main() {
  cin >> n >> m >> w >> t;
  for(int i = 0; i < m; ++i) {
    string s;
    long long v, p;
    cin >> s >> v >> p;
    mp[s] = {v, p};
  }
  towns.resize(n);
  for(int i = 0; i < n; ++i) {
    int l;
    cin >> l >> towns[i].x >> towns[i].y;
    towns[i].l = l;
    towns[i].values.resize(l);
    towns[i].weights.resize(l);
    for(int j = 0; j < l; ++j) {
      string s;
      cin >> s >> towns[i].values[j];
      towns[i].weights[j] = mp[s].v;
      towns[i].values[j] =
          max(0LL, mp[s].p - towns[i].values[j]);
    }
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  // calc time bit dp
  {
    memot.assign(1 << n, t + 1);
    vector<vector<long long>> dp(
        1 << n, vector<long long>(n, t + 1));
    for(int i = 1; i < (1 << n); ++i)
      for(int j = 0; j < n; ++j)
        if(i >> j & 1) {
          if((1 << j) == i)
            dp[i][j] = abs(towns[j].x) + abs(towns[j].y);
          else {
            for(int k = 0; k < n; ++k)
              if(j != k && (i >> k & 1))
                dp[i][j] =
                    min(dp[i][j],
                        dp[i - (1 << j)][k] +
                            abs(towns[j].x - towns[k].x) +
                            abs(towns[j].y - towns[k].y));
          }
          memot[i] =
              min(memot[i], dp[i][j] + abs(towns[j].x) +
                                abs(towns[j].y));
        }
  }
  // calc value knapsack dp
  {
    memov.assign(1 << n, 0);
    vector<vector<long long>> dp(
        1 << n, vector<long long>(w + 1, 0));
    for(int i = 1; i < (1 << n); ++i)
      for(int j = 0; j < n; ++j)
        if(i >> j & 1)
          for(int k = 0; k < towns[j].l; ++k)
            for(int p = towns[j].weights[k]; p <= w; ++p) {
              dp[i][p] = max(
                  dp[i][p], dp[i][p - towns[j].weights[k]] +
                                towns[j].values[k]);
              memov[i] = max(memov[i], dp[i][p]);
            }
  }
  // calc max profit
  long long res = 0;
  {
    vector<long long> dp(t + 1, 0);
    for(int i = 1; i < (1 << n); ++i)
      for(int j = memot[i]; j <= t; ++j) {
        dp[j] = max(dp[j], dp[j - memot[i]] + memov[i]);
        res = max(res, dp[j]);
      }
  }
  return res;
}


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

string s[]={"thu","fri","sat","sun","mon","tue","wed"};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	cout << s[n%7] << endl;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
string s;
int a,b=1,aa[1000]={};
signed main()
{
	cin>>a;
	cin>>s;
	rep(i,a){
		aa[s[i]]++;
	}
	rep(i,26){
		b*=aa[i+97]+1;
		b%=1000000007;
	}
	cout<<b-1;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
typedef long long ll;

int main() {
	int n;
	double m;
	std::cin >> n >> m;
	std::vector<int> A;
	double b = 0;
	for (int i = 0; i < n; i++) {
		int k;
		std::cin >> k;
		A.emplace_back(k);
		b += k;
	}
	std::vector<int> baketto;
	for (int i = 0; i <= 1000; i++) {
		baketto.emplace_back(0);
	}
	for (auto iter = A.begin(); iter != A.end(); iter++) {
		baketto[*iter]++;
	}
	int c = 1;
	for (int i = 0; i < n; i++) {
		while (1) {
			if (baketto[c] != 0) {
				A[i] = c;
				baketto[c]--;
				break;
			}
			c++;
		}
	}
	for (int i = 0; i < m; i++) {
		if (A[n - i - 1] < (double)b / (4.0 * m)) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int n, a;
  cin >> n;
  map<int, int> m;
  long int ans = 0;
  for(int i = 1; i <= n; i++){
    cin >> a;
    ans = ans + m[i-a];
    m[i+a]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 20612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    int s[n],t[m];
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<m;i++)cin>>t[i];
    ll dp[n+1][m+1],sum[n+1][m+1];
    dp[0][0]=sum[0][0]=1;
    for(int i=1;i<n+1;i++){
        dp[i][0]=0;
        sum[i][0]=1;
    }
    for(int j=1;j<m+1;j++){
        dp[0][j]=0;
        sum[0][j]=1;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=sum[i][j];
            }else{
                dp[i+1][j+1]=0;
            }
            sum[i+1][j+1]=(dp[i+1][j+1]+sum[i][j+1]+sum[i+1][j]-sum[i][j]+MOD)%MOD;
        }
    }
    cout<<sum[n][m]<<endl;
}


Measured memory_bytes: 62848
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
//#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e8+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
int main(void){
	int i,j,n,m,a,b;cin>>n>>m;
	vector<vector<int>>ed(n);
	vector<bool> use(n);
	deque<int>ans;
	for(i=0;i<m;i++){
		cin>>a>>b;a--;b--;
		ed[a].pub(b);
		ed[b].pub(a);
	}
	use[0]=true;
	ans.pub(0);
	while(true){
		int now=ans.back();
		use[now]=true;
		for(i=0;i<ed[now].size();i++){
			if(!use[ed[now][i]]){ans.pub(ed[now][i]);break;}
		}
		if(i==ed[now].size()){break;}
	}
	while(true){
		int now=ans.front();
		use[now]=true;
		for(i=0;i<ed[now].size();i++){
			if(!use[ed[now][i]]){ans.puf(ed[now][i]);break;}
		}
		if(i==ed[now].size()){break;}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++){cout<<ans[i]+1<<" ";}
	return 0;
}


Measured memory_bytes: 6656
n = gets.to_i
# "Yes" "No"
t1 = 0
x1, y1 = [0, 0]
n.times do |_|
  t2, x2, y2 = gets.chomp.split.map(&:to_i)
  d = (x2 - x1).abs + (y2 - y1).abs
  if t2 - t1 < d || (t2 - t1) % 2 != d % 2
    puts "No"
    exit
  end
  t1, x1, y1 = t2, x2, y2
end

puts "Yes"

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;
const int MAX_N=1000;

int main(){
	int n,k;
	int x=1;
	cin>>n>>k;
	REP(i,n){
		if(x>k){
			x+=k;
		}else{
			x*=2;
		}
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    long long minum = N - 1;
    for(long long i = 2;i * i <= N;i++){
        if(N % i == 0){
            minum = min(minum,i + N / i - 2);
        }
    }
    cout << minum << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int R, G, B, n;
    int ans = 0;

    cin >> R >> G >> B >> n;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++){
            if ((n - (R * i + G * j)) % B  == 0 && R * i + G * j <= n){
                ans++;
            }
        }
    }

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

Measured memory_bytes: 256
using System;
using static System.Console;

namespace atcoder
{
	class Program
    {
    	static void Main(string[] args)
        {
          int N = int.Parse(ReadLine());
          	
          for(int i = 1; i < 10; i++)
          {
          	for(int j = 1; j < 10; j++)
            {
            	if(N == i * j)
                {
                	goto loopend;
                }
            }
          }
          WriteLine("No");
          return;
          loopend:;
          WriteLine("Yes");
          return;
        }
    }
}

Measured memory_bytes: 13140
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n > m:
    print(0)
    exit()

x.sort()
l = []
for i in range(len(x)):
    if i == 0:
        continue
    l.append(x[i] -  x[i-1])
l.sort(reverse=True)
sum = sum(l)
for i in range(n-1):
    sum -= l[i]

print(sum)

Measured memory_bytes: 13968
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    dic = defaultdict(int)
    for _ in range(n):
        s = input()
        dic[s] = 1
    ans = 0
    for e in dic:
        ans += dic[e]
    print(ans)    
if __name__ == "__main__":
    main()

Measured memory_bytes: 131868
import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {

    fun PrintWriter.solve() {
        var (n,a,b) = List(3){nextLong()}

        var times = n/(a+b)
        var left = n%(a+b)
        left =minOf(a,left)


        var ans = times*a + left

        println(ans)


    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()



Measured memory_bytes: 34412
s=input()
res='keyence'
n=len(s)
if s[0]!='k':
  if s[n-7:n]=='keyence':
    print('YES')
  else:
    print('NO')
elif s[n-1]!='e':
  if s[:7]=='keyence':
    print('YES')
  else:
    print('NO')
elif s[0]=='k' and s[n-1]=='e':
  lb=1
  while lb<6:
    if s[lb]==res[lb]:
      lb+=1
    else:
      break
  ub=1
  while ub<7-lb:
    if s[n-ub-1]==res[6-ub]:
      ub+=1
    else:
      break
  if ub+lb==7:
    print('YES')
  else:
    print('NO')
    

Measured memory_bytes: 9096
import Foundation
let mod = Int(1e9)+7

let k = Array(readLine()!)
let d = Int(readLine()!)!

var dp = [[[Int]]](repeating: [[Int]](repeating: [Int](repeating: -1,
                                                       count: 2),
                                      count: 10010),
                   count: 110)




func dfs(_ cs: Int, _ pos: Int, _ isOnUpper: Bool) -> Int {
    if pos == k.count {
        return cs == 0 ? 1 : 0
    }
    let upperBound = isOnUpper ? Int("\(k[pos])")! : 9
    guard dp[cs][pos][isOnUpper ? 0 : 1] == -1 else {
        return dp[cs][pos][isOnUpper ? 0 : 1]
    }
    
    var res = 0
    for i in stride(from: 0, through: upperBound, by: 1) {
        res += dfs((cs+i)%d, pos+1, isOnUpper && i == upperBound)
        if res >= mod {
            res -= mod
        }
    }
    
    dp[cs][pos][isOnUpper ? 0 : 1] = res
    return res
}

let res = dfs(0,0, true)-1
print(res < 0 ? mod + res : res)
//print(brute(String(k), d))


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

int main()
{
    string A, B;
    cin >> A >> B;

    string ans = "EQUAL";
    if (A.size() == B.size())
    {

        for (int i = 0; i < A.size(); i++)
        {
            if (A[i] > B[i])
            {
                ans = "GREATER";
                break;
            }
            if (A[i] < B[i])
            {
                ans = "LESS";
                break;
            }
        }
    }
    else
    {
        if (A.size() > B.size())
        {
            ans = "GREATER";
        }
        else
        {
            ans = "LESS";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    string s, t;
    cin >> s >> t;
    
    for(int i = 0; i < n; i++) {
        cout << s[i];
        cout << t[i];
        
        if(i == n - 1) {
            cout << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
py_dict = dict()
ip_dict = dict()
io_dict = dict()

for i in range(m):
    py_list = list(map(int, input().split()))
    py_list.append(i)
    if py_list[0] in py_dict:
        py_dict[py_list[0]].append(py_list)
    else:
        py_dict[py_list[0]] = [py_list]
    ip_dict[i] = py_list[0]

for item in py_dict:
    tmp_list = py_dict[item]
    tmp_list.sort(key=lambda x: x[1])
    for i in range(len(tmp_list)):
        io_dict[tmp_list[i][2]] = str(
            ip_dict[tmp_list[i][2]]).zfill(6) + str(i+1).zfill(6)

for i in range(m):
    print(io_dict[i])


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

const int d[] = {0, 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 main() {
    int k; cin >> k;
    cout << d[k] << endl;
    return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
c=0

if n%2==1:
    for i in range((n-1)//2):
        if s[i]!=s[-i-1]:
            c+=1
else:
    for i in range(n//2):
        if s[i]!=s[-i-1]:
            c+=1
print(c)

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


int main() {
  int N;
  string S;
  cin >> N >> S;
  
  string Ans = "No";
  
  if(N%2 == 1 || N < 2){
  }else{
    for(int i = 0; i < N/2; i++){
      if(S.at(i) == S.at(N/2 + i)){
        	if(i == N/2 - 1){
              Ans = "Yes";
              break;
            }else{
              continue;
            }
      }else{
        break;
      }
    }
  }
  
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int toint(const char c){
    if ('0' <= c && c <= '9' ) return (c - '0');
    return 0;
}
int main (){
    while (1){
        int ans = 0;
        char x[1000] = {0};
        cin >> x;
        if (x[0] == '0') break;
        for (int i = 0; i < 1000; i++){
            ans += toint(x[i]);
        }
        cout << ans << endl;
        
    }
}



Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
int v[114141];
vector<P>V1, V2;
int c1[114514], c2[114514];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> v[i];
	rep(i, n) {
		if (i&1) {
			c2[v[i]]++;
		}
		else c1[v[i]]++;
	}

	rep(i, 100001) {
		V1.push_back(P(c1[i], i));
		V2.push_back(P(c2[i], i));
	}
	sort(V1.begin(), V1.end());
	sort(V2.begin(), V2.end());
	reverse(V1.begin(), V1.end());
	reverse(V2.begin(), V2.end());
	if (V1[0].second != V2[0].second) {
		cout << n - V1[0].first - V2[0].first << endl;
	}
	else {
		cout << n - max(V1[0].first + V2[1].first, V1[1].first + V2[0].first) << endl;
	}

}


Measured memory_bytes: 7016
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,z;
    cin>>n>>l>>r;
    while(n--){
       cin>>a>>b;
       if(a>=l && b>=r){
         sum++;
       }
    }
    cout<<sum<<endl;

    return EXIT_SUCCESS;
}



Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)

long long INF = 1000000007;

int main(){
  int N;  
  cin >> N;
  int C[N][2];
  rep(i, N)
    cin >> C[i][0]>>C[i][1];
  //

  int con=0;
  rep(i, N-2){
    if(C[i][0] == C[i][1])
      if( C[i+1][0] == C[i+1][1] )
	if(C[i+2][0] == C[i+2][1]){
	  Yes();
	  return 0;
	}
  }
    
  No();

  return 0;
}


Measured memory_bytes: 3636
K,S = map(int,input().split())

same_all = 0
same_two = 0
same_none = 0

for i in range(K, -1, -1):
    for j in range(S - i, -1, -1):
        if ( K<j or i<j):
            continue
        k = S-i-j
#         print(i,j,k)
        if (k <= K and k<=j):
            if(i == j and j == k):
                same_all += 1
            elif(i == j or i == k or k == j):
                same_two += 1
            else:
                same_none += 1


print(same_all + same_two*3 + same_none*6)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let c:Vec<(f64, String)> = (0..n).map(|_| (read(), read())).collect();

    let mut ans:f64 = 0.0;
    for &(x,ref u) in c.iter() {
        if u == "JPY" {
            ans += x;
        } else {
            ans += x * 380000.0;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int h,w,k; cin >> h >> w >> k;
  vector<int> s(4);
  rep(i,4) {
    cin >> s[i];
    s[i]--;
  }
  vector<vector<char>> c(h, vector<char>(w));
  rep(i,h) rep(j,w) cin >> c[i][j];

  using pi = pair<int,int>;
  using pii = pair<int,pi>;  
  queue<pi> q;  
  q.push({s[0], s[1]});
  vector<vector<int>> d(h, vector<int>(w, -1));
  d[s[0]][s[1]] = 0;
  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};
  while( !q.empty() ) {
    pi p = q.front(); q.pop();
    int x = p.first, y = p.second;
    rep(i,4) {
      rep1(j,k) {	
	int nx = x + dx[i]*j;
	int ny = y + dy[i]*j;
	if(0 <= nx && nx < h && 0 <= ny && ny < w) {
	  if(c[nx][ny] == '@') break;
	  if(d[nx][ny] == d[x][y] + 1) continue;
	  if(0 <= d[nx][ny]) break;
	  d[nx][ny] = d[x][y] + 1;
	  q.push({nx, ny});
	}
	else break;
      }
    }	  
  }

  // rep(i,h) {
  //   rep(j,w) cout << d[i][j] << " ";
  //   cout << "\n";
  // }
  
  cout << d[s[2]][s[3]] << "\n";
  
  return 0;
}


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

/* 解説を見て考えてみた */

int main(){
    // 入力スタンダード
    ll n; // n人の参加者
    cin >> n ;

    ll gp = 0; //最終的に出力するpair数

    map<ll,ll> mp;

    for(ll i=0; i<n; i++){
        ll ai;
        cin >> ai;
        mp[i+ai]++;
        gp += mp[i-ai];
    }

    cout << gp <<endl;
    return 0;
}

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

int main(int argc, char *argv[])
{
	char str[21], reversed[21];
	int i, length;

	scanf("%s", str);
	length = strlen(str);
	for (i=0; i<length; i++) {
		reversed[i] = str[length-1-i];
	}
	reversed[i] = '\0';

	printf("%s\n", reversed);
	return 0;
}

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

int main(){
    string s; cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

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

int main() {
    int temp = 1;
    while(1) {
        int num;
        cin>>num;
        
        if(num == 0) {
            cout<<temp<<endl;
            return 0;
        }
        temp++;
    }
    return 0;
}

Measured memory_bytes: 3676
import itertools

if __name__ == '__main__':
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    # print(A)
    # A, B, C, X = 30, 40, 50, 6000

    A_list = list(map(lambda x: x * 500, range(A + 1)))
    B_list = list(map(lambda x: x * 100, range(B + 1)))
    C_list = list(map(lambda x: x * 50, range(C + 1)))

    all_list = list(itertools.product(A_list, B_list, C_list))
    sum_list = list(map(lambda t: sum(t), all_list))
    print(sum_list.count(X))


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

int main(){
    char a,b,ans='A';
    while(scanf(" %c,%c",&a,&b)!=EOF){
        if(a==ans){
            ans=b;
        }else if(b==ans){
            ans=a;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i < r + 1; ++i) {
        if(i % d == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3592
#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>;
//pow(x,n)
//cout << fixed << setprecision(桁数);

int main() {
    int in; cin >> in;
    vector<int> vec(4);
    vec[0]=in/1000; vec[1]=(in/100)%10; vec[2]=(in%100)/10; vec[3]=in%10;
    vector<string> op={"+++","++-","+-+","+--","-++","-+-","--+","---"};
    vector<char> kai(3);


    for(auto p:op){
        int sum=vec[0];
        for(int i=0;i<3;++i){
            if(p.at(i)=='+'){
                sum += vec[i+1];
                kai[i]='+';
            }
            else if(p.at(i)=='-'){
                sum -= vec[i+1];
                kai[i]='-';
            }
        }
        if(sum==7) break;
    }
    cout << vec[0] << kai[0] << vec[1] << kai[1] <<vec[2] << kai[2] <<vec[3] << "=7" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

double conb(double a, double b){
    if(b == 0)return 1.0;
    return a/b * conb(a-1, b-1);
}
int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> ind(26, 0);
    rep(i, n)ind[s[i]-'a']++;

    ll ans = 1;
    rep(i, 26)ans = (ll)(ans*(ind[i] + 1))%1000000007;
    ans = (ll)(ans - 1 + 1000000007)%1000000007;
    cout << ans << endl;
}

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

int main(){
  string S;
  cin >> S;
  bool bus = false;
  if(S.at(0) != S.at(1)) bus = true;
  if(S.at(1) != S.at(2)) bus = true;
  if(S.at(2) != S.at(0)) bus = true;
  puts(bus ? "Yes" : "No");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		for(int i=1; i<=9;i++) {
			for(int j=1; j<=9;j++) {
				if(i*j==n) {
					System.out.println("Yes");
					return ;
				}
			}
		}

		System.out.println("No");
	}
}

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

int main()
{
    int n1,n2;
    cin>>n1;
    n2=n1%10;
    if (n2==3)
    {
        cout<<"bon"<<endl;
    }
    else if (n2==0 || n2==1 || n2==6 || n2==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"hon"<<endl;
    }
}

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

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

    ll ans = 0, sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;

        if (a == 0) {
            ans += sum / 2;
            sum = 0;
        }
    }

    ans += sum / 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3580
/**
 *      ABC 56 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-10 21:46:04
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll X; cin >> X;
    for (ll i = 1; i <= X; ++i) {
        if (i * (i + 1) / 2 >= X){
            cout << i << endl; return 0;
        }
    }
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    bool b;
    cin >> b;
    cout << (b ? 0 : 1) << endl;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int calc(int n){
	int ok = 0, ng = 1000;
	while(ng - ok > 1){
		int mid = (ok + ng) / 2;
		(mid*(mid-1) <= 2 * n ? ok : ng) = mid;
	}
	return (ok*(ok-1) == 2*n ? ok : -1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int k = calc(n);
	if(k == -1){
		cout << "No" << endl;
		return 0;
	}
	int cnt = 1;
	vector<vector<int>> ans(k);
	rep(i,k)rep(j,i){
		ans[i].push_back(cnt);
		ans[j].push_back(cnt);
		cnt++;
	}
	cout << "Yes" << endl;
	cout << k << endl;
	rep(i,k){
		cout << ans[i].size();
		for(int j : ans[i]){
			cout << " " << j;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2304