akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		sort(ALL(A));
		ll ans=INF;
		REP(x, 101) {
			ll v=0;
			REP(i, N) v+=(A[i]-x)*(A[i]-x);
			minUpdate(ans, v);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> AC(N, false);
    vector<int> P(N, 0);
    for (int i = 0; i < M; i++) {
        int p; string S;
        cin >> p >> S; p--;
        if (S == "AC") AC[p] = true;
        if (S == "WA") {
           if (!AC[p]) P[p]++;
        }
    }

    int ans = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (AC[i]) {
            ans++;
            sum += P[i];
        }
    }
    
    cout << ans<< " " << sum << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////
#define N 200005

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return mod(po(mod(mod(i)*mod(i)),p/2));
    else  return mod(mod(i)*mod(po(i,p-1)));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    for(int i=1;i<N;i++){
        kai[i]=mod(kai[i-1]*i);
        kai2[i]=mod(po(kai[i],i_5));
    }
}
ll comb(ll n,ll k){
    if(n==0){
        if(k==0)return 1;
        else return 0;
    }
    else if(n<k)return 0;
    else return mod(mod(mod(kai[n])*mod(kai2[n-k]))*mod(kai2[k]));
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    calc();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ans=0;
    ll p=h-a-1,q=b;
    while(p>=0&&q<=w-1){
        ll plus=mod(comb(b+(h-a-1),q)*comb((h-p-1)+(w-q-1),h-p-1));
        ans=mod(ans+plus);
        p--;q++;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String s = sc.next();
    String sm = s.substring(0,k-1);
    String sa = s.substring(k,s.length());
    String ss = s.substring(k-1,k).toLowerCase();
    System.out.println(sm + ss + sa);
  }
}


Measured memory_bytes: 21588
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();

		int[] arr = new int[N];

		int sum = 0;
		for (int i = 0; i < arr.length; i++) {
			int n = sc.nextInt();
			sum += arr[i] = n;
		}

		double ave = (double)sum / N;
		double subMin = 100;
		int imin = 0;
		for (int i = 0; i < arr.length; i++) {
			double sub = arr[i] - ave;
			if (sub < 0) {
				sub /= -1.0;
			}
			if (subMin > sub) {
				subMin = sub;
				imin = i;
			}
		}
		System.out.println(imin);
		sc.close();
	}

}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < H; i++) {
    vector<char> vec(W);
    cout << '#';
    for (int j = 0; j < W; j++) {
      cin >> vec.at(j);
      cout << vec.at(j);
    }
    cout << '#' << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}

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

