akhauriyash/Code-Regression huggingface dataset:
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6+5;
int cnt[5];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b;
    for(int i = 0; i<3;i++){
        cin>>a>>b;
        cnt[a]++;
        cnt[b]++;
    }
    
    int cnt1 = 0, cnt2= 0, ok = 1;
    for(int i = 1; i<=4; i++){
        if(cnt[i] == 1)cnt1++;
        else if(cnt[i] == 2)cnt2 ++;
        else ok = 0;
    }
    
    if(ok == 0|| cnt1!=2)cout<<"NO\n";
    else cout<<"YES\n";
    
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String symbol = null;
        if (a > b)
            symbol = ">";
        if (a == b)
            symbol = "==";
        if (a < b)
            symbol = "<";
        System.out.printf("%s %s %s", "a", symbol, "b\n");
        sc.close();
    }
}



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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

const ll MAX = 1000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}

const ll mod = 1e9 + 7;

int main(){
    COMinit();
    ll n, k; cin >> n >> k;
    k = min(k, n-1);
    ll ans = 0;
    REP(i, 0, k+1){
        ans += COM(n, i) * COM(n-1, i);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 27032
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	vector<int> v(3);
	
	cin >> v[0] >> v[1] >> v[2];

	sort(v.begin(), v.end());

	cout << v[0] + v[1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> l(n);
    
    for (int i = 0; i < n; i++) cin >> l[i];
    
    int start = 0, end = 0;
    int res = 0, tmp = 0;
    while (accumulate(l.begin(), l.end(), 0) != 0) {
        
        // find a start index
        for (int i = 0; i < n; i++) {
            if (l[i] != 0) {
                start = i;
                break;
            }
        }
            
        // find an end index
        end = l.size();
        for (int i = start; i < n; i++) {
            if (l[i] == 0) {
                end = i;
                break;
            }
        }
        
        tmp = *min_element(l.begin()+start, l.begin()+end);
        res += tmp;
        for (int i = start; i < end; i++) {
            l[i] -= tmp;
        }
    }
    cout << res << endl;
    
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> v(n);
    int mx = 0;

    REP(i, n) {
        cin >> v[i];
        chmax(mx, v[i]);
    }

    auto isExtinct = [&](int c) {
        ll count = 0;
        int r;
        REP(i, n) {
            r = max(0, v[i] - b * c);
            if (r) count += (ll)(r + (a - b) - 1) / (a - b);
        }
        return count <= (ll)c;
    };

    int l = -1;
    int r = (mx + b - 1) / b;
    while (abs(r - l) > 1) {
        int m = (l + r) / 2;
        //cout << l << "," << r << ">" << m << endl;
        if (isExtinct(m)) {
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << endl;
}


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

int main(void) {
    int n;
    cin >> n;
    int x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += x[i];
    }
    int avg = round(sum / (double)n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (x[i] - avg) * (x[i] - avg);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int x = n % k;

	if (x == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
	
	return 0;
}

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

int main()
{
	string ws[] = { "dream", "dreamer", "erase", "eraser" };
	string S; cin >> S;
	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; ++i) {
		reverse(ws[i].begin(), ws[i].end());
	}
	int Sz = S.size();
	for (int i = 0; i < Sz; ++i) {
		for (int w = 0; w < 4; ++w) {
			if (i + ws[w].size() <= Sz) {
				string str = S.substr(i, ws[w].size());
				if (ws[w] == str) {
					i = i + ws[w].size() - 1;
					break;
				}
			}
			if (w == 3) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;;

}

Measured memory_bytes: 3100
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	vector<tuple<int, int, int>> z(N + 1);
	z[0] = make_tuple(0, 0, 0);
	string res = "Yes";
	REP(i, N) {
		int t, x, y;
		cin >> t >> x >> y;
		z[i + 1] = make_tuple(t, x, y);
	}
	sort(z.begin(), z.end());
	REP(i, N) {
		int dt = get<0>(z[i + 1]) - get<0>(z[i]);
		int dx = abs(get<1>(z[i + 1]) - get<1>(z[i]));
		int dy = abs(get<2>(z[i + 1]) - get<2>(z[i]));
		if (dt < dx + dy || (dt - dx - dy) % 2) {
			res = "No";
		}
	}
	cout << res << "\n";
	

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll x[maxn];
ll l[maxn],r[maxn];
int main()
{
    int n;
    ll k;
    while(~scanf("%d%lld",&n,&k))
    {
        int pos = n;
        int have = 0;
        for(int i = 0; i < n; ++i)
        {
            scanf("%lld",x + i);
        }
        ll da = inf;

        for(int i = k - 1; i < n; ++i)
        {
            da = min(x[i] - x[i - k + 1] + min(abs(x[i]),abs(x[i - k + 1])),da);
        }
        printf("%lld\n",da);

    }

}















Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod.m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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


int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int ans = r/d - (l-1)/d;
    cout << ans << endl;
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
int dp[3005][3005];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    for(int i=1;i<=s.size();i++)
        for(int j=1;j<=t.size();j++)
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    string ans;
    for(int i=s.size(),j=t.size();i;)
    {
        if(s[i-1]==t[j-1])
        {   ans+=s[i-1];
            i--;
            j--;
        }
        else if( dp[i-1][j]<dp[i][j-1]) j--;
        else --i;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cmath>
#define eps 1e-9

using namespace std;

struct vec3d{
	double x, y, z;
	vec3d(){}
	vec3d(double x, double y, double z){
		this->x = x, this->y = y, this->z = z;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec3d operator+(vec3d ope){
		return vec3d(add(x, ope.x), add(y, ope.y), add(z, ope.z));
	}
	vec3d operator-(vec3d ope){
		return vec3d(add(x, -ope.x), add(y, -ope.y), add(z, -ope.z));
	}
	vec3d operator*(double t){
		return vec3d(x*t, y*t, z*t);
	}
	double dot(vec3d ope){
		return add(add(x*ope.x, y*ope.y), z*ope.z);
	}
};

int N;
vec3d p, l, c[105];
double r[105];

int main(void)
{
	while(1){
		cin >> N;
		if(N == 0) break;
		
		p = vec3d(0.0, 0.0, 0.0);
		cin >> l.x >> l.y >>l.z;
		for(int i = 0; i < N; i++){
			cin >> c[i].x >> c[i].y >> c[i].z >> r[i];
		}
		
		int prev_i = -1;
		while(1){
		
			int min_i = -1;
			double t1, t2, min_t = 1e100;
			double A, B, C, D;
			for(int i = 0; i < N; i++){
				if(i == prev_i) continue;
				A = l.dot(l);
				B = 2*l.dot(p-c[i]);
				C = (p-c[i]).dot(p-c[i]) - r[i]*r[i];
				D = B*B - 4*A*C;
				
				if(D < 0) continue;
				if(D == 0) t1 = -B / (2*A), t2 = -1;
				else{
					t1 = (-B + sqrt(D)) / (2*A);
					t2 = (-B - sqrt(D)) / (2*A);
				}
				if(t1 > 0 && min_t > t1){
					min_t = t1;
					min_i = i;
				}
				if(t2 > 0 && min_t > t2){
					min_t = t2;
					min_i = i;
				}
			}
			
			if(min_i == -1) break;
			p = p + l*min_t;
			vec3d r = p - c[min_i];
			l = l - r*(2/r.dot(r))*(l.dot(r));
			prev_i = min_i;
		}
		
		cout << p.x << " " << p.y << " " << p.z << endl;
	}
	return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef pair<string, int> P;
int main() {
    string w;
    while (cin>>w) {
        if (w=="0") break;
        queue<P> que;
        que.push(P(w,0));
        int res=-1;
        set<string> done;
        while (!que.empty()) {
            P p=que.front(); que.pop();
            char f=p.first[0]; bool flag=true;
            for (int i=1; i<p.first.length(); i++) if (p.first[i]!=f) {
                flag=false;
                break;
            }
            if (flag) {
                res=p.second;
                break;
            }
            for (int i=0; i<p.first.length()-1; i++) {
                if (p.first[i]!=p.first[i+1]) {
                    string temp=p.first;
                    if (temp[i]!='r'&&temp[i+1]!='r') {
                        temp[i]='r'; temp[i+1]='r';
                    } else if (temp[i]!='g'&&temp[i+1]!='g') {
                        temp[i]='g'; temp[i+1]='g';
                    } else if (temp[i]!='b'&&temp[i+1]!='b') {
                        temp[i]='b'; temp[i+1]='b';
                    }
                    if (done.count(temp)==0) {
                        que.push(P(temp,p.second+1));
                        done.insert(temp);
                    }
                }
            }
        }
        if (res==-1) puts("NA");
        else printf("%d\n",res);
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,h,w;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>h>>w;
	cout<<(H-h)*(W-w)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main()
{
    int a,b,i,j;
    cin>>a>>b;
    i=a+b;
    j=a-b;
    i=max(i,j);
    j=a*b;
    i=max(i,j);
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string str;
int len;
long long str2num(int begin,int end){
  long long  rec=0;
  for(int i=begin;i<=end;i++){
    rec*=10;
    rec+=str[i]-'0';
  }
  return rec;
}
long long total(int now,long long sum){
  long long rec=0;
  if(now==len)
    return sum;
  for(int i=now;i<len;i++){
    rec+=total(i+1,sum+str2num(now,i));
  }
  return rec;
}
int main(){
  long long  ans;
  cin >> str;
  len=str.size();
  ans=total(0,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<int, int> PII;
 
int N, M[200], D[200];
int dd[5] = { 0, 1, 0, -1, 0 };
 
int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N - 1) cin >> M[i] >> D[i];
 
    vector<PII> v;
    v.push_back(PII(0, 0));
 
    REP(i, 0, N - 1) v.push_back(PII(v[M[i]].first + dd[D[i]], v[M[i]].second + dd[D[i] + 1]));
 
    int t = 100000000, l = 100000000, b = -100000000, r = -100000000;
    REP(i, 0, N) {
      t = min(t, v[i].first);
      l = min(l, v[i].second);
      b = max(b, v[i].first + 1);
      r = max(r, v[i].second + 1);
    }
 
    cout << (r - l) << " " << (b - t) << endl;
  }
 
  return 0;
}

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

P = [0] * 150

robot = []

for i in range(N):
    X, L = map(int,input().split())

    left = X-L
    right = X+L

    # 右端でソートしたいため右端を配列1にする
    robot.append([right,left])

robot = sorted(robot)

cnt = 0 #ロボット数
last_right = -float('inf') #最後の右端

for i in range(N):
    if last_right <= robot[i][1]:
        cnt += 1
        last_right =  robot[i][0]

print(cnt)

Measured memory_bytes: 59736
import itertools

N, M, Q = map(int, input().split())

Q_list = []
for _ in range(Q):
    a, b, c, d = list(map(int, input().split()))
    Q_list.append((a, b, c, d))

A_list = []
for a in itertools.combinations_with_replacement(range(1, M+1), N):
    A_list.append(a)

answer = 0
score_list = []
for A in A_list:
    score = 0
    for i in range(Q):
        a, b, c, d = Q_list[i]
        a -=1
        b -=1
        if A[b] - A[a] == c:
            score += d
    answer = max(answer, score)

print(answer)

Measured memory_bytes: 21572
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int K=26;

signed main()
{
    string s,t; cin>>s>>t;
    
    vector<vector<int>> pos(K);
    for(int i=0;i<s.size();i++){
        pos[s[i]-'a'].push_back(i);
    }

    int ans=0,cur=-1;
    for(int i=0;i<t.size();i++){
        if(pos[t[i]-'a'].size()==0){
            cout<<-1<<endl;
            return 0;
        }
        if(pos[t[i]-'a'].back()<=cur){
            ans+=s.size()-cur-1;
            cur=-1;
        }
        int nxt=*upper_bound(pos[t[i]-'a'].begin(),pos[t[i]-'a'].end(),cur);
        ans+=nxt-cur;
        cur=nxt;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1852
#include <stdio.h>

int selectionsort(int A[],int N)
{
	int i,j,t,minj;
	int count = 0;
	
	for(i = 0; i < N - 1; i++)
	{
		minj = i;
		for(j = i; j < N; j++)
		{
			if(A[j] < A[minj])
			{
				minj = j;
			}
		}
		
		t = A[minj];
		A[minj] = A[i];
		A[i] = t;
		
		if(i != minj)
		{
			count++;
		}
	}
	return count;
}

int main(void)
{
	int A[100],N,count;
	int i;
	
	scanf("%d",&N);
	
	for(i = 0; i < N; i++)
	{
		scanf("%d",&A[i]);
	}
	
	count = selectionsort(A,N);
	
	for(i = 0; i < N; i++)
	{
		if(i > 0)
		{
			printf(" ");
		}
		
		printf("%d",A[i]);
	}
	printf("\n");
	
	printf("%d\n",count);
	
	return 0;
}
	

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

using namespace std;

int main()
{
	int M, N;
	cin >> N >> M;
	vector<int> A(N);
	int T = 0;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		T += A[i];
	}
	int C = 0;
	for (int i = 0; i < N; ++i)
	{
		if (A[i] * 4 * M >= T)
		{
			++C;
		}
	}
	if (C >= M)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\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)
typedef long long ll;

int main() {
  string X;
  cin >> X;
  int s = 0, t = 0;
  rep(i, X.size()) {
    if (X[i] == 'S') {
      s++;
    } else {
      if (s)
        s--;
      else
        t++;
    }
  }
  cout << s + t << endl;
  return 0;
}


Measured memory_bytes: 640
# coding: utf-8
from math import gcd
def main():
    k = int(input())
    ans= 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                ans += gcd(gcd(i,j),k)
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 67676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    int n;
    cin >> n;

    bool flg = false;
    if(n/100 == 7) flg = true;
    n %= 100;
    if(n/10 == 7) flg = true;
    n %= 10;
    if(n == 7) flg = true;

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main() {
	int n, m;

	while( 1 ) {
		cin >> n >> m;
		if( n == 0 && m == 0 ) break;
		int sum = 0;
		vector<int> a( n );
		REP( i, n ) cin >> a[i];
		
		sort( ALL( a ) );
		
		if( a[0] + a[1] > m ) cout << "NONE" << endl;
		else if( a[0] + a[1] == m ) cout << a[0] + a[1] << endl;
		else {
			REP( i, n ) {
				REP( j, n - i - 1) {
					if( a[n - i - 1] + a[j] <= m ) {
						sum = max( sum, a[n - i - 1] + a[j] );
					}
				}
			}
			cout << sum << endl;
		}
	}

}


Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main () {
    int h, n;
    cin >> h >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        h -= a[i];
    }
    if (h <= 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

const long long INF = (long long) 1e11+1;
const long long mod = (long long) 100000000 ;
const long long hell = (long long) 1000000007;


ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  return res;
}

ll modinv(ll x,ll m){
  return power(x,m-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;

   while(test--)
   solve();
}


void solve(){
    int n;
    cin>>n;
    
    bool flag=false;
    while(n>0){
        int x=n%10;
        n/=10;
        if(x==7){
            flag=true;
            break;
        }
    }
    if(flag){
        cout<<"Yes";
    }
    else
    cout<<"No";
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

// gcd of strings
/*
string getgcd(string s1,string s2){
    
    while(true){
        if(s1.length()<s2.length()){
            swap(s1,s2);
            continue;
        }
        if(s2.empty())
        return s1;
        
        if(s1.substr(0,s2.length())!=s2)
        return "";
        
        s1=s1.substr(s2.length());
    }
}
*/
/*
// for user defined DS hashmap and set
 
struct hash_pair{
      size_t operator()(const pair<int,pair<int,int>>& p) const{
          auto hash1=hash<int>()(p.F) ;
          auto hash2=hash<int>()(p.S.F) ;
          auto hash3=hash<int>()(p.S.S) ;
          return (hash1^hash2)^hash3;
      }  
};
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
*/



Measured memory_bytes: 3648
uses math;
var x,y,a,n,k,z:longint;
begin
  readln(k,n);
  for x:=0 to k do
    for y:=max(n-x-k,0) to min(n-x,k) do
    begin{
      writeln(x,' ',y,' ',n-x-y);}
      inc(a);
    end;
  writeln(a);
end.

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define snd second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  
  REP(i,n){
    if(c*i-d*(n-i-1) <= a-b && a-b <= d*i-c*(n-i-1)){
      cout << "YES" << endl;
      return 0;
    }
  }
  
  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
rate = [False] * 8
a = list(map(int,input().split()))
a.sort()
CntOver3200 = 0

for i in range(N):
    if a[i] >= 3200:
        CntOver3200 = N - i
        break
    rate[a[i] // 400] = True
min_val = max(sum(rate) , 1)
if any(rate):
    max_val = min_val + CntOver3200
else:
    max_val = CntOver3200
print(min_val , max_val)

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

int main() {
	int n, ma=-1,mi=1001;
	cin >> n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i);
		ma=max(v.at(i),ma);
		mi=min(v.at(i),mi);
	}

	cout<<ma-mi<<endl;
	return 0;
}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dp[151][151][11];

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

  int N, M;
  while(cin>>N>>M,N){
	vector<vector<PII>> xs(N);
	REP(i,N){
	  int k; cin >> k;
	  REP(j,k){
		PII p;
		cin >> p.FF >> p.SS;
		xs[i].EB(p);
	  }
	}

	fill((LL*)dp, (LL*)dp+151*151*11, 1e15);
	REP(j,11)
	  dp[0][0][j] = dp[1][1][j] = 0;
	
	REP(i,N){
	  REP(k,M+1){
		for(int j1=0;j1<SZ(xs[i]);++j1){
		  if(i-1>=0)
			for(int j2=0;j2<SZ(xs[i-1]);++j2){
			  mini(dp[i][k][j1],
				   dp[i-1][k][j2] + abs(xs[i][j1].FF - xs[i-1][j2].FF)
				   * (xs[i][j1].SS + xs[i-1][j2].SS));
			}
		  if(i-2>=0)
			for(int j2=0;j2<SZ(xs[i-2]);++j2){
			  mini(dp[i][k+1][j1],
				   dp[i-2][k][j2] + abs(xs[i][j1].FF - xs[i-2][j2].FF)
				   * (xs[i][j1].SS + xs[i-2][j2].SS));
			}
		}
	  }
	}

	LL ans = 1e15;
	REP(k,M+1) REP(j,11) mini(ans, dp[N-1][k][j]);
	REP(k,M) REP(j,11) mini(ans, dp[N-2][k][j]);
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
    // freopen("alchemy_input.txt", "r", stdin);
 //    // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	ll i,k;
    	cin>>k;
    	ll val=7;
    	ll cnt=1;
    	while(cnt<=k && val%k!=0)
    	{
    		val*=10;
    		val+=7;
    		val%=k;
    		// cout<<val<<"\n";
    		cnt++;
    	}
    	if(val%k==0) cout<<cnt;
    	else cout<<-1;
    }

	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> k_tl(n), k_tr(n);
  rep(i, n){
    ll a;
    cin >> a;
    ll l = i - a, r = i + a;
    if(l >= 0) ++k_tl[l];
    if(r <= n-1) ++k_tr[r];
  }
  ll ans = 0;
  rep(i, n) ans += k_tl[i] * k_tr[i];
  cout << ans << endl;
}


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

int main() {
	int x,y;
	cin>>x>>y;
	if(y%2!=0)
		{
			cout<<"No";
			return 0;
		}
	if(y%2==0){
		if(y>=x*2 && y<=x*4){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

int main(){
	int n,k,q;
	cin >> n >> k >> q;
	int a[q];
	int cor[n]={};
	int point[n];
	rep(i,q){
		cin>>a[i];
		cor[a[i]-1]++;
	}
	rep(i,n){
		point[i]=k-q+cor[i];
		if(point[i]>0)puts("Yes");
		else puts("No");
	}
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3080
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<cassert>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

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

    ll pos[n][16], neg[n][16];
    for(int x=0;x<=15;++x) {
        pos[n-1][x] = x;
        neg[0][x] = x;
    }

    for(int i=n-2;i>=0;--i) {
        ll x4 = 1;
        for(int x=0;x<=15;++x) {
            int j = 0;
            ll j4 = 1;
            while(a[i] * x4 > a[i+1] * j4) {
                j4 *= 4;
                ++j;
            }
            if(j <= 15) {
                pos[i][x] = pos[i+1][j] + x;
            } else {
                pos[i][x] = pos[i+1][15] + (n-i-1) * (j-15) + x;
            }
            x4 *= 4;
        }
    }

    for(int i=1;i<n;++i) {
        ll x4 = 1;
        for(int x=0;x<=15;++x) {
            int j = 0;
            ll j4 = 1;
            while(a[i-1] * j4 < a[i] * x4) {
                j4 *= 4;
                ++j;
            }
            if(j <= 15) {
                neg[i][x] = neg[i-1][j] + x;
            } else {
                neg[i][x] = neg[i-1][15] + i * (j-15) + x;
            }
            x4 *= 4;
        }
    }

    ll ans = pos[0][0] * 2;
    for(int i=1;i<n;++i) {
        ans = min(ans, i + neg[i-1][0] * 2 + pos[i][0] * 2);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 51840
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read1();
      Read2();
      int checkA=0;//1b
      int checkB=0;//2b
      checkA=Math.Abs(s[0]-s[1]);
      checkB=0;
      for(int i=2;i<N;i++){
      if(Math.Abs(s[i]-s[i-1])+checkA<Math.Abs(s[i]-s[i-2])+checkB)
      {
      checkB=checkA;
      checkA=Math.Abs(s[i]-s[i-1])+checkA;
      }
        else{
         int tmp=checkA;
        checkA=Math.Abs(s[i]-s[i-2])+checkB;
                  checkB=tmp;
        }
      }
                    Console.WriteLine(checkA.ToString());

    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

 
    }


}

Measured memory_bytes: 17120
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto& x : a) {
        cin >> x;
    }

    int ans = numeric_limits<int>::max();
    for (int y = -100; y <= 100; ++y) {
        int cost = 0;
        for (auto x : a) {
            cost += (x - y) * (x - y);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


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


template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


using P = pair<int, int>;
int main(){
	int N;
	cin >> N;

	vector<vector<P>> vec(N);
	for(int i=0; i<N-1; i++){
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		vec[u].emplace_back(v, w);
		vec[v].emplace_back(u, w);
	}

	// DFS
	vector<int> color(N, -1);
	stack<P> st;
	st.push(P(0, -1));
	color[0] = 0;//最初の1個を適当に塗る
	while(!st.empty()){
		int node = st.top().first;
		int parent = st.top().second;
		st.pop();

		for(P x : vec[node]){
			// cout << "  node: " << node+1 << " parent: " << parent + 1 << "  child: " << child + 1 << endl;
			int child = x.first;
			int w = x.second;
			if(child == parent) continue;
			if(color[child] != -1) continue;
			if(w % 2 == 1) color[child] = (color[node] + 1) % 2;
			else color[child] = color[node];
			st.push(P(child, node));
		}
	}
	
	for(int i=0; i<N; i++) cout << color[i] << endl;
	return 0;
}


Measured memory_bytes: 9540
def main06():
    num = int(input())
    data = input().split()
    zyun = []
    for i in data:
        zyun.append(int(i))
    zyun.sort()
    naka = int(num/2)
    result = zyun[naka] - zyun[naka-1]
    print(result)
    
if __name__ == "__main__":
    main06()

Measured memory_bytes: 14396
l=[int(input()) for i in range(5)]
ans=[]
ans1=[]
for i in l:
    if i%10==0:
        ans+=[i]
    else:
        ans1+=[i]
ans2=[]
amari=[]
for i in ans1:
    amari+=[i%10]
    i=((i//10)+1)*10
    ans2+=[i]

amari.sort()
print(sum(ans+ans2)-(10-amari[0]) if len(amari)!=0 else sum(ans+ans2) )

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


void solve(){
	ll n;
	string s;
	cin>>n;
	cin>>s;
	ll r,g,b;
	r=g=b=0;
	for(char ch: s){
		if(ch == 'R'){
			++r;
		}else if(ch == 'G'){
			++g;
		}else if (ch == 'B'){
			++b;
		}
	}
	ll total = r*g*b;
	if(total == 0){
		cout<<total<<endl;
	}else{
		for(ll i=0;i<n;++i){
			for(ll j= i+1;j<n;++j){
				ll k = j + (j-i);
				if(k < n && (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])){
				   total -=1;
				}
			}
		}
		cout<<total<<endl;
	}
}
int main()
{

  solve();

return 0;
}



Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main()
{
int n,x,t,count=0;
  cin>>n>>x>>t;
if(n%x>0)
{count=((n/x)+1)*t;}
  else{
    count=(n/x)*t;
  }
  cout<<count<<"\n";
return 0;
}

Measured memory_bytes: 3152
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int X = scan.nextInt();
		int N = scan.nextInt();

		int[] pList = new int[N];

		for (int i = 0; i < N; i++) {
			pList[i] = scan.nextInt() - X;
		}

		//WK変数
		SortedSet<Integer> set = new TreeSet<>();

		for (int i = -500; i <= 500; i++) {
			set.add(i);
		}

		for (int i = 0; i < N; i++) {
			set.remove(pList[i]);
		}

		//演算
		int result = 0;

		if (set.contains(0)) {
			result = X;
		}

		int idx = 1;

		while (result == 0) {
			if (set.contains(idx)) {
				result = X + idx;
			}

			if (set.contains(-idx)) {
				result = X - idx;
				break;
			}

			idx++;
		}

		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 36724
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second
#define MP make_pair
#define PB push_back

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n;
  vector<int> vec(n) ;
  vector<int> vecvec(n) ;
  REP(i,n){
    cin >> vec.at(i) ;
    vecvec.at(i) = vec.at(i) ;
  }
  
  sort(ALL(vec)) ;
  REP(i,n){
    if(vecvec.at(i)==vec.at(n-1)){
      cout << vec.at(n-2) <<endl ;
    }
    else{
      cout << vec.at(n-1) <<endl ;
    }
  }

  return 0 ;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define SQ 320
#define N 8388607
typedef int ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,l,timer;
ll a[100500];
string s;
int main() {
    //freopen("input.txt","r",stdin);
    cin >> s;
    if (s.size() >= 4 && s.substr(0,4) == "YAKI")
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	double x1, y1, x2, y2, x3, y3, xp, yp;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
		double c1 = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1);
		double c2 = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2);
		double c3 = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3);
		bool flag1 = (c1 < 0.0 && c2 < 0.0 && c3 < 0.0);
		bool flag2 = (c1 > 0.0 && c2 > 0.0 && c3 > 0.0);
		if(flag1 || flag2) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    queue<int> BFS;
    bool can = false;
    BFS.push(0);
    while(!BFS.empty()){ // キューが空になるまで続ける
        int t = BFS.front();
        BFS.pop();
        if(t == S.size()){ // 最後まで切れたら成功
            can = true;
            break;
        }
        for(string s : divide){
            if(S.substr(t, s.size()) == s){ // 切れたらとりあえず切ったことにしてみる
                BFS.push(t + s.size());
            }
        }
    }
    cout << (can ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;
int main(){
    int M1,D1;
    int M2,D2;

    cin >> M1 >> D1;
    cin >> M2 >> D2;

    if(M2 > M1){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }

    return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;



int main(){
	string n; cin >> n;
	ll ans = 0;
	rep(i,4){
		if(n[i]=='2') ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ag
//
//  Created by h3037175 on 2017/07/28.
//  Copyright ?? 2017??´ h3037175. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n,a[3];
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[j];
        }
        sort(a,a+3);
        if(a[2]*a[2]==a[1]*a[1]+a[0]*a[0]){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

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

int main() {
    int64_t N;
    string S;
    cin >> N >> S;

    reverse(S.begin() + N, S.end());

    map<pair<string, string>, int64_t> mp[2];
    for (int64_t i = 0; i < (1LL << N); i++) {
        for (int64_t j = 0; j < 2; j++) {
            string str1, str2;
            for (int64_t k = 0; k < N; k++) {
                if (i & (1LL << k)) {
                    str1 += S[k + N * j];
                } else {
                    str2 += S[k + N * j];
                }
            }

            mp[j][make_pair(str1, str2)]++;
        }
    }

    int64_t ans = 0;
    for (const auto& p : mp[0]) {
        ans += mp[0][p.first] * mp[1][p.first];
    }
    cout << ans << endl;
}

Measured memory_bytes: 108288
fun main(args: Array<String>) {
    val S = next()
    val K = nextLong()
    var n = 0
    while (n < S.length && n.toLong() < K) {
        if (S[n] != '1') {
            println(S[n])
            return
        }
        n += 1
    }
    println(1)
}

fun next() = readLine()!!
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 29784
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cout << v << " ";  \
  }                    \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  REP(i, N) {
    char p;
    cin >> p;
    if (p == 'Y') {
      print("Four");
      return 0;
    }
  }
  print("Three");
}

Measured memory_bytes: 256
# N = 3
# ARR = [[[2],[3]], [[3],[1]], [[1],[2]]]

# N = 2
# ARR = [[[], [2]], [[], [1]]]


# N = 3
# ARR = [[[2],[]],[[1],[]],[[],[2]]]

N = int(input())
ARR = []
for i in range(N):
    A = int(input())
    X = []
    Y = []
    for j in range(A):
        x, t = map(int, input().split())
        if t == 1:
            X.append(x)
        else:
            Y.append(x)
    ARR.append([X,Y])

def calculate(n,arr):
    result = []
    for i in range(2**n):
        cases = []
        goods = set()
        suspicious = set()
        for j in range(n):
            cases.append(i >> j & 1)
            if i >> j & 1:
                goods.add(j)
            else:
                suspicious.add(j)
        res = judge(arr,cases,goods,suspicious)
        if res:
            result.append(len(goods))

    if len(result) == 0:
        print(0)
    else:
        print(max(result))

def judge(arr,cases,goods,suspicious):
        tempGoods = set()
        tempSuspicious = set()

        if sum(cases) == 0:
            return False

        for index,ca in enumerate(cases):
            if ca == 1:
                for g in arr[index][0]:
                    tempGoods.add(g - 1)
                for s in arr[index][1]:
                    tempSuspicious.add(s - 1)

        if len(list(tempGoods & suspicious)) > 0:
            return False

        if len(list(tempSuspicious & goods)) > 0:
            return False

        return True


calculate(N,ARR)

Measured memory_bytes: 3504
n = int(input())
a = list(map(int,input().split()))
c = 0

for i in range(n):
    if a[i] == -1:
        pass
    elif a[a[i] - 1] - 1 == i:
        c += 1
        a[a[i] - 1] = -1
        a[i] = -1
    else:
        pass

print(c)

Measured memory_bytes: 20712
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double[] A = new double[N];
        double sum1 = 0;


        
        for(int i = 0; i < N; i++) {
        	A[i] = sc.nextDouble();
        }
        
        for(int i = 0; i < A.length; i++) {
        	sum1 += 1/A[i];
        }
        
System.out.println(1/sum1);
        
        sc.close();
    }
}


Measured memory_bytes: 23252