akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

int n;
vector<vector<int>> M(100, vector<int>(100));
vector<int> d(100), C(100);
static const int INFTY = INT_MAX;

void bfs(int s) {
	for (int i = 0; i < n; i++) {
		C.at(i) = 0;
		d.at(i) = INFTY;
	}

	C.at(s) = 1;
	d.at(s) = 0;
	queue<int>q;
	q.push(s);

	while (!q.empty()) {
		int u = q.front();
		q.pop();

		for (int i = 0; i < n; i++) {
			if (M.at(u).at(i) && (C.at(i) == 0)) {
				C.at(i) = 1;
				d.at(i) = d.at(u) + 1;
				q.push(i);
			}
		}

		C.at(u) = 2;
	}

	for (int i= 0; i < n; i++) {
		cout << i + 1 << ' ' << (d.at(i) == INFTY ? -1 : d.at(i)) << endl;
	}
}

int main() {
	int u, k, v;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v >> k;

		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			M.at(v - 1).at(x - 1) = true;
		}
	}

	bfs(0);

	return 0;
}


Measured memory_bytes: 3188
import numpy as np

n, c = list(map(int, input().split(' ')))
x, v = [], []

for i in range(n):
  x_, v_ = list(map(int, input().split(' ')))
  x.append(x_)
  v.append(v_)
x = np.array(x)
v = np.array(v)
sum_v = np.cumsum(v)
inv_x = c - x[::-1]
inv_v = v[::-1]
sum_inv_v = np.cumsum(inv_v)

cal = sum_v - x
inv_cal = sum_inv_v - inv_x

cal_cummax = np.maximum.accumulate(cal)
inv_cal_cummax = np.maximum.accumulate(inv_cal)

fr_double_cal = sum_v - 2 * x + \
    np.insert(inv_cal_cummax[:-1], 0, 0)[::-1]
fl_double_cal = sum_inv_v - 2 * inv_x + \
    np.insert(cal_cummax[:-1], 0, 0)[::-1]

print(np.max(
    [0, cal.max(), inv_cal.max(), fr_double_cal.max(), fl_double_cal.max()]))


Measured memory_bytes: 22908
#include <iostream>
using namespace std;
int main()
{
	char s;
	cin>>s;
	switch(s){
		case 'a': cout<<"vowel";break;
		case 'e':cout<<"vowel";break;
		case 'i':cout<<"vowel";break;
		case 'u':cout<<"vowel";break;
		case 'o':cout<<"vowel";break;
		default:
			cout<<"consonant";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
struct func{
  int num, denom;
  func(int num, int denom=1)
    : num(num), denom(denom)
    {

    }
  ~func(){

  }
};
func operator +(func const &l, func const &r){
  if(l.denom==r.denom) return func(l.num+r.num, l.denom);
  return func(l.num*r.denom+r.num*l.denom, l.denom*r.denom);
}
struct IntLike{
  int data;
  IntLike(int data)
    : data(data)
    {}
  IntLike operator +(IntLike const & right){
    return IntLike{data + right.data};
  }
};
struct array3{
  int storage[3];
  int & operator [](size_t i){
    return storage[i];
  }
};
int main(){
  string f = "first", sec = "second";
  int N;  cin>>N;
  vector<ll> v(N);
  rep(i,0,N) cin>>v[i];
  bool isPrime = 0;
  for_each(all(v), [&](auto x){if(x%2==1) isPrime = 1;});
  if(isPrime){
    cout << f << endl;
  }else{
    cout << sec << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,m; cin>>n>>m;
adj.resize(m+1);
for(int i=0;i<n;++i){
	int a,b; cin>>a>>b;
	if(a>m) continue;
	adj[a].pb(b);
}
int ans=0;
priority_queue<int> pq;
for(int i=1;i<=m;++i){
	for(auto j: adj[i]) pq.push(j);
	if(!pq.empty()) {
		ans+=pq.top();
		pq.pop();
	}
}
cout<<ans<<el;

return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


bool check(string &s){
  for (int i=0; i<s.size(); i++) if (s[i] != s[0]) return false;
  return true;
}

int solve(string &s, char c){
  if (find(all(s), c) == s.end()) return INT_MAX;
  string t = s;
  while (!check(t)){
    for (int i=0; i<t.size()-1; i++){
      if (t[i] == c) t[i] = c;
      if (t[i+1] == c) t[i] = c;
    }
    t.pop_back();
  }
  return s.size() - t.size();
}

int main() {
  string s; cin >>s;
  int res = 100;
  for (char c='a'; c<='z'; c++) chmin(res, solve(s, c));
  cout <<res <<endl;
}


Measured memory_bytes: 256
n = int(input())
a = [[0]*9 for _ in range(9)]
for i in range(n):
    if str(i+1)[0] != '0' and str(i+1)[-1] != '0':
        a[int(str(i+1)[0])-1][int(str(i+1)[-1])-1] += 1
        
ans = 0
for i in range(9):
    for j in range(9):
        ans += a[i][j]*a[j][i]
        
print(ans)

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};




int main(){
	int n;
	vector<int> sosu;
	cin >> n;
	sosu.pb(2);
	for(int i = 3; i <= 55555; i++){
		bool check = true;
		for(int j = 0; j < sosu.size(); j++){
			if(i%sosu[j] == 0) check = false;
		}
		if(check) sosu.pb(i);
	}
	for(int i = 0; i < n; i++){
		if(sosu[0]%5 == 1){
			cout << sosu[0];
			if(i != n-1) cout << " ";
		}else{
			i--;
		}
		sosu.erase(sosu.begin());
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
need = Counter(T)
aru = Counter(D)
for k in need:
    if aru[k] < need[k]:
        print('NO')
        exit()
print('YES')


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

const double PI=3.14159265358979323846;

int main() {
    double r;
    cin >> r ;
    
   cout << setprecision(10) << fixed << 2*r*PI << endl;
	return 0;
}



Measured memory_bytes: 3792
#include"stdio.h"
#include"math.h"

int cls(int);

int main()
{
  int n;
  int p;
  int i;
  int num=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&p);
      if(cls(p))num++;
    }
  printf("%d\n",num);
    return 0;
}

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


Measured memory_bytes: 2124
using System;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if (N % 1000 == 0)
                Console.WriteLine("0");
            else
            {
                int n = (N / 1000 + 1) * 1000;
                Console.WriteLine(n - N);
            }
        }
    }
}