bool isRed(int i, int j, int bith, int bitw){
    if(((1 << i) & bith) || ((1 << j) & bitw)) return true;
    else return false;
}

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

    int h,w,k; cin >> h >> w >> k;
    vector<string> c(h); rep(i,h) cin >> c[i];
    int ans = 0;
    for(int bith = 0; bith < (1<<h); ++bith){
        for(int bitw = 0; bitw < (1<<w); ++bitw){
            int black = 0;
            rep(i,h) rep(j,w) if((!isRed(i,j,bith, bitw)) && c[i][j] == '#') ++black;
            if(black == k) ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         998244353
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x;
    cin>>n;
    string s;
    vector<pair<string,pair<ll,ll> > > vi;
    for(i=1;i<=n;i++){
        cin>>s>>x;
        vi.pb(mp(s,mp(x,i)));
    }
    sort(vi.begin(),vi.end());
    vector<pair<ll,ll> > vi1;
    for(i=1;i<n;i++){
        //cout<<vi[i-1].ff<<" "<<vi[i].ff<<endl;
        if(vi[i-1].ff==vi[i].ff){
            vi1.pb(mp(vi[i-1].se.ff,vi[i-1].se.se));
        }
        else{
            vi1.pb(mp(vi[i-1].se.ff,vi[i-1].se.se));
            reverse(vi1.begin(),vi1.end());
            for(auto j:vi1){
                cout<<j.se<<endl;
            }
            vi1.clear();
        }
    }
    vi1.pb(mp(vi[n-1].se.ff,vi[n-1].se.se));
    reverse(vi1.begin(),vi1.end());
    for(auto j:vi1){
        cout<<j.se<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a, b, c;
    
    scanf("%d %d %d",&a ,&b ,&c);
    
    if(a<b && b<c){
    	printf("Yes\n");
    }
    else{
    	printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
import math

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

def CP(p1, p2, p3):
    ax = p2.x-p1.x
    ay = p2.y-p1.y
    bx = p3.x-p1.x
    by = p3.y-p1.y
    return ax*by - ay*bx

def Judge(a,b,c):
    if a > 0 and b > 0 and c > 0:
        print("YES")
    elif a < 0 and b < 0 and c < 0:
        print("YES")
    else:
        print("NO")

def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    x1,y1,x2,y2,x3,y3,xp,yp = [float(i) for i in N[l].split()]
    P1 = Point(x1,y1)
    P2 = Point(x2,y2)
    P3 = Point(x3,y3)
    PP = Point(xp,yp)

    cp1 = CP(PP, P1, P2)
    cp2 = CP(PP, P2, P3)
    cp3 = CP(PP, P3, P1)

    Judge(cp1,cp2,cp3)


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, b, a) for (int i=(b); i>(a); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)

long long INF = 1LL<<60;
long long MOD = 1e9+7;

template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    FOR(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

const int BIG = 3e6+5;
int fact[BIG], invfact[BIG];
int nCk(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*invfact[k] % MOD * invfact[n-k] % MOD;
}

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

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    fact[0] = 1;
    FOR(i, 1, BIG) fact[i] = i*fact[i-1] % MOD;
    invfact[BIG-1] = inv(fact[BIG-1]);
    ROF(i, BIG-2, -1) invfact[i] = (i+1) * invfact[i+1] % MOD;
    int res = 0;
    FOR(rr, r1, r2+1) {
        res = (res + (nCk(rr+c2+1, rr+1) - nCk(rr+c1, rr+1) + 3*MOD) % MOD) % MOD;
    }
    cout << res;
}

Measured memory_bytes: 47104
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int length;
	map<char, int> pair;
	string str;
	cin >> str;
	length = str.size();

	for(int i = 0; i < length; i++){
		pair[str[i]] = pair[str[i]] + 1; 
	}
	for(map<char, int>::iterator itr = pair.begin(); itr != pair.end(); ++itr){
		if(itr -> second % 2 != 0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

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

	vector<pair<int, int>> A(N);
	rep(i, N)
	{
		cin >> A[i].first;
		cin >> A[i].second;
	}
	sort(A.begin(), A.end());

	long long ans = 0;
	int j = 0;
	priority_queue<int> B;
	rep(i, M)
	{
		while(A[j].first <= i+1 && j <N)
		{
			B.push(A[j].second);
			j++;
		}
		if(!B.empty()){
			ans += B.top();
			B.pop();
		}
	}
	cout << ans;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll n, k; cin >> n >> k;
  vector<pair<int, int>> v(n);
  rep(i, n){
    cin >> v[i].first >> v[i].second;
  }
  sort(All(v));
  for(int i = 0; i < n; i++){
    k -= v[i].second;
    if(k <= 0){
      cout << v[i].first << endl;
      system("pause");
      return 0;
    }
  }

  system("pause");
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	string s;
	cin >> s;
	int N = s.size();
	V<int> v;
	rep(i,N){
		if(i == 0 || s[i] != s[i-1]) v.pb(1);
		else v.back()++;
	}
	V<int> ans(N);
	int ku = v[0];
	rep(i,v.size()/2){
		int l = v[i*2], r = v[i*2+1];
		ans[ku-1] = r/2 + (l+1)/2;
		ans[ku] = (r+1)/2 + l/2;
		if(i != (int)v.size()/2-1) ku += v[i*2+1] + v[i*2+2];
	}
	rep(i,N) cout << ans[i] << " ";
	cout << endl;
}


Measured memory_bytes: 1480
#include<stdio.h>

int  main () {
   int  x ,  a ,  b ;
   scanf ("%d%d%d" , &x , &a , &b ) ;
   if  (b-a<=0)
   printf("delicious\n");
   else if (b-a<=x)
   printf("safe\n");
   else 
   printf("dangerous\n");
   
   }

Measured memory_bytes: 128
n,c=map(int,input().split())
imos=[[0 for i in range(c)] for j in range(10**5+1)]#1~10**5+1
for i in range(n):
    s,t,_c=map(int,input().split())
    imos[s-1][_c-1]+=1
    imos[t][_c-1]-=1
for i in range(1,10**5+1):
    for j in range(c):
        imos[i][j]+=imos[i-1][j]
imosans=[0]*(10**5+1)
for i in range(10**5+1):
    for j in range(c):
        imosans[i]+=(imos[i][j]>=1)
print(max(imosans))

Measured memory_bytes: 45492
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,l[1000],r[1000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>l[i]>>r[i];
	}
	int ans=0;
	for(int j=0;j<N;j++){
		ans=ans+(r[j]-l[j]+1);
	}
	cout<<ans;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v[n];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    bool ok = false;
    for (auto first : v[0]) {
        if (first == n - 1) ok = true;
        for (auto second : v[first]) {
            if (second == n - 1) ok = true;
        }
    }

    if (ok)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 15016
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int i=0;
    while(i<=s.size()-1){
        if(s.substr(i,5)=="maerd")i+=5;
        else if(s.substr(i,7)=="remaerd")i+=7;
        else if(s.substr(i,5)=="esare")i+=5;
        else if(s.substr(i,6)=="resare")i+=6;
        else{
            cout<<"NO"<<endl;
            exit(0);
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int dp[3001][3001];

int main() {
    string s, t;
    cin >> s >> t;

    int n = (int)s.size();
    int m = (int)t.size();

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = max({ dp[i][j + 1], dp[i + 1][j], dp[i][j] + (s[i] == t[j]) });
            //cout << dp[i + 1][j + 1] << " \n"[j == m - 1];
        }
    }

    int k = dp[n][m];
    string r(k, 0);
    for (int i = n, j = m; k > 0;) {
        while (dp[i][j - 1] == k) j--;
        while (dp[i - 1][j] == k) i--;
        i--; j--;
        r[--k] = s[i];
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 35456
fun main(args: Array<String>) {
  val input1 = readLine()!!.split(" ").map(String::toInt)
  var lifeT = input1[0]
  var attT = input1[1]
  var lifeA = input1[2]
  var attA = input1[3]
  var isContinue = true
  var result = "No"
  while(isContinue) {
    lifeA -= attT
    isContinue = lifeA > 0
    if (!isContinue) {
      result = "Yes"
      break
    }
    lifeT -= attA
    isContinue = lifeT > 0
    if (!isContinue) {
      break
    }
  }
  println(result)
}


Measured memory_bytes: 36380
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, x, y);
	bool ans = false;
	incII(i, 0, x) {
		ans |= (2 * i + 4 * (x - i) == y);
	}
	OUT(ans ? "Yes" : "No");
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
map<int, int> n_match={{1,2}, {2,5}, {3,5}, {4,4}, {5,5}, {6,6}, {7,3}, {8,7}, {9,6}};

int main(){
  int N, M;cin>>N>>M;
  vi A;
  for (int i=0;i<M;++i){int a;cin>>a;A.push_back(a);}

  vi use_list(10, -1);
  for (int i=2;i<=7;++i){
    for (int m=0;m<M;++m){
      if(n_match[A[m]]==i) use_list[i]=max(use_list[i], A[m]);
    }
  }

  vvi dp(N+10, vi(10,-1));

  dp[0]=vi(10,0);

  for (int i=0;i<=N;++i){
    for (int j=2;j<=7;++j){
      if(use_list[j]==-1) continue;
      dp[i][10-use_list[j]]++;dp[i][0]++;
      dp[i+j]=max(dp[i], dp[i+j]);
      dp[i][10-use_list[j]]--;dp[i][0]--;
    }
  }

  for (int i=1;i<10;++i){
    for (int j=0;j<dp[N][i];++j){
      cout << 10-i;
    }
  }

  return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int mem[N + 1];
    for (int i = 1; i <= N; ++i) {
        int P;
        cin >> P;
        mem[P] = i;
    }

    int maxcnt = 1;
    int cnt = 1;
    for (int i = 1; i < N; ++i) {
        if (mem[i] < mem[i + 1]) {
            cnt++;
        } else {
            maxcnt = max(maxcnt, cnt);
            cnt = 1;
        }
        if (i == N - 1) {
            maxcnt = max(maxcnt, cnt);
        }
    }
//    cnt = 1;
//    for (int i = N; i > 1; --i) {
//        if(mem[i] > mem[i-1]){
//            cnt++;
//        }
//    }

    cout << N - maxcnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>

int X;
using namespace std;

int main()
{
	cin >> X;
	int a1 = (X / 500) * 1000;
	X %= 500;
	int a2 = (X / 5) * 5;
	cout << a1 + a2 << endl;
}


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

using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define all(a) a.begin(),a.end()
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
ll fac[200001];

 long long power( long long x, 
                         ll y, ll p) 
{ 
    long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
 long long modInverse( long long n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
 long long nCrModPFermat(long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    
    
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
  

void powe(ll p)
{
    fac[0] = 1; 
    for (int i = 1; i <= 200000; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
    
}

int main() {
ll n,m,k;
cin>>n>>m>>k;
ll sum=0;
string s[n];
f(i,0,n)
{
    cin>>s[i];
}
ll sm=0;
f(i,0,n)
f(j,0,m)
if(s[i][j]=='#')
sm++;

f(i,0,pow(2,n))
{
   // cout<<"i= "<<i<<endl;
    ll yemp=sm;
    ll vis[n][m];
    f(h,0,n)
    f(w,0,m)
    vis[h][w]=0;
    
    ll temp=i;
    ll c=0;
    while(temp)
{
    ll val=temp%2;
    if(val)
    {
        f(ii,0,m)
        {
            vis[c][ii]=1;
            if(s[c][ii]=='#')
            yemp--;
        }
    }
    
    
    temp=temp/2;
    c++;
    
    
}
    //cout<<"BLACK REMAINING = "<<yemp<<endl;
    
    f(j,0,pow(2,m))
    {
       ll tp=j;
       ll r=0;
       
       ll x=yemp;
      // cout<<"j= "<<j<<endl;
       while(tp)
       {
           ll vel=tp%2;
           if(vel)
           {
               //cout<<"R= "<<r<<endl;
               f(ii,0,n)
               if(s[ii][r]=='#'&&!vis[ii][r])
               x--;
               
           }
           tp=tp/2;
           r++;
           
           
       }

            if(x==k)
    sum++;
       // cout<<"YEMP= "<<yemp<<endl;
        //cout<<"x= "<<x<<endl;
    }

    
    
}

cout<<sum<<endl;




    return 0;
}

Measured memory_bytes: 3948
import sys
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        sys.exit()
    ans = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ans += 1
    print(ans)



Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int P=scan.nextInt();
		int Q=scan.nextInt();
		int R=scan.nextInt();
		System.out.println(P+Q+R-(Math.max(Q,Math.max(P, R))));

	}

}


Measured memory_bytes: 35496
# coding: utf-8
# Your code here!
#N=int(input())
#a = list(map(int,input().split()))

#x = []
#y = []
#for i in range(5):
#    x1,y1=[int(i) for i in input().split()]
#    x.append(x1)
#    y.append(y1)

N,C=[int(i) for i in input().split()]

x = [0]
v = [0]
for i in range(N):
    x1,v1=[int(i) for i in input().split()]
    x.append(x1)
    v.append(v1)

x.append(C)
v.append(0)

s = [0]*(N+1)
g = [0]*(N+2)
m1=0;m2=0

for i in range(1,N+1):
    s[i] = s[i-1]+v[i]-(x[i]-x[i-1])

for i in reversed(range(1,N+1)):
    g[i] = g[i+1]+v[i]+(x[i]-x[i+1])

j=N+1
M=0
jj=N+2
for i in reversed(range(N+1)):
    val = s[i] + g[j] -(C-x[j])
    jj=jj-1
    newval = s[i] + g[jj] - (C-x[jj])
    if newval >= val:
        val = newval
        j=jj
#    print(i,j,val)
    M=max(M,val)


j=N+1
jj=N+2
for i in reversed(range(N+1)):
    val = s[i] + g[j] -(x[i])
    jj=jj-1
    newval = s[i] + g[jj] - (x[i])
    if newval >= val:
        val = newval
        j=jj
#    print(i,j,val)
    M=max(M,val)

#print(s,g)
print(M)
            
        
        
    
    
    
    
    
    
    




















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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
const int INF = 1e9;

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

	string S;
	string ans;

	cin >> S;

	vector<char> c;
	c.push_back(S[0]);
	rep2(i, 1, S.size()) {
		auto itr = find(c.begin(), c.end(), S[i]);
		if (itr == c.end()) {
			c.push_back(S[i]);
		}
	}

	if (c.size() != 2) ans = "No";
	else ans = "Yes";
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
using namespace std;
#define EPS 1e-10
#define INF 1e9

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
	return a+b;
}

class P{
public:
	double x,y,r;
	P(){}
	P(double xx,double yy,double rr){
		x=xx;
		y=yy;
		r=rr;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y),r);
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y),r);
	}
	P operator *(double d){
		return P(x*d,y*d,r);
	}
	P operator /(double d){
		return P(x/d,y/d,r);
	}
	double dot(P p){
		return add(x*p.x,y*p.y);
	}
	double det(P p){
		return add(x*p.y,-y*p.x);
	}
};

bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}

P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}

class node{
public:
	double cost;
	int v,v2;
	node(){}
	node(double cc,int vv,int vv2){
		cost=cc;
		v=vv;
		v2=vv2;
	}
	bool operator<(const node& n1)const{
		return cost>n1.cost;
	}
};

int n;
P p[105];
P data[105][2];
double dp[105][2];

double dijk(){
	for(int i=0;i<=n;i++){
		dp[i][0]=dp[i][1]=INF;
	}
	priority_queue<node> que;
	que.push(node(0.0,0,0));
	dp[0][0]=0.0;
	while(que.size()){
		node q=que.top();
		que.pop();
		if(dp[q.v][q.v2]<q.cost)continue;
		for(int next=q.v;next<=n;next++){
			for(int j=0;j<2;j++){
				if((next==n+1 || next==0) && j==1)continue;
				bool flag=true;
				for(int k=q.v+1;k<next;k++){
					if((data[q.v][q.v2]-data[k][0]).det(data[next][j]-data[k][1])==0){
						if(!(on_seg(data[q.v][q.v2],data[k][0],data[next][j])
						  || on_seg(data[q.v][q.v2],data[k][0],data[k][1])
						  || on_seg(data[next][j],data[k][1],data[next][j])
						  || on_seg(data[next][j],data[k][1],data[k][0])))flag=false;
					}else{
						P r=intersection(data[q.v][q.v2],data[next][j],data[k][0],data[k][1]);
						if(!(on_seg(data[k][0],data[k][1],r) && on_seg(data[q.v][q.v2],data[next][j],r)))flag=false;
					}
				}
				if(flag){
					P len=data[next][j]-data[q.v][q.v2];
					double len2=sqrt(add((len.x*len.x),(len.y*len.y)));
					if(add(dp[q.v][q.v2],len2)<dp[next][j]){
						dp[next][j]=add(dp[q.v][q.v2],len2);
						que.push(node(dp[next][j],next,j));
					}
				}
			}
		}
	}
	return dp[n][0];
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].r);
		}
		data[0][0]=p[0];
		data[n][0]=p[n-1];
		for(int i=0;i<n-1;i++){
			P pp=p[i+1]-p[i];
			double len=add(pp.x*pp.x,pp.y*pp.y);
			double d=(add(p[i].r*p[i].r,-p[i+1].r*p[i+1].r)+len)/(2*sqrt(len));
			double c=sqrt(add(p[i].r*p[i].r,-d*d));
			double ang=atan2(pp.y,pp.x);
			double ang2=atan2(c,d);
			data[i+1][0]=p[i]+P(p[i].r*cos(add(ang,ang2)),p[i].r*sin(add(ang,ang2)),0);
			data[i+1][1]=p[i]+P(p[i].r*cos(add(ang,-ang2)),p[i].r*sin(add(ang,-ang2)),0);
		}
		printf("%.4f\n",dijk());
	}
	return 0;
}

