akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<queue>
using namespace std;
const int MAX_VALUE = 1e9;

struct dataNode
{
	int next,end_pos,road_length,road_price;
}Edge[205000];


int head[10050];
bool visited[10050];
int dis[10050];
int flag_cost[10050];
int N,M,total_data;


void init ()
{
	memset(head,-1,sizeof(head));
	total_data = 0;
}

void addEdge (int start_pos,int end_pos,int road_length,int road_price)
{
	Edge[total_data].end_pos = end_pos;
	Edge[total_data].road_length = road_length;
	Edge[total_data].road_price = road_price;
	Edge[total_data].next = head[start_pos];
	head[start_pos] = total_data++;
}

int SPFA (int start_pos)
{
	
	for(int i=1;i<=N;i++)
	{
		visited[i] = false;
		flag_cost[i] = dis[i] = MAX_VALUE;
	}
 	dis[start_pos] = 0;
	flag_cost[start_pos] = 0;
	visited[start_pos] = true;
	queue<int> q;
	q.push(start_pos);
	while (q.empty() != true)
	{
		int v = q.front();
		q.pop();
		visited[v] = false;
		for (int i = head[v];i != -1;i = Edge[i].next)
		{
			int u = Edge[i].end_pos;
			if ( dis[v] + Edge[i].road_length < dis[u])
			{
				dis[u] = dis[v] + Edge[i].road_length;
				flag_cost[u] = Edge[i].road_price;
				if (visited[u] == false)
				{
					visited[u] = true;
					q.push(u);
				}
			}
			else if ((dis[u] == dis[v] + Edge[i].road_length && flag_cost[u]>Edge[i].road_price))
			{
				flag_cost[u] = Edge[i].road_price;
				if (visited[u] == false)
				{
					visited[u] = true;
					q.push(u);
				}
			}
		}
	}
	int sum = 0;
	for (int i=1;i<=N;i++)
	{
		sum += flag_cost[i];
	}
	return sum;
}