Measured memory_bytes: 27376
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
using namespace std;

const long int INF = 1000000007;

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

    long sum = 0;
    int i = 1;
    while (sum < N)
    {
        sum += i;
        i++;
    }
    i--;
    // printf("sum : %d\ni : %d\n", sum, i);
    
    for (int j = i; N != 0; j--)
    {
        if (N - j >= 0)
        {
            cout << j << endl;
            N -= j;
        }
    }
}

Measured memory_bytes: 3584
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

h,w = m()

a = []
ans = []
for i in range(h):
	a.append(l())

for i in range(h):
	for j in range(w-1):
		if a[i][j] % 2 == 1:
			ans.append([i+1,j+1,i+1,j+2])
			a[i][j+1] += 1

for i in range(h-1):
	if a[i][w-1] % 2 == 1:
		ans.append([i+1,w,i+2,w])
		a[i+1][w-1] += 1
print(len(ans))
for ans in ans:
	print(*ans)


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

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

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      break;
    }

    if (i == B) {
      if (i % K != 0) {
        cout << "NG" << endl;
      }
    }

  }
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>


using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };


#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll n, a[4010];
char c[4010];
ll dp[2010][2010], costi[2010][2010], costj[2010][2010], it[3][2010];


struct BIT {
private:
	vector<ll>Bit;
	ll N;
public:
	void init(ll n) {
		N = n;
		Bit.resize(n);
	}
	void add(ll a, ll w) {
		for (int x = a; x < N; x += x & -x) Bit[x] += w;
	}
	int SUM(ll a) {
		ll ret = 0;
		for (int x = a; x > 0; x -= x & -x) ret += Bit[x];
		return ret;
	}
};


int main() {	
	cin >> n;
	for (int i = 1;i <= 2*n;i++) {
		cin >> c[i];
		cin >> a[i];
		a[i]--;
		if (c[i] == 'B')it[1][a[i]] = i;
		else 	it[0][a[i]] = i;
	}
	for (int i = 0;i <= n;i++) {
		BIT bit;
		bit.init(2 * n + 1);
		for (int k = 0;k < i;k++)bit.add(it[0][k], 1);
		for (int j = 0;j <= n;j++) {
			if (i != n) {
				costi[i][j] = i + j - bit.SUM(it[0][i]);
			}
			if (j != n) {
				costj[i][j] = i + j - bit.SUM(it[1][j]);
			}
			if (j == n) continue;
			bit.add(it[1][j], 1);
		}
	}
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n;j++) {
			if (i == 0 && j == 0)continue;
			ll s = INF;
			if (i > 0)s = min(s, dp[i - 1][j] + costi[i - 1][j]);
			if (j > 0)s = min(s, dp[i][j - 1] + costj[i][j - 1]);
			dp[i][j] = s;
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}