Measured memory_bytes: 1240
#!/usr/bin/env python3
n = int(input())
for i in range(n):
    t,x,y = map(int,input().split())
    if x+y <= t and (x+y-t) % 2 == 0: pass
    else: 
        print("No")
        break
    if i == n-1: print("Yes")

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



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

    int n;
    cin >> n;
    cout << n + (n * n) + (n * n * n) << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>


using namespace std;


void check( int val ){
	
	cout << val << endl;
}

struct DATA
{
	long long T;
	long long A;
	long long sum(int dp) {return T*dp + A*dp;}
	long long calc(){return T+A;}
};

int main( int argc , char ** argv ){
	
	int N = 0;
	cin >> N;

	vector <DATA> TA;
	for(int i = 0 ; i < N ; i++){
	DATA buf;
		cin >> buf.T >> buf.A;
		TA.push_back(buf);
	}

	std::vector<int> dp;
	dp.resize(N);
	dp[0] = 1;

	for(int i= 1 ; i < N ; i++){

		//long long left  = 1+((TA[i-1].T*dp[i-1]) -1) / TA[i].T;
		//long long right = 1+((TA[i-1].A*dp[i-1]) -1) / TA[i].A;
		
		//long long left  = 1 + (TA[i-1].T - 1) / TA[i].T;
		//long long right = 1 + (TA[i-1].A - 1) / TA[i].A;
		
		//dp[i] = max( left , right);
		long long n = max(1 + (TA[i-1].T - 1) / TA[i].T , 1 + (TA[i-1].A - 1) / TA[i].A);

		TA[i].A *= n;
		TA[i].T *= n;
	}

	// cout << TA[N-1].sum(dp[N-1]) << endl;
	cout << TA[N-1].calc() << endl;
}