int main ()
{
	while (cin>>N>>M)
	{
		if (N == 0 && M == 0)
		{
			break;
		}
		init();
		for (int i=0;i<M;i++)
		{
			int start_pos,end_pos,road_length,road_price;
			cin>>start_pos>>end_pos>>road_length>>road_price;
			addEdge(start_pos,end_pos,road_length,road_price);
			addEdge(end_pos,start_pos,road_length,road_price);
		}
		cout<<SPFA(1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3820
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;


ll N, L, ans;
string S;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> L;
	ans = (N * (N - 1)) / 2 + N * L;
	if (L > 0)ans -= L;
	if (L < 0)
	{
		if (L + N-1 >= 0)ans -= 0;
		if (L + N-1 < 0)ans -= L + N - 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  string s;
  vector<char> w = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  cin >> n >> s;
  rep(i,s.size()) {
    rep(j,26) {
      if(s[i] == w[j]) {
        s[i] = w[j+n];
        break;
      }
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int A[3]; REP(i, 3) cin >> A[i];
	
	int ans = INF;
	REP(i, 1<<3) {
		int pop = 0;
		REP(j, 3) if (i >> j & 1) pop++;
		if (i != 0 && pop != 2) continue;
		
		int tmp[3];
		REP(j, 3) tmp[j] = A[j] + (i >> j & 1);
		int ma = *max_element(tmp, tmp + 3);
		int cur = i != 0;
		bool ng = false;
		REP(j, 3) {
			if ((ma & 1) != (tmp[j] & 1)) ng = true;
			cur += (ma - tmp[j]) / 2;
		}
		if (!ng) chmin(ans, cur);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define  ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define vii vector<pair<int,int> >
#define pb push_back
#define inf 1000000007
#define f(i,a,b) for(i=a;i<b;i++)

using namespace std;
bool cmp(string &a,string &b)
{
	if(a.size()==b.size())return a<b;
	return a.size()<b.size();
}

int main()
{ 
 ll n,i,j,s=0;
 cin>>n;
 ll a[n];
 f(i,0,n)
 {
 	cin>>a[i];
 	
 	if(i)
 	{
 		if(a[i]<a[i-1])s+=(a[i-1]-a[i]),a[i]=a[i-1];
	 }
 }
 cout<<s;
}

Measured memory_bytes: 5156
#include <stdio.h>

int main() {
	int a, b, c, max1, max2;

	scanf("%d %d %d", &a, &b, &c);

	while (1) {
		if (a >= b && a >= c) {
			max1 = a;
			a = 0;
			break;
		}
		if (b >= a && b >= c) {
			max1 = b;
			b = 0;
			break;
		}
		if (c >= a && c >= b) {
			max1 = c;
			c = 0;
			break;
		}
	}
	while (1) {
		if (a >= b && a >= c) {
			max2 = a;
			a = 0;
			break;
		}
		if (b >= a && b >= c) {
			max2 = b;
			b = 0;
			break;
		}
		if (c >= a && c >= b) {
			max2 = c;
			c = 0;
			break;
		}
	}

	printf("%d\n", max1 * 10 + max2 + a + b + c);
	

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;


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

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    while (a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
  }
  cout << cnt << endl;

  return 0;
}

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

using namespace std;
using ll = long long;

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

    string N; cin >> N;

    if (N.find('7') != string::npos) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


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

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

  cin >> N;
  vector<int> a(N);
  rep (i, N) cin >> a[i];

  map<int, int> c;
  rep (i, N) c[a[i]]++;

  for (pair<int, int> c_i : c) {
    int current = c_i.first;
    int prev_ = c_i.first - 1;
    int next_ = c_i.first + 1;

    int ans_ = c[current];
    if (c.end() != c.find(prev_)) ans_ += c[prev_];
    if (c.end() != c.find(next_)) ans_ += c[next_];

    ans = max(ans, ans_);
  }

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



Measured memory_bytes: 3584
# coding: utf-8

import sys
input = sys.stdin.readline

def f(n, abc):
    la, lb, lc = 0, 0, 0
    for a, b, c in abc:
        na, nb, nc = max(lb + a, lc + a), \
            max(la + b, lc + b), max(la + c, lb + c)
        la, lb, lc = na, nb, nc
    return(max(la, lb, lc))

n = int(input())    # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print(f(n, abc))


Measured memory_bytes: 30580
#include <iostream>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#include <string>
#include <vector>
#include <algorithm>
int main() {
	int n;

	
	long long int p[20000],a[20000],b[20000];
	cin >> n;
	rep(i, n)
		cin >> p[i];
	for (int i = 0; i < n; i++) {
		a[i] = n+n*i+5;
		b[i] = n*(n - i)+5;
	}
	
	for (int i = 0; i < n; i++) {
		a[p[i]-1] += i;
		}


	rep(i, n - 1)
		cout << a[i] << " ";
	cout << a[n - 1] << endl;
	rep(i, n - 1)
		cout << b[i] << " ";
	cout << b[n - 1] << endl;




}

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

using namespace std;

const int N = 102;
int n, a, b;
bool memo[N][N];
int ans[N][N];
int win(int x, int y) {
   if(x <= 0 || x > n)return 1;
   if(y <= 0 || y > n) return 2;
   if(memo[x][y])return ans[x][y];
   memo[x][y] = 1;
   if(x - 1 > 0 && x - 1 != y && win(y, x - 1) == 2) {
    return ans[x][y] = 1;
   }
   if(x + 1 <= y && x + 1 <= n && win(y, x + 1) == 2)
    return ans[x][y] = 1;
   if(x - 1 > 0 && x - 1 != y && win(y, x - 1) == 0) return ans[x][y] = 0;
   if(x +1<=y&&x+1<=n&&win(y,x+1)==0)return ans[x][y]=0;
   return ans[x][y]=2;
}
int main() {
   cin >> n >> a >> b;
   if(win(a, b) == 0)cout << "Draw";
   else
      cout << (win(a, b) == 1 ? "Alice" : "Borys");

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int getdst(const vs& amida,int src)
{
	int h=amida.size(),w=amida[0].size();
	rep(i,h){
		if(src!=1 && amida[i][src-2]=='1')
			src--;
		else if(src!=w+1 && amida[i][src-1]=='1')
			src++;
	}
	return src;
}

void solve(vs& amida,int src,int dst)
{
	if(getdst(amida,src)==dst){
		cout<<0<<endl;
		return;
	}
	
	int h=amida.size(),w=amida[0].size();
	if(w==1){
		rep(i,h)
			if(amida[i][0]=='0'){
				cout<<i+1<<" "<<1<<endl;
				return;
			}
		cout<<1<<endl;
		return;
	}
	
	rep(i,h)
		rep(j,w){
			if(amida[i][j]=='1')
				continue;
			
			bool ok=false;
			if(j==0){
				if(amida[i][j+1]=='0'){
					amida[i][j]='1';
					if(getdst(amida,src)==dst)
						ok=true;
				}
			}
			else if(j==w-1){
				if(amida[i][j-1]=='0'){
					amida[i][j]='1';
					if(getdst(amida,src)==dst)
						ok=true;
				}
			}
			else{
				if(amida[i][j-1]=='0' && amida[i][j+1]=='0'){
					amida[i][j]='1';
					if(getdst(amida,src)==dst)
						ok=true;
				}
			}
			amida[i][j]='0';
			
			if(ok){
				cout<<i+1<<" "<<j+1<<endl;
				return;
			}
		}
	
	cout<<1<<endl;
}

int main()
{
	for(int n;cin>>n,n;){
		int src,dst,h;
		cin>>src>>dst>>h;
		vs amida(h);
		rep(i,h)
			cin>>amida[i];
		solve(amida,src,dst);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
ll N,W;
int v[1005];
int w[1005];
ll dp[105][10005];//n種類までに重さの総和がkまでの価値の最大値
int main(void) {
	cin >> N >> W;
	FOR(i, 0, N)cin >> v[i] >> w[i];
	FOR(i, 0, N) {
		FOR(j, 0, W + 1) {
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W]<<endl;
	return 0;
}


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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}
int main(){
  ll n; cin>>n;
  string ans;
  while(n){
    n--;
    ans+='a'+n%26;
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  

  return 0;
  
  
}


Measured memory_bytes: 3632
MAX_LEN = 1000
dp = Array.new (MAX_LEN + 1) { Array.new MAX_LEN + 1 }
gets.to_i.times do
  x, y = gets.chomp.chars, gets.chomp.chars
  m, n = x.size, y.size
  for i in 0..m
    dp[i][0] = 0
  end
  for j in 0..n
    dp[0][j] = 0
  end
  for i in 1..m
    for j in 1..n
      a, b = dp[i-1][j], dp[i][j-1]
      dp[i][j] = (a > b ? a : b)
      if x[i-1] == y[j-1]
        c = dp[i-1][j-1] + 1
        dp[i][j] = c if dp[i][j] < c
      end
    end
  end
  p dp[m][n]
end

Measured memory_bytes: 16704
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    scanf("%i %i", &a,&b);
    if (a<b)
    {
        printf("a < b\n");
    }
    else if (a>b)
    {
        printf("a > b\n");
    }
    else if(a == b)
    {
        printf("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2040
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

ll a,b,k;

int main(){
  cin>>a>>b>>k;
  if(a<=k){
    b-=(k-a);
    a=0;
    b=max(0LL,b);
  }
  else{
    a-=k;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin >> N;
    int a[N], ans[N] = {}, d[N], dans[N];
    rep(i, 0, N) cin >> a[i];
    // rep(i, 0, N)
    // {
    //     int tmp = 1, count = 1;
    //     while (a[i] > tmp)
    //     {
    //         tmp <<= 1;
    //         ++count;
    //     }
    //     d[i] = count - 1;
    // }
    int max = a[0];
    rep(i, 1, N)
    {
        max ^= a[i];
    }
    rep(count, 0, N)
    {
        int tmp = max;
        tmp ^= a[count];
        ans[count] = tmp;
    }
    rep(i, 0, N)
    {
        printf("%d", ans[i]);
        if (i < N - 1)
            putchar(' ');
    }
    putchar('\n');
}
int main()
{
    func();
}

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

int main(){
  int s;
  cin >> s;
  int a[1000000];
  a[0]=s;
  for (int i=1;i<1000000;i++){
    if (a[i-1] % 2 ==0){
      a[i]=a[i-1]/2;
    }
    else{
      a[i]=3*a[i-1]+1;
    }
  }
  int ans=1;
  for (int i=0;i<1000000;i++){
    if (a[i]!=4){
      ans++;
    }
    else {
      break;
    }
  }
  if (s==1){
    cout << 4 << endl;
  }
  else if (s==2){
    cout << 4 << endl;
  }
  else{
    cout << ans+3 << endl;
  }
}
    
      
    

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

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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;
	vector<int> p(n*n);
	for(int i=0; i<n*n; i++){
		cin >> p[i];
		p[i]--;
	}

	vector<vector<int>> s(n, vector<int>(n));
	vector<vector<bool>> done(n, vector<bool>(n));
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			s[i][j] = min(min(i, n-1-i), min(j, n-1-j));
		}
	}

	vector<pair<int, int>> q(n*n);
	for(int i=0; i<n*n; i++){
		q[i] = {p[i]/n, p[i]%n};
	}

	ll ans = 0;
	int dx[] = {0, -1, 0, 1};
	int dy[] = {-1, 0, 1, 0};
	for(int i=0; i<n*n; i++){
		int x = q[i].first;
		int y = q[i].second;
		dbg(x, y, s[x][y]);
		ans += s[x][y];
		done[x][y] = true;
		queue<pair<int, pair<int, int>>> que;
		for(int k=0; k<4; k++){
			int nx = x+dx[k];
			int ny = y+dy[k];
			if(0<=nx&&nx<n&&0<=ny&&ny<n&&s[x][y]<s[nx][ny]) que.push({s[x][y], {nx, ny}});
		}

		while(!que.empty()){
			int r = que.front().first;
			int x = que.front().second.first;
			int y = que.front().second.second;
			que.pop();
			if(r>=s[x][y]) continue;
			dbg("-", x, y, r);
			s[x][y] = r;
			for(int k=0; k<4; k++){
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(0<=nx&&nx<n&&0<=ny&&ny<n){
					int u = r;
					if(!done[x][y]) u++;
					if(u<s[nx][ny]) que.push({u, {nx, ny}});
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

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

typedef long long ll;
vector<pair<ll,ll>> v_p;
vector<pair<ll,ll>> v_g_s;
ll Q;
ll dfs(ll N, ll M, vector<ll> cur_vec) {
    ll res = 0;
    if (N==0) {
        REP(j, Q) {
            if (cur_vec[v_p[j].second] - cur_vec[v_p[j].first] == v_g_s[j].first) res += v_g_s[j].second;
        }
        return res;
    }
    for (ll i = max(1LL, cur_vec.back()); i <= M; i++) {
        cur_vec.push_back(i);
        res = max(res, dfs(N-1, M, cur_vec));
        cur_vec.pop_back();
    }
    return res;
}
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, M; cin >> N >> M >> Q;
 
    REP(i, Q) {
        ll tmp_l, tmp_r, tmp_g, tmp_s; cin >> tmp_l >> tmp_r >> tmp_g >> tmp_s;
        v_p.push_back(make_pair(tmp_l, tmp_r));
        v_g_s.push_back(make_pair(tmp_g, tmp_s));
    }
    ll res = 0;
    
    vector<ll> start;
    start.push_back(0);
    res = dfs(N,M, start);
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3656
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s;
  cin >> s;
  string t;
  cin >> t;
  set<string> ans;
  rep(i, SZ(s)-SZ(t)+1){
    bool f = 1;
    rep(j, SZ(t)){
      if(s[i+j] != '?' && s[i+j] != t[j]){
        f = 0;
        break;
      }
    }
    if(f){
      string stmp = s;
      rep(j, SZ(t)){
        stmp[i+j] = t[j];
      }
      rep(j, SZ(s)){
        if(stmp[j] == '?'){
          stmp[j] = 'a';
        }
      }
      ans.emplace(stmp);
    }
  }
  if(SZ(ans)){
    print(*ans.begin());
  }else{
    print("UNRESTORABLE");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int dp[1000001];


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

	vector<int> h(n + 1);
	for (int i = 1; i <= n; i++) cin >> h[i];

	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);


	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

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

	if (a >= 3200){
		cout << s << endl;
	}else{
		cout << "red" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <limits>
using namespace std;

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

	int diff = 0;
	int easts = 0;
	int mini = numeric_limits<int>::max();
	for (int i=0; i<n; ++i)
	{
		if ('W' == s[i])
		{
			if (diff < mini)
			{
				mini = diff;
			}
			++diff;
		}
		else if ('E' == s[i])
		{
			--diff;
			if (diff < mini)
			{
				mini = diff;
			}

			++easts;
		}
	}

	cout << easts + mini << endl;
	
	return 0;
}

Measured memory_bytes: 900
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
ans = [list('0')*w for i in range(h)]
temp = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1),
        (1, -1), (1, 0), (1, 1)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ans[i][j] = '#'
        else:
            count = 0
            for k in temp:
                i_temp, j_temp = i+k[0], j+k[1]
                if 0 <= i_temp < h and 0 <= j_temp < w:
                    if s[i_temp][j_temp] == '#':
                        count += 1
            ans[i][j] = count
    print(*ans[i], sep='')

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

int main() {
	int A,B,C,D;
    cin >> A >> B >> C >> D;
  	if(A + B > C + D){
    cout << "Left" << endl;
    }
  	else if(A + B == C + D){
    cout << "Balanced"  << endl;
    }
  	else{
    cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

const int MOD = 1e9+7;

long long mod_pow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m, n;
  cin >> m >> n;
  ll ans = mod_pow(m, n, MOD);
  cout << ans << endl;
  return 0;
}


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

int main(){
  
  int h1, h2, k1, k2, a, b, c, d, sum1, sum2;
  cin >> h1 >> h2;
  cin >> k1 >> k2;
  cin >> a >> b >> c >> d;
  sum1 = k1*a + k2*b + k1/10*c + k2/20*d;
  sum2 = h1*a + h2*b + h1/10*c + h2/20*d;
  if(sum1<sum2){
    cout << "hiroshi" << endl;
  }else if(sum1>sum2){
    cout << "kenjiro" << endl;
  }else{
    cout << "even" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3116
a = int(input())
b = []
c = 0
y = ""
for i in range(a):
    b.append(input().split(' '))
    #print(b)
x = input()
#print(x)
for i,j in b:
    if y == "x":
        c = c + int(j)
    #print(i)
    #print(j)
    if str(x) == str(i):
        y = "x"
print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define ll long long
#define M 1000000007
#define N 22
using namespace std;

ll n,k,a[N][N],dp[N][1<<N];
vector<int> states[N];

int main()
{
    cin>>n; FOR(i,1,n+1) FOR(j,1,n+1) cin>>a[i][j];
    for(int j=2;j<(1<<(n+1));j+=2) states[__builtin_popcount(j)].push_back(j);
    dp[0][0]=1;
    FOR(i,1,n+1)
    {
        for(int j: states[i])
        {
            FOR(k,1,n+1)
            {
                if(!(j&(1<<k)) || a[i][k]==0) continue;
                dp[i][j]=(dp[i][j]+dp[i-1][j^(1<<k)])%M;
            }
        }
    }
    cout<<dp[n][(1<<(n+1))-2]<<'\n';

    return 0;
}

Measured memory_bytes: 597436
#include <iostream>
#define ull unsigned long long
using namespace std;

int main()
{
    ull n;
    cin >> n;
    ull sum = (n+1)*n/2;
    ull temp = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(i % 3 == 0 || i % 5 == 0 || i % 15 == 0)
            temp += i;
    }
    cout << sum - temp;
}


Measured memory_bytes: 3160
/***************************************************
 * Problem Name : C - Next Prime.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-01-02
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
bool isPrime (ll n) {
    if (n == 1) return false;

    for (int i = 2; i <= sqrt (n); i++) {
        if (n % i == 0) return false;
    }

    return true;
}
int main () {
    __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    ll x;
    cin >> x;

    while (1) {
        if (isPrime (x) ) {
            cout << x << "\n";
            break;
        }

        x++;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int n,m,i,j;
char s;
int a[30];
int flag,ans;
int main()
{
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cin>>s;
			a[s-'a'+1]++;
		}
	}
	if(n%2==0&&m%2==0)
	{
		for(i=1;i<=26;i++)
		{
			if(a[i]%4!=0)
			{
				flag=1;
				break;
			}
		}
	} 
	else if(n%2==0&&m%2!=0)
	{
		int cnt=0;
		for(i=1;i<=26;i++)
		{
			if(a[i]%2!=0)
			{
				flag=1;
				break;
			}
			if(a[i]%2==0&&a[i]%4!=0)
				cnt++;
		}
		if(cnt>n/2)
			flag=1;
	}
	else if(n%2!=0&&m%2==0)
	{
		int cnt=0;
		for(i=1;i<=26;i++)
		{
			if(a[i]%2!=0)
			{
				flag=1;
				break;
			}
			if(a[i]%2==0&&a[i]%4!=0)
				cnt++;
		}
		if(cnt>m/2)
			flag=1;

	}
	else
	{
		int cnt=0;
		int tot=0;
		for(i=1;i<=26;i++)
		{
			if(a[i]%2==0&&a[i]%4!=0)
				cnt++;
			if(a[i]%2!=0)
				tot++;
		}
		if(cnt>(n-1)/2+(m-1)/2||tot>1||tot==0)
		{
				flag=1;
		}
	}
	if(flag==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using lint = long long;

lint getNum(const int l, const int r, const string& s) {
    lint result = 0;
    for (int i = l; i < r; i++) {
        result = (s[i] - '0') + result * 10;
    }
    return result;
}

int main() {
    string s;
    cin >> s;
    lint ans = 0;
    const int N = s.size();
    for (int bs = 0; bs < (1<<(N-1)); ++bs) {
        int l = 0;
        lint sum = 0;
        for (int i = 0; i < N-1; i++) {
            if ((bs>>i)&1) {
                sum += getNum(l, i+1, s);
                l = i+1;
            }
        }
        sum += getNum(l, N, s);
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int n, i, j, p, ans = 10000000,a[111];
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> a[i];
	for (i = -100; i <=100; i++) {
		p = 0;
		for (j = 0; j < n; j++)
			p += (i - a[j])*(i - a[j]);
		ans = min(ans, p);
	}
	cout << ans << endl;
}

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

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

        long x = sc.nextLong();

        long cu = 100;
        long ans = 0;

        while (cu<x){
            cu = cu + (cu/100);
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35616
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
q = list(map(int, input().split()))

flg = [0 for _ in range(2001)]

for i in range(2**N):
	out = 0
	for j in range(N):
		if i & (1 << j):
			out += A[j]

	if out <= 2000:
		flg[out] = 1

for i in range(Q):
	if flg[q[i]]:
		print('yes')
	else:
		print('no')


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) {
    cin >> x[i];
  }
  int ans = INF;
  for(int i=1; i<=100; i++) {
    int d = 0;
    rep(j, n) {
      d += pow(i-x[j],2);
    }
    ans = min(d, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define pb push_back
#define in(x) int x; cin>>x;
#define ln(x) long long x; cin>>x;
#define memf(a) memset(a,false,sizeof(a))
#define F first
#define S second
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main()
{
	fast
	int h1,w1,m;
	cin>>h1>>w1>>m;
	int h[m],w[m];
	map<int,int> m1,m2;
	int mx1=0,mx2=0;
	for(int i=0;i<m;i++)
	{
		cin>>h[i]>>w[i];
		m1[h[i]]++;
		m2[w[i]]++;
		mx1=max(mx1,m1[h[i]]);
		mx2=max(mx2,m2[w[i]]);
	}
	set<int> s1,s2;
	for(auto i:m1)
		if(i.S==mx1)
			s1.insert(i.F);
	for(auto i:m2)
		if(i.S==mx2)
			s2.insert(i.F);
	int x=*s1.begin();
	int y=*s2.begin();
	int f=0,ans;
	for(int i=0;i<m;i++)
		if(x==h[i] && y==w[i])
		{
			f=1;
			ans=mx1+mx2-1;
			break;
		}
	if(f==0)
	{
		ans=mx1+mx2;
		cout<<ans;
		// cout<<"Fuck";
		return 0;
	}
	int c=0;
	for(int i=0;i<m;i++)
	{
		if(s1.count(h[i]) && s2.count(w[i]))
			c++;
	}
	if((s1.size())*(s2.size())==c)
		ans=mx1+mx2-1;
	else
		ans=mx1+mx2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 62224
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int H, W, N, a[10010];
deque<int> deq;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>H>>W>>N;
    REP(i,0,N) cin>>a[i];

    int row = 0;
    int col = 0;
    int ind = 0;
    bool r = true;
    while(row < H){
        if(r && col==W) {
            r = false;
            col = W-1;
            row++;
            REP(i,0,deq.size()) cout<<deq[i]<<" ";
            deq.clear();
            cout<<endl;
        }else if(!r && col==-1){
            r = true;
            col = 0;
            row++;
            REP(i,0,deq.size()) cout<<deq[i]<<" ";
            deq.clear();
            cout<<endl;
        }else{
            if(a[ind] > 0){
                if(r) deq.push_back(ind+1);
                else deq.push_front(ind+1);
                a[ind]--;
            }else{
                ind++;
                if(r) deq.push_back(ind+1);
                else deq.push_front(ind+1);
                a[ind]--;
            }

            if(r) col++;
            else col--;
        }
    }

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    private static String solve(String s, String t) {
        char[] sa = s.toCharArray();
        char[] ta = t.toCharArray();
        int[][] lcsLen =  new int[sa.length+1][ta.length+1];

        for (int i = 0; i < sa.length; i++)
            for (int j = 0; j < ta.length; j++) {
                if (sa[i] == ta[j]) lcsLen[i+1][j+1] = 1 + lcsLen[i][j];
                else lcsLen[i+1][j+1] = Math.max(lcsLen[i+1][j], lcsLen[i][j+1]);
            }

        int maxLen = lcsLen[sa.length][ta.length];
        if (maxLen == 0) return "";
        char[] lcs = new char[maxLen];

        int i = sa.length;
        int j = ta.length;
        int k = maxLen-1;
        while (k >= 0) {
            if (j > 0 && lcsLen[i][j] == lcsLen[i][j-1]) j--;
            else if (i > 0 && lcsLen[i][j] == lcsLen[i-1][j]) i--;
            else {
                lcs[k--] = sa[i-1];
                i--;
                j--;
            }
        }

        return new String(lcs);
    }

    public static void main(String[] args) {
        String s, t;
        try (Scanner scanner = new Scanner(System.in)) {
            s = scanner.nextLine();
            t = scanner.nextLine();
        }

        String result = solve(s, t);
        System.out.println(result);
    }
}


Measured memory_bytes: 85792
n = int(input())
w = []
s = input().split()
for i in range(n):
    w.append(int(s[i]))
ans3 = []
for t in range(1,n):
    s1 = 0
    s2 = sum(w)
    for i in range(t):
        s1+=w[i]
    s2 = s2 - s1
    d = abs(s1 - s2)
    ans3.append(d)
print(min(ans3))

Measured memory_bytes: 3064
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}

console.log(main());

function main() {
    let N = next();
    let K = next();
    let A = nexts(N);
    let t = xArray(0, N);
    let B = Array(N);
    let i, j, k, left, right;
    for (k = 0; k < K; k++) {
        left = xArray(0, N);
        right = xArray(0, N);
        for (i = 0; i < N; i++) {
            // 各Aiの電球が照らす範囲の端の数を計算する。
            left[Math.max(i + 1 - A[i], 1) - 1]++;
            right[Math.min(i + 1 + A[i], N) - 1]++;
        }
        // 両端にすべての灯りが届いているかどうかをチェック。
        if (left[0] == N && right[N - 1] == N) {
            return xArray(N, N).join(" ");
        }
        // 各範囲の数を合計する。
        A[0] = left[0];
        for (i = 1; i < N; i++) {
            A[i] = A[i - 1] + left[i] - right[i - 1];
        }
    }
    return A.join(" ");
}

Measured memory_bytes: 88856
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, m;
    cin >> n >> m;
    map<long, long> l;
    bool z = true;
    for(int i = 0; i < m; i++){
        long a, b;
        cin >> a >> b;
        if(l.count(a) && l[a] != b){
            z = false;
            break;
        }
        l[a] = b;
        if((n != 1 && a == 1 && b == 0) || a > n){
            z = false;
            break;
        }
    }
    long ans = 0;
    long nn[][3] = {{1, 0, 0}, {10, 1, 0}, {100, 10, 1}};
    if(z){
        for(int i = 1; i <= n; i++){
            if(l.count(i)){
                ans += l[i] * nn[n-1][i-1];
            }else{
                if(i == 1) ans += nn[n-1][i - 1];
            }
            
        }
        if(n == 1 && m == 0) ans = 0;
        cout << ans << endl;
    }else cout << "-1" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a;
  cin >> N;
  a = N % 10;
    
  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) {
    cout << "hon" << endl;
  }
 
  if (a == 0 || a == 1 || a == 6 || a == 8) {
    cout << "pon" << endl;
  }
 
  if (a == 3) {
    cout << "bon" << endl;
  }
 
  
}

Measured memory_bytes: 3636
n, m = map(int, (input().split()))
x = list(map(int, input().split()))
x = sorted(x)
diff = []
for i in range(m-1):
    diff.append(x[i+1] - x[i])

diff = sorted(diff, reverse=True)

dist = x[-1] - x[0]
if dist < n:
    print(0)
    exit()

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

for i in range(n-1):
    dist -= diff[i]

print(dist)


Measured memory_bytes: 20476
H, W, D = map(int, input().split())

field = {}
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        field[A[j]] = (i,j)

Q = int(input())


cum = [0] * (H*W+1)
for i in range(D+1, H*W+1):
    cum[i] = cum[i-D] + abs(field[i][0] - field[i-D][0]) + abs(field[i][1] - field[i-D][1])

"""
for i in range(1,D+1):
    tmp = 0
    cum[i] = 0
    n = D
    while i+n <= H*W:
        cum[i+n] = cum[i+n-D] + abs(field[i+n][0] - field[i+n-D][0]) + abs(field[i+n][1] - field[i+n-D][1])
        #print("---", i+n, cum[i+n], field[i+n][0] , field[i+n-D][0], field[i+n][1] , field[i+n-D][1])
        n += D
"""
#print(cum)
LR = [None] * Q
for i in range(Q):
    L, R = map(int, input().split())
    LR[i] = (L,R)

for l,r in LR:
    print(cum[r] - cum[l])



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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll a, b, c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    while(a >= b) b *= 2, k--;
    while(b >= c) c *= 2, k--;
    cout << (k >= 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>

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

int main(void){
	int i,n,a[10],lcm;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	lcm=a[0];
	for(i=1;i<n;i++){
		if(a[i]<lcm){
			lcm=(a[i]/gcd(lcm,a[i]))*lcm;
		}else{
			lcm=(lcm/gcd(a[i],lcm))*a[i];
		}
	}
	printf("%d\n",lcm);
	return 0;
}	

Measured memory_bytes: 596
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S1 = sc.next();
		String S2 = sc.next();
		
		int cnt = 0;
		long ans = 0;
		int flag = 0;
		if(S1.substring(cnt, cnt + 1).equals(S2.substring(cnt, cnt + 1))) {
			ans = 3;
			cnt++;
			flag = 0;
		} else {
			ans = 6;
			cnt += 2;
			flag = 1;
		}
		
		while(cnt < S1.length()) {
			if(flag == 0) {
				if(S1.substring(cnt, cnt + 1).equals(S2.substring(cnt, cnt + 1))) {
					ans = ans * 2 % 1000000007;
					cnt++;
					flag = 0;
				} else {
					ans = ans * 2 % 1000000007;
					cnt += 2;
					flag = 1;
				}
			} else {
				if(S1.substring(cnt, cnt + 1).equals(S2.substring(cnt, cnt + 1))) {
					cnt++;
					flag = 0;
				} else {
					ans = ans * 3 % 1000000007;
					cnt += 2;
					flag = 1;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e16
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
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;
}
long long dp[150];

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main()
{
  ll X;
  cin >> X;

  REP(i,150){
    dp[i] = INF;
  }

  REP(i,10){
    dp[i] = i;
  }

  FOR(i,1,150){
    FOR(j,1,10){
      ll a = 1;
      ll b = GetDigit(dp[i]);
      REP(k,b){
        a*=10;
      }
      chmin(dp[i+j],dp[i]*10+j);
      chmin(dp[i+j],dp[i]+(j*a));
    }
  }

  
  int MAX = 0;
  REP(i,150){
    if(dp[i]<=X){
      chmax(MAX,i);
    }
  }
 
  cout << MAX << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 110;
const int INF = 0x3f3f3f3f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\n'

int x, n, t, a[MAXN];
void run(){
    cin >> x >> n;
    for(int i = 1; i <= n; i++)
        cin >> t, a[t] = 1;
    int mi = 110, ans;
    for(int i = 0; i <= 101; i++)
        if(!a[i] && abs(i - x) < mi) mi = abs(i - x), ans = i;
    cout << ans;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run();
}


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

using namespace std;

// Main function 
int main() 
{
    long int X;
    cin>>X;
    
    int a = 120, b = 120;
    
    for(int i = -118; i < 120; i++){
        for(int j = -119; j < 118; j++){
            if(i*i*i*i*i - j*j*j*j*j == X){
                a = i;
                b = j;
                break;
            }
        }
        if(a != 120 && b != 120){
            break;
        }
    }
    
    cout<<a<<" "<<b<<endl;
    return 0; 
} 

Measured memory_bytes: 3628