Measured memory_bytes: 94848
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin >> n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==n){
                cout << "Yes"<<endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,Q = map(int, input().split())
S = input()

t = [0]*Q
d = [0]*Q
for q in range(Q):
    t[q],d[q] = map(str, input().split())


s1 = 0
sN = N-1

for q in reversed(range(Q)):
    if t[q] == S[s1] and d[q] == 'L':
        s1 += 1
    elif s1 > 0:
        if d[q] == 'R' and S[s1-1] == t[q]:
            s1 -= 1
    if t[q] == S[sN] and d[q] == 'R':
        sN -= 1
    elif sN < N-1:
        if d[q] == 'L' and S[sN+1] == t[q]:
            sN += 1
    if s1 > sN:
        break
    #print(s1,sN)


print(sN-s1+1)

Measured memory_bytes: 6580
#include <iostream> 
#include <algorithm>
#include <cmath>
#include <vector>
#include <tuple>
#include <queue>  
#define ll long long
  
using namespace std; 

int main(){
    int n,m;
    cin >> n >> m;
    int pointer[200000];

    for (int i = 0; i < 200000; i++) pointer[i] = -1;
    pointer[0] = 0;

    vector< vector<int>> adj;
    for (int i = 0; i < n; i++) {
        vector<int> tmp;
        adj.push_back(tmp);
    }

    for (int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }

    queue<int> check_nodes;
    check_nodes.push(0);
    while(!check_nodes.empty()) {
        int cn = check_nodes.front();
        check_nodes.pop();
        for (int ad : adj[cn]) {
            if (pointer[ad] == -1) {
                pointer[ad] = cn;
                check_nodes.push(ad);
            }
        }
    }

    bool found = true;
    for (int i = 0; i < n; i++) {
        if (pointer[i] == -1){ 
            found = false;
            break;    
        }
    }

    if (found) {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i++) {
            cout << pointer[i]+1 << endl;
        }
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define int long long 

#define fs first
#define sc second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define pb push_back
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MP make_pair
#define sqr(x) ((x) * (x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 41, K = 17;
const int MOD = 1e9 + 7;
int add(int a, int b) {
	return (a + b + MOD) % MOD;
}

int dp[N][1 << K];

signed main() {
	fastio;
	#ifdef FlameDragon
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	int s = x + y + z;
	int need = (1 << (x - 1)) | (1 << (x + y - 1)) | (1 << (x + y + z - 1)); 
	int full = (1 << s) - 1;
	int ans = 1;
	for (int i = 1; i <= n; i++) {
		ans = 10ll * ans % MOD;
	}	
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < (1 << s); j++) {
			for (int k = 1; k <= 10; k++) {
				int mask = (j << k) | (1 << (k - 1));
				mask &= full;
				if ((mask & need) != need) 
					dp[i][mask] = add(dp[i][mask], dp[i - 1][j]);
			}
		}
	}
	for (int i = 0; i < (1 << s); i++) 
		ans = add(ans, -dp[n][i]);
	cout << ans << '\n';
}

Measured memory_bytes: 44528
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll a = 0, b = 0, c = 0;
    ll p = 1;
    for(int i = 0; i < n; i++){
        if(s[i] == 'A') a = (a + p) % MOD;
        if(s[i] == 'B') b = (b + a) % MOD;
        if(s[i] == 'C') c = (c + b) % MOD;
        if(s[i] == '?'){
            c = (c * 3 + b) % MOD;
            b = (b * 3 + a) % MOD;
            a = (a * 3 + p) % MOD;
            p = p * 3 % MOD;
        }
    }
    cout << c << endl;
}


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

const int MOD = (int)1e9+7;