Measured memory_bytes: 256
package main

import (
    "fmt"
    "bufio"
    "os"
)

func main(){
    a := bufio.NewReader(os.Stdin)
    var W, H, x, y, r int
    
    fmt.Fscan(a, &W, &H, &x, &y, &r)

    x1 := x-r
    x2 := x+r
    y1 := y-r
    y2 := y+r
    
    if 0<=x1 && 0<=y1 && x2<=W && y2<=H {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}
    


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int k, n, res;

int color(int r, int c) {
  int ret = 0;
  ret += n * (r & 1);
  ret += (c + r) % n;
  if(r & 1 && (c + r) % n >= n - res){
    ret -= n;
  }
  ret++;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k;
  if (k == 1) {
    cout << "1\n1" << '\n';
    return 0;
  }

  n = (k + 3) / 4 * 2;
  res = n * 2 - k;
  cout << n << '\n';
  for (int r = 0; r < n; r++) {
    for (int c = 0; c < n; c++) {
      cout << color(r, c);
      if (c==n-1){
        cout << '\n';
      } else {
        cout << ' ';
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if ((d*d > 4 *(a * b)) && (d>0)) {
        cout << "Yes"<<endl;
    }
    else {
        cout << "No" << endl;
    }
}

int main() {
	Main();
	return 0;
}

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

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

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;
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}


void solve(){
  int n,m;
  cin >> n >> m;
  ll l[m],r[m];
  ll lmax = -MOD;
  ll rmin = MOD;
  rep(i,0,m) {
    cin >> l[i] >> r[i];
    lmax = max(lmax,l[i]);
    rmin = min(rmin,r[i]);
  }
  if(lmax <= rmin){
      cout << rmin-lmax+1 <<endl;
  }else{
      cout << 0 << endl;
  }
}

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


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;
#define X first
#define Y second

const ll MAX_N = 2e5 + 12, MOD = 998244353, BASE = 101;
ll n, ans;
ll Arr[MAX_N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> Arr[i];

    if (Arr[0]) {
        cout << "0\n";
        return 0;
    }

    sort(Arr, Arr + n);



    for (ll i = 1; i < n; i++)
        if (Arr[i] == 0) {
            cout << "0\n";
            return 0;
        }

    ll ans = 1, cnt = 1, prv = 1;
    for (ll i = 1; i < n; i++) {
        if (Arr[i] - 1 > Arr[i - 1]) {
            cout << "0\n";
            return 0;
        }

        if (Arr[i] == Arr[i - 1]) {
            cnt++;
            ans = (ans * prv) % MOD;
            continue;
        }  

        prv = cnt;
        cnt = 1;
        ans = (ans * prv) % MOD;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
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;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve(long long N, std::string S){
    vector<char> data(S.begin(),S.end());
    // unique(all(data));
    // vout(data);
    cout << UNIQ(data) - data.begin() << "\n";
}

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


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
a,b,c = map(int,input().split())
k = int(input())

"""
for i in range(k):
    D = [a,b,c]
    D.sort()
    D[2] = 2 * D[2]
ans = a + b + c
print(ans)
"""

D = [a,b,c]
D.sort()
ans = D[0] + D[1] + D[2] * 2 ** k
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int N;
string s[100];
int dots[100];

int multi(int num);

int add(int num) {
    int n = dots[num];
    int m = num;
    for (int i = num + 1; i < N; i++) {
        if (dots[i] <= n) {
            m = i;
            break;
        }
        if (i == N - 1) {
            m = N;
        }
    }
    int ans = 0;
    for (int i = num + 1; i < m; i++) {
        if (isdigit(s[i][n + 1])) {
            ans += s[i][n + 1] - '0';
        } else if (s[i][n + 1] == '+') {
            ans += add(i);
        } else if (s[i][n + 1] == '*') {
            ans += multi(i);
        }
    }
    return ans;
}

int multi(int num) {
    int n = dots[num];
    int m = num;
    for (int i = num + 1; i < N; i++) {
        if (dots[i] <= n) {
            m = i;
            break;
        }
        if (i == N - 1) {
            m = N;
        }
    }
    int ans = 1;
    for (int i = num + 1; i < m; i++) {
        if (isdigit(s[i][n + 1])) {
            ans *= s[i][n + 1] - '0';
        } else if (s[i][n + 1] == '+') {
            ans *= add(i);
        } else if (s[i][n + 1] == '*') {
            ans *= multi(i);
        }
    }
    return ans;
}

int main() {
    while (1) {
        cin >> N;
        if (N == 0) {
            break;
        }
        fill(s, s + 100, "");
        fill(dots, dots + 100, 0);
        for (int i = 0; i < N; i++) {
            cin >> s[i];
            int len = s[i].size();
            int num = 0;
            for (int j = 0; j < len; j++) {
                if (s[i][j] != '.') {
                    break;
                }
                num++;
            }
            dots[i] = num;
        }
        if (isdigit(s[0][0])) {
            cout << s[0][0] - '0' << endl;
        } else if (s[0][0] == '+') {
            cout << add(0) << endl;
        } else {
            cout << multi(0) << endl;
        }
    }
}



Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
q, h, s, d = map(int,input().split())
n = int(input())

tmp = [4 * q, 2 * h, s, d / 2] #1Lあたりの値段
tmp.sort()
if tmp[0] == d / 2:
    if n % 2 == 0:
        ans = d * (n // 2)
    elif tmp[1] == s:
        ans = d * (n // 2) + s
    elif tmp[1] == 2 * h:
        ans = d * (n // 2) + 2 * h
    elif tmp[1] == 4 * q:
        ans = d * (n // 2) + 4 * q
elif tmp[0] == s:
    ans = s * n
elif tmp[0] == 2 * h:
    ans = h * n * 2
elif tmp[0] == 4 * q:
    ans = q * n * 4
print(ans) 


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n, k;
    int now=1;
    
    scanf("%d%d", &n, &k);
    
    rep(i, n){
        now=fmin(now+k, 2*now);
    }
    
    printf("%d", now);

    return 0;
}


Measured memory_bytes: 2132
s = input()
k = int(input())
cnt = 0
cnt2 = 0
cnt3 = 0
streak = 1
s2 = s + s
s3 = s2 + s

# s3に対して
for i in range(3*len(s)-1):
    if s3[i + 1] == s3[i]:
        streak += 1
    else:
        if streak > 1:
            cnt3 += streak // 2
        streak = 1
if streak > 1:
    cnt3 += streak // 2


# s2 に対して
streak = 1
for i in range(2*len(s)-1):
    if s2[i + 1] == s2[i]:
        streak += 1
    else:
        if streak > 1:
            cnt2 += streak // 2
        streak = 1
if streak > 1:
    cnt2 += streak // 2

# sに対して
streak = 1
for i in range(len(s) - 1):
    if s[i + 1] == s[i]:
        streak += 1
    else:
        if streak > 1:
            cnt += streak // 2
        streak = 1
if streak > 1:
    cnt += streak // 2

if cnt3 - cnt2 == cnt2 - cnt:
    res = cnt + (cnt2 - cnt) * (k - 1)
else:
    if k > 2:
        res = cnt + ((cnt2 - cnt) + (cnt3 - cnt2)) * ((k - 1) // 2)
        if k % 2 == 0:
            res += (cnt2 - cnt)
    else:
        if k == 1:
            res = cnt
        else:
            res = cnt2
print(res)

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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++)
    cin >> h.at(i);
  
  vector<int> cost(n, -1);
  cost.at(0) = 0;
  cost.at(1) = abs(h.at(1) - h.at(0));
  for(int i = 2; i < n; i++)
    cost.at(i) = min(cost.at(i-2) + abs(h.at(i) - h.at(i-2)), 
                    cost.at(i-1) + abs(h.at(i) - h.at(i-1)));
  
  cout << cost.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

bool comp(P a, P b){
	return (a.first < b.first);
}

int n,a,b,c,l[10],ans=INF;

void dfs(int d, int x, int y, int z, int p, int q, int r){
	if(d<n){
		dfs(d+1,x,y,z,p,q,r);
		dfs(d+1,x+l[d],y,z,p+1,q,r);
		dfs(d+1,x,y+l[d],z,p,q+1,r);
		dfs(d+1,x,y,z+l[d],p,q,r+1);
	}else if(p&&q&&r){
		ans = min(ans,abs(x-a)+abs(y-b)+abs(z-c)+10*(p+q+r-3));
	}
}

int main(void){
	int i;
	cin >> n;
	cin >> a >> b >> c;
	for(i=0; i<n; ++i){
		cin >> l[i];
	}
	dfs(0,0,0,0,0,0,0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//itp1_6-c
#include <iostream>
#include <vector>
using namespace std;

int main(){
 int n;
 cin>>n;
 vector<vector<vector<int> > > a(4,vector<vector<int> >(3,vector<int>(10,0)));
 int b,f,r,v;
 for(int i=0;i<n;i++){
  cin>>b>>f>>r>>v;
  a[b-1][f-1][r-1]+=v;
 }
 for(int i=0;i<15;i++){
  if((i+1)%4==0) cout<<"####################"<<endl;
  else{
   for(int j=0;j<10;j++){
    cout<<" "<<a[i/4][i%4][j];
   }
   cout<<endl;
  }
 }
 return 0;
}

Measured memory_bytes: 1212
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

count = 0
for i in 0..a
  next if 500*i > x
  for j in 0..b
    next if 500*i + 100*j > x
    left = x - (500*i + 100*j)
    count += 1 if left % 50 == 0 && left <= 50 * c
  end
end

puts count

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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;
	int N[27] = {};
	REP(h, H)
	{
		string S;
		cin >> S;
		REP(w, W)
		{
			N[(int)(S[w] - 'a')]++;
		}
	}

	int f = (H / 2)*(W / 2);
	int t = (H / 2)*(W % 2) + (H % 2)*(W / 2);
	int o = (H % 2)*(W % 2);

	REP(i, 27)
	{
		if (f > 0)
		{
			f -= N[i] / 4;
			N[i] %= 4;
		}
		if (t > 0)
		{
			t -= N[i] / 2;
			N[i] %= 2;
		}
		if (o > 0)
		{
			o -= N[i];
			N[i] = 0;
		}
		if (N[i] != 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var read = Console.ReadLine();
                var temp_string = read.Split(' ');

                int H = int.Parse(temp_string[0]), W = int.Parse(temp_string[1]);

                if (H == 0 && W == 0)
                    break;

                if(H!=0)
                {
                    for(int i=0;i<W;i++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();

                    for (int i = 0; i < H - 2;i++ )
                    {
                        Console.Write("#");
                        for(int r = 0 ;r < W-2;r++)
                        {
                            Console.Write(".");
                        }
                        Console.Write("#");
                        Console.WriteLine();

                    }


                        if (H > 1)
                        {
                            for (int i = 0; i < W; i++)
                            {
                                Console.Write("#");
                            }
                            Console.WriteLine();
                        }
                        Console.WriteLine();
                }
            }

        }
    }
}

Measured memory_bytes: 8840