int main(){
  long long N,M;
  cin >> N >> M;

  long long ans=0;
  for(long long i=1;i*i<=M;i++){
    if(M%i==0){
      long long x=i;
      long long y=M/i;
      if(x>=N)  ans=max(ans,y);
      if(y>=N)  ans=max(ans,x);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

  int w, a, b;
  cin >> w >> a >> b;

  if (a < b){
    if ((a + w) > b){
      cout << 0 << endl;
    }
    else {
      cout << b - (a + w) << endl;
    }
  }

  else {
    if ((b + w) > a){
      cout << 0 << endl;
    }
    else {
      cout << (a - (b + w)) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    max_attack = max(magic_list)[0]
    dp = [0] * (h + max_attack)

    # time O(HN)
    for hp in range(1, h + 1):
        dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)

    return dp[h]


main()


Measured memory_bytes: 41820
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define int long long
#define ll long long
#define us unsigned
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define nin(ary, n) for (int i = 0; i < (n); i++) cin >> ary[i]
#define nnin(ary, h, w) for (int i = 0; i < (h); ++i) for (int j = 0; j < (w); ++j) cin >> ary[i][j]
#define opt(conditions, a, b) cout << ((conditions) ? #a : #b) << endl
using namespace std;
const double PI = acos(-1.0);
const int MOD = 1e9 + 9;

int max_n(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_o(int ary[], int length) {
	int max;
	max = max_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_n(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_o(int ary[], int length) {
	int min;
	min = min_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int gcm(int a, int b) {
	int result = a;
	int k = 0;
	int n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while (k != 0);
	return result;
}

int gcm_n(int ary[], int length) {
	int g = ary[0];
	for (int i = 0; i < length; i++)
		g = gcm(g, ary[i]);
	return g;
}

int lcm(int a, int b) {
	int g, n;
	g = gcm(a, b);
	n = gcm(a, g);
	a = a / n;
	b = b / (g / n);
	return a*b;
}

int lcm_n(int ary[], int length) {
	int l = ary[0];
	for (int i = 0; i < length; i++)
		l = lcm(l, ary[i]);
	return l;
}

signed main() {
	char c = 'a';
	char s[1000000];
	cin >> s;
	string st = s;
	int size;
	size = st.size();
	sort(s, s+(signed)size);
	rep(i, size) {
		for(char a='a';a<='z';a++) {
			if (s[i] == c)
				c++;
		}
	}
	if ('a' <= c&&c <= 'z')
		cout << c << endl;
	else
		cout << "None" << endl;
		return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int n;
int a[N] ;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    cout << (n - 2) * 180;
    return 0;
}


Measured memory_bytes: 256
s=input()

n=len(s)
ans=[0]*n
r=0
l=0
for i in range(n):
  if s[i]=="R":
    r+=1
    
    if l%2==0:
      ans[i-l-1]+=(l//2)
      ans[i-l]+=(l//2)
    else:
      ans[i-l-1]+=(l//2)
      ans[i-l]+=(l//2)+1    
    l=0
  elif s[i]=="L":
    l+=1
    
    if r%2==0:
      ans[i-1]+=(r//2)
      ans[i]+=(r//2)
    else:
      ans[i-1]+=((r//2)+1)
      ans[i]=+(r//2)
      
    if i == n-1:
      if l%2==0:
        ans[i-l]+=(l//2)
        ans[i-l+1]+=(l//2)
      else:
        ans[i-l]+=(l//2)
        ans[i-l+1]+=(l//2)+1
    r=0

    
print(*ans)

    
    

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

pair<int, int> add(pair<int, int> p, pair<int, int> q) {
    if (p.first < q.first) swap(p, q);
    if (p.second < q.first) p.second = q.first; 
    return p;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    pair<int, int> v[1 << n];
    for (int i = 0; i < (1 << n); i++) {
        int c; cin >> c;
        v[i] = {c, 0};
    }
    for (int digit = 0; digit < n; digit++) {
        for (int i = 0; i < (1 << n); i++) {
            if (i & (1 << digit)) {
                v[i] = add(v[i], v[i & ~(1<<digit)]);
            }
        }
    }
    int ret = 0;
    for (int i = 1; i < (1 << n); i++) {
        ret = max(ret, v[i].first + v[i].second);
        printf("%d\n", ret);
    }
    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

int main() {
	long long int a,b,c,k,result=0;
	scanf("%lld%lld%lld%lld", &a, &b, &c,&k);
	int two[12] = { 1,2,4,8,16,32,64,128,256,512,1024 };
	printf("%lld",(two[k]-1)*big(a,big(b,c))+a+b+c);
}

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


int main() {
    vector<int> antennas(5);
    for (int i = 0; i < 5; i++) cin >> antennas[i];
    int k; cin >> k;


    string ans;
    int diff = antennas[4] - antennas[0];
    if (diff <= k) {
        ans = "Yay!";
    } else {
        ans = ":(";
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int K;
    string s,t,u;
    cin>>K>>s;
    if(s.size()<=K) p(s);
    else{
        t=s.substr(0,K);
        cout<<t<<"..."<<endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int n;
    cin >> n;
    if (n <= 111) {
        cout << 111 << endl;
    } else if (111 < n && n <= 222) {
        cout << 222 << endl;
    } else if (222 < n && n <= 333) {
        cout << 333 << endl;
    } else if (333 < n && n <= 444) {
        cout << 444 << endl;
    } else if (444 < n && n <= 555) {
        cout << 555 << endl;
    } else if (555 < n && n <= 666) {
        cout << 666 << endl;
    } else if (666 < n && n <= 777) {
        cout << 777 << endl;
    } else if (777 < n && n <= 888) {
        cout << 888 << endl;
    } else if (888 < n && n <= 999) {
        cout << 999 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
"""
日本でよく使われる紙幣は、10000円札、5000円札、1000円札です。
以下、「お札」とはこれらのみを指します。

青橋くんが言うには、彼が祖父から受け取ったお年玉袋には、
お札がN枚入っていて、合計でY円だったそうですが、嘘かもしれません。
このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。
なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。

入力は以下の形式で標準入力から与えられる。
>>> N Y
"""

lis = input().split()
N, Y = [int(x) for x in lis]

# 10000円札、5000円札、1000円札がそれぞれA, B, C枚とする。
maxA = min(Y // 10000, N)
bl = True

for A in range(maxA + 1):
    d = Y - 10000 * A
    n = N - A
    
    """ 
    この時、解くべき連立方程式
    B + C = n
    5000 * B + 1000 * C = d
    であり、これを解くと
    B = (d - 1000 * n) / 4000
    C = (5000 * n - d) / 4000
    
    """
    B_times_4k = d - 1000 * n
    C_times_4k = 5000 * n - d
    
    cond1 = B_times_4k >= 0 and C_times_4k >= 0
    cond2 = B_times_4k % 4000 == 0 and C_times_4k % 4000 == 0

    if cond1 and cond2:
        B = B_times_4k // 4000
        C = C_times_4k // 4000
        print('{} {} {}'.format(A, B, C))
        bl = False
        break

if bl:
    print('-1 -1 -1')

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

using namespace std;

int main()
{
    
    int N, a;
    vector<int> vec;
    
    cin >> N;
    
    for(int i = 0; i < N; ++i)
    {
        cin >> a;
        vec.push_back(a);
    }
    
    long ans_sum , ans_min, ans_max;
    
    ans_sum = 0;
    ans_min = 1000000;
    ans_max = -1000000;
    
    for(int i = 0; i < N; ++i)
    {
       if(vec[i] < ans_min) ans_min = vec[i];
       if(vec[i] > ans_max) ans_max = vec[i];
       ans_sum += vec[i];
    }
      
    cout << ans_min << " " << ans_max << " " << ans_sum << endl;
    
    return 0;
}


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

using namespace std;
vector<long> G;

long insertionSort(vector<unsigned long>& objective_array,long len_array,long g){
    long counter = 0;
    for(long i = g;i < len_array;i++){
        long v = objective_array[i];
        long j = i-g;
        while(j>=0 && objective_array[j] > v){
            objective_array[j+g] = objective_array[j];
            j-=g;
            counter++;
        }
        objective_array[j+g] = v;
    }  
    return counter;
}

long shellSort(vector<unsigned long>& objective_array,long len_array){
    long counter = 0;
    long h = 1;
    while(h <= len_array){
        G.push_back(h);
        h = 3*h + 1;
    }
    for(int i = 0;i < G.size();i++){
        counter += insertionSort(objective_array,len_array,G[G.size()-i-1]);
    }
    return counter;
}


int main(){
    unsigned long n;
    cin >> n;
    vector<unsigned long> num_array(n,0);
    rep(i,n){
        cin >> num_array[i];
    }
    long counter = shellSort(num_array,n);
    
    cout << G.size() << "\n";
    for(int i = 0;i < G.size();i++){
        cout << G[G.size()-1-i];
        if(i < G.size()-1) cout << " ";
        else cout << "\n";
    }
    cout << counter << "\n";
    rep(i,n){
        cout << num_array[i] << "\n";
    }
    

    return 0;   
}


Measured memory_bytes: 10640
import sys
from collections import deque


def LS():
    return list(input().split())


S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
    A = LS()
    if A[0] == "1":
        rev += 1
        rev %= 2
    else:
        if A[1] == "1":
            if rev == 0:
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if rev == 0:
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))


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

vector<int> par;

int find(int n){
	if(par[n]==n)return n;
	else return par[n]=find(par[n]);
}

void uni(int a,int b){
	if(a!=b){
		par[b]=a;
	}
}
 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i,j,n,m,a,b;
    cin>>n>>m;
    par=vector<int>(n+1);
    for(i=1;i<=n;i++)par[i]=i;
    while(m--){
    	cin>>a>>b;
    	a=find(a);
    	b=find(b);
    	uni(a,b);
    }
    set<int> s;
    for(i=1;i<=n;i++){
    	s.insert(find(i));
    }
    cout<<s.size()-1;


   

 
	
	
	
 
 
 
 
 
 
 
	return 0;
}

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

int main(void){
    int N, M;
    cin >> N >>M;
    
    vector<int> S(N), T(M);
    for (int i = 0; i < N; i++) {
    			cin >> S.at(i);
  	}
  	
    for (int i = 0; i < M; i++) {
    			cin >> T.at(i);
  	}
  	
  	
  	vector<vector<ll>> dp(N+1, vector<ll>(M+1,1)); 
  	ll P = 1000*1000*1000+7; 
  	
  	for(int i=1; i<=N; i++){
  	    ll sum=0; 
  	    for(int j=1; j<=M; j++){

  	        if(S.at(i-1)==T.at(j-1)){
  	            dp.at(i).at(j) = dp.at(i-1).at(j-1) + dp.at(i-1).at(j) + sum; 
  	            sum+= dp.at(i-1).at(j-1); 
  	            dp.at(i).at(j) = dp.at(i).at(j)%P;
  	            sum = sum%P; 
  	        }else{
  	            dp.at(i).at(j) = dp.at(i-1).at(j) + sum; 
  	            dp.at(i).at(j) = dp.at(i).at(j)%P;
  	        }
  	        //cout<< dp.at(i).at(j)<<" "; 
  	    }
  	    //cout<< endl; 
  	}
  	dp.at(N).at(M)=dp.at(N).at(M)%P; 
  	
  	cout<< dp.at(N).at(M);   	  	
    
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007,N=200001;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

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

vector<vector<ll> > v(N);
vector<ll> dpin(N,1),pa(N),dpout(N);

void dfs1(ll n,ll p){
	pa[n]=p;
	for(auto& to:v[n]){
		if(to==p)continue;
		dfs1(to,n);
		dpin[n]+=dpin[to];
	}
	return;
}

void dfs2(ll n,ll p){
	vector<ll> v1,v2;
	for(auto& to:v[n]){
		if(to==p)v1.pb(0),v2.pb(0);
		else v1.pb(dpin[to]),v2.pb(dpin[to]);
	}
	int niko=v1.size();
	for(int i=1;i<niko;i++)v1[i]+=v1[i-1];
	for(int i=niko-2;i>=0;i--)v2[i]+=v2[i+1];
    for(int i=0;i<niko;i++){
    	int to=v[n][i];
    	if(to==p)continue;
    	ll line=1LL;
    	if(i>0)line+=v1[i-1];
		if(i<niko-1)line+=v2[i+1];
		line+=dpout[n];
		dpout[to]=line;
		dfs2(to,n);
    }
    return;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n;
    for(int i=1;i<n;i++){
    	cin>>a>>b;
    	a--;b--;
    	v[a].pb(b);
    	v[b].pb(a);
    }
    ll ans=(n*(modpow(2LL,n-1)-1))%mod;
    dfs1(0,-1);
    dpout[0]=0;
    dfs2(0,-1);
    for(int i=0;i<n;i++){
    	(ans-=modpow(2LL,dpout[i])-1)%=mod;
    	for(auto& to:v[i]){
    		if(to==pa[i])continue;
    		(ans-=modpow(2LL,dpin[to])-1)%=mod;
    	}
    }
    (ans*=modpow(2LL,n*(mod-2)))%=mod;
    (ans+=mod)%=mod;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 48256
using System;
class panasonic_a{
  public static void Main(){
    int[] num = new int[32]{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 n = int.Parse(Console.ReadLine());
    Console.WriteLine(num[n-1]);
  }
}


Measured memory_bytes: 11092
from collections import deque

def bfs(graph, stack, visited, times):
    cnt = 0
    while stack:
        a,cost = stack.popleft()
        if cost > times:
            stack.appendleft([a,cost])
            break
        for b in graph[a].keys():
            if not visited[b]:
                stack.append([b,cost+1])
                visited[b] += 1 
                cnt += 1
    return cnt

def bi_bfs(graph, start, goal):
    s_stack, g_stack = deque(), deque()
    s_stack.append([start,0])
    g_stack.append([goal, 0])
    visited = [0 for i in range(N+1)]
    visited[start] = visited[goal] = 1 
    s_cnt = g_cnt = 1
    times = 0

    while s_stack or g_stack:
        s_cnt += bfs(graph, s_stack, visited, times)
        g_cnt += bfs(graph, g_stack, visited, times)
        times += 1
    return s_cnt > g_cnt

N = int(input())
graph = {}
for i in range(N-1):
    a,b = map(int, input().split())
    if a not in graph:
        graph[a] = {}
    if b not in graph:
        graph[b] = {}
    graph[a][b] = graph[b][a] = 1
print('Fennec' if bi_bfs(graph,1,N) else 'Snuke')


Measured memory_bytes: 48340
def main():
    d = list(input())
    alp = [chr(i) for i in range(65, 65 + 26)]

    for x in range(len(d)):
        idx = alp.index(d[x]) - 3
        if idx < 0:
            idx = 26 + idx
        else:
            pass
        d[x] = alp[idx]

    ans = ""
    for x in d:
        ans += x
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 7544
import java.util.HashSet;
import java.util.Scanner;

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

		HashSet<Integer> set = new HashSet<Integer>();
		set.add(a);
		set.add(b);
		set.add(c);
		System.out.println(set.size() == 2 ? "Yes" : "No");
	}
}


Measured memory_bytes: 22996
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int main(){

	int n;
	cin>>n;

	vector<int> a(n);
	set<int> b[100000];
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
		b[a[i]].insert(i);
	}

	int res=0;
	for(int i=0;i<n;i++){
		if(b[i].find(a[i])!=b[i].end()) res++;
	}
	cout<<res/2<<endl;

}


Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>

using namespace std;

#define MAXN (17)
#define INF  (1<<29)
#define X    real()
#define Y    imag()

typedef complex<double> P;

template<class T>
inline T Sq(T x) { return x*x; }

inline double getDist(P, P);
struct Segment {
  P s, t;
  double d;
  Segment() {}
  Segment(P s, P t) : s(s), t(t) { d = getDist(s, t); }
};

inline double getDist(P a, P b) { return sqrt(Sq(a.X-b.X)+Sq(a.Y-b.Y)); }
inline double getDist(Segment sg) { return sqrt(Sq(sg.s.X-sg.t.X)+Sq(sg.s.Y-sg.t.Y)); }

int n;
double dist[MAXN][2][MAXN][2]; // seg s: 0, t: 1
double dp[1<<MAXN][MAXN][2];
Segment seg[MAXN];

int main() {
  
  int tcase = 1;
  double x1, y1, x2, y2;
  double allseglen;
  
  while(cin >> n, n) {
    
    allseglen = 0.0;
    
    for(int i=0; i<n; i++) {
      cin >> x1 >> y1 >> x2 >> y2;
      seg[i] = Segment(P(x1, y1), P(x2, y2));
      allseglen += seg[i].d;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	
	if(i == j) {
	  for(int ii=0; ii<2; ii++) {
	    for(int jj=0; jj<2; jj++) {
	      if(ii == jj) { dist[i][ii][j][jj] = 0; }
	      else { dist[i][ii][j][jj] = seg[i].d; }
	    }
	  }
	  
	  continue;
	}
	
	dist[i][0][j][0] = getDist(seg[i].s, seg[j].s);
	dist[i][0][j][1] = getDist(seg[i].s, seg[j].t);
	dist[i][1][j][0] = getDist(seg[i].t, seg[j].s);
	dist[i][1][j][1] = getDist(seg[i].t, seg[j].t);
	
      }
    }
        
    for(int i=0; i<(1<<n); i++)
      for(int j=0; j<n; j++)
	for(int k=0; k<2; k++)
	  dp[i][j][k] = INF;
      
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	dp[1<<i][i][j] = 0;
    
    for(int S=0; S<(1<<n); S++){
      for(int u=0; u<n; u++){
	if( !( (S>>u) & 1 ) ) continue;
	for(int i=0; i<2; i++){
	  if(dp[S][u][i] == INF) continue;
	  for(int v=0; v<n; v++){
	    if( (S>>v) & 1 ) continue;
	    if(u == v) continue;
	    for(int j=0; j<2; j++){
	      int T = S | (1<<v);
	      dp[T][v][j] = min(dp[T][v][j], dp[S][u][i] + dist[u][(i+1)&1][v][j]);
	    }
	  }
	}
      }
    }
    
    double ans = INF;
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	ans = min(ans, dp[(1<<n)-1][i][j]);
    
    printf("Case %d: %f\n", tcase++, ans + allseglen);
  }
  
  return 0;
}

Measured memory_bytes: 7388
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m;
	cin >> m;
	int arr[m][3],i,j,k;
	for(i=0;i<m;i++)
	cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	for(i=1;i<m;i++)
	{
		arr[i][0]+=max(arr[i-1][1],arr[i-1][2]);
		arr[i][1]+=max(arr[i-1][0],arr[i-1][2]);
		arr[i][2]+=max(arr[i-1][0],arr[i-1][1]);
	}
	cout << max(arr[m-1][0],max(arr[m-1][1],arr[m-1][2]));
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }
 
   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

int main(){
  int n;
  cin >> n;
  int w[n];
  rep(i,n)cin >> w[i];
  int sum=0;
  rep(i,n)sum+=w[i];
  int temp=0;
  int ans=inf;
  rep(i,n){
    ans=min(ans,abs(2*temp-sum));
            temp+=w[i];
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (H, W) = Read2Longs();
            var output = new StringBuilder();
            for (var i = 0; i < H; i++)
            {
                var text = ReadText();
                output.AppendLine(text);
                output.AppendLine(text);
            }
            return output.ToString().Trim();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28300
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int lli;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1},dy[]={0,1,0};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct State{
	int x,y,d,o,s;
	State(int a,int b,int h,int e,int g):x(b),y(a),d(h),o(e),s(g){}
	bool operator>(const State& s)const{
		return d>s.d;
	}
};

int W,H,f,m,o,c[10][10],d[10][10][51][1<<10],ans;

void Solve(){
	fill_n((int*)d,10*10*51*(1<<10),INF);
	ans=INF;
	priority_queue<State,vector<State>,greater<State>> que;
	REP(x,0,W){
		int cost=0,oxy=o-1;
		if(oxy<=1) continue;
		if(c[0][x]<0) cost=-c[0][x];
		else oxy=min(m,oxy+c[0][x]);
		if(cost>f) continue;
		d[0][x][oxy][1<<x]=cost;
		que.push(State(0,x,cost,oxy,1<<x));
	}
	while(!que.empty()){
		State v=que.top();
		que.pop();
		int vy=v.y,vx=v.x,vd=v.d,vo=v.o,vs=v.s;
		if(vy==H-1) ans=min(ans,d[vy][vx][vo][vs]);
		if(d[vy][vx][vo][vs]<vd||vo<=1) continue;
		REP(i,0,3){
			int ny=vy+dy[i],nx=vx+dx[i];
			if(ny<0||H<=ny||nx<0||W<=nx) continue;
			int cost=0,no=vo-1,ns=vs|(1<<nx);
			if(ny!=vy||((vs>>nx)&1)==0){
				if(c[ny][nx]<0) cost=-c[ny][nx];
				else no=min(m,no+c[ny][nx]);
			}
			if(ny!=vy) ns=1<<nx;
			if(vd+cost<d[ny][nx][no][ns]&&vd+cost<=f){
				d[ny][nx][no][ns]=vd+cost;
				que.push(State(ny,nx,d[ny][nx][no][ns],no,ns));
			}
		}
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while(true){
		cin >> W >> H;
		if(W==0&&H==0) break;
		cin >> f >> m >> o;
		REP(y,0,H) REP(x,0,W) cin >> c[y][x];
		Solve();
		if(ans==INF) cout << "NA";
		else cout << ans;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 21736
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  ll H,N; cin>>H>>N;
  vl A(N), B(N); REP(i,N) cin>>A[i]>>B[i];

  vvl dp(N+MGN, vl(H+MGN, LINF));
  REP(i,N) {
    FOR(j,1,H+MGN) {
      int num = (j+A[i]-1)/A[i];
      dp[i][j] = B[i]*num;
    }
  }

  FOR(i,1,N) {
    FOR(j,1,H+MGN) {
      dp[i][j] = min(dp[i][j], dp[i-1][j]);
      if (j-A[i]>=0) {
        dp[i][j] = min(dp[i][j], dp[i][j-A[i]]+B[i]);
      }
    }
  }

  ll ans = dp[N-1][H];
  cout << ans << endl;


  return 0;
}

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

void call(int);

int main() {
    int n;
    cin >> n;
    
    call(n);
    
    return 0;
}

void call(int n)
{
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        else if (i % 10 == 3 || (i / 10) % 10 == 3 || (i / 100) % 10 == 3 || (i / 1000) % 10 == 3 || (i / 10000) % 10 == 3)
        {
            cout << " " << i;
            continue;
        }
    }
    cout << endl;
}


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

int main(){
  int n;
  cin >> n;
  
  int a[n];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  long int first_pos = 0;
  int sum1 = 0;
  for (int i = 0; i < n; i++){
    sum1 += a[i];
    if (i % 2 == 0){
      if (sum1 <= 0){
        first_pos += -sum1 + 1;
        sum1 = 1;
      }
    }else{
      if (sum1 >= 0){
        first_pos += sum1 + 1;
        sum1 = -1;
      }
    }
  }
  
  long int first_neg = 0;
  int sum2 = 0;
  for (int i = 0; i < n; i++){
    sum2 += a[i];
    if (i % 2 == 0){
      if (sum2 >= 0){
        first_neg += sum2 + 1;
        sum2 = -1;
      }
    }else{
      if (sum2 <= 0){
        first_neg += -sum2 + 1;
        sum2 = 1;
      }
    }
  }
  
  cout << min(first_pos, first_neg) << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans=1000000;
  for(int i=2;i<(n+4)/2;i++){
    int a=i,b=n-i;
    int suma=0,sumb=0,sum=0;
    while(a>0){
      suma+=a%10;
      a=a/10;
    }
    while(b>0){
      sumb+=b%10;
      b=b/10;
    }
    sum=suma+sumb;
    if(sum<ans)ans=sum;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256