akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
    {
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
	}
	int dp[k+1];
	dp[0]=0;
	for(int j=1;j<k+1;j++)
	{
		dp[j]=0;
	}
	for(int j=1;j<k+1;j++)
	{
		for(int i=0;i<n;i++)
		{
			if((j-a[i]>=0)and(dp[j]==0))
			{
				dp[j]=1-dp[j-a[i]];
			}
		}
	}
	if(dp[k]==1)
	{
		cout<<"First";
	}
	else
	{
		cout<<"Second";
	}
    return(0);
    }


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

int main()
{
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  int a, b, c;
  a = b = c = 0;
  char turn = 'a';
  while (1) {
    switch(turn) {
    case 'a':
      if (a == s1.size()) {
	cout << 'A' << endl;
	return 0;
      }
      turn = s1[a++];
      break;
    case 'b':
      if (b == s2.size()) {
	cout << 'B' << endl;
	return 0;
      }
      turn = s2[b++];
      break;
    case 'c':
      
      if (c == s3.size()) {
	cout << 'C' << endl;
	return 0;
      }
      turn = s3[c++];
      break;
    }
  }
  
  return 0;
}


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

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> cnt(h, vector<int>(w, 0));
    rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.') continue;
            bool ok = false;
            rep(k,4){
                int nh = i + dx[k];
                int nw = j + dy[k];
                if(nh >= h || nh < 0 || nw >= w || nw < 0) continue;
                if(s[nh][nw]=='#' && s[i][j]=='#') ok = true;
            }
            if(!ok) {cout << "No" << endl; return 0;}
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define per1(i,n) for (int i = n; i >= 1; --i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
// if(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W)
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

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

    string S; cin >> S;
    int X,Y; cin >> X >> Y;
    int N = S.size();

    vector<int> xnums,ynums;
    bool horiz = 1;
    int streak = 0;

    rep(i, N) {
        if(S[i] == 'F') {
            ++streak;
            continue;
        }

        if(horiz) {
            xnums.push_back(streak);
        } else {
            ynums.push_back(streak);
        }
        horiz = !horiz;
        streak = 0;
    }

    if(streak) {
        if(horiz) {
            xnums.push_back(streak);
        } else {
            ynums.push_back(streak);
        }
    }

    int xn = xnums.size(), yn = ynums.size();
    unordered_set<int> dpx, dpy;
    dpx.insert(0);
    dpy.insert(0);

    rep(i, xn) {
        auto cp = dpx;
        dpx.clear();
        for(auto&bef:cp) {
            dpx.insert(bef + xnums[i]);
            if(i != 0) dpx.insert(bef - xnums[i]);
        }
    }

    rep(i, yn) {
        auto cp = dpy;
        dpy.clear();
        for(auto&bef:cp) {
            dpy.insert(bef + ynums[i]);
            dpy.insert(bef - ynums[i]);
        }
    }

    if(dpx.find(X) != dpx.end() && dpy.find(Y) != dpy.end()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int n,m,Q;
vector<int> G[MAX_N];
int color[MAX_N];
int op[MAX_N][3];
int af[MAX_N];

void dfs(int num,int u,int dep,int D)
{
	if(af[u] >= D-dep){
		return;
	}
	af[u] = D-dep;
	if(color[u] == 0){
		color[u] = num;
	}
	if(D-dep>0){
		rep(i,G[u].size()){
			dfs(num,G[u][i],dep+1,D);
		}
	}
}

int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d%d",&x,&y);
		G[x-1].push_back(y-1);
		G[y-1].push_back(x-1);
	}
	scanf("%d",&Q);
	rep(i,Q){
		scanf("%d%d%d",&op[i][0],&op[i][1],&op[i][2]);
	}
	rep(i,n){
		af[i] = -1;
	}
	for(int i=Q-1;i>=0;i--){
		dfs(op[i][2],op[i][0]-1,0,op[i][1]);
	}
	rep(i,n){
		printf("%d\n",color[i]);
	}
	return 0;
}

Measured memory_bytes: 8440
n, m = [int(i) for i in input().split()]

A = []
for _ in range(n):
    A.append([int(i) for i in input().split()])
b = [int(input()) for _ in range(m)]
    
ans = []
for a in A:
    ans.append(sum([x * y for x, y in zip(a, b)]))

for a in ans:
    print(a)


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

int main() {

    int n;
    cin >> n;
    vector< vector< int > > p(n, vector< int >(3));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> p[i][j];
        }
        sort(p[i].begin(), p[i].end());
    }
    sort(p.begin(), p.end());

    cout << p.end() - unique(p.begin(), p.end()) << endl;
}

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

int main() {
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans==0) cout<<0<<endl;
    else cout<<1000-ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
 
struct lunch {
    int w, s;
    char name[21];
 
    bool operator < (const lunch &l) const {
	if (w != l.w) {
	    return w < l.w;
	} else {
	    return s < l.s;
	}
    }
};
 
lunch N[10], ans[10];
int n;
 
void make()
{
    for (int i = 0; i < n; i++) {
	ans[i] = N[i];
    }
}
 
bool check(int &G)
{
    int Ws1 = 0, Ws2 = 0;
    for (int i = 0; i < n; i++) {
	if (N[i].s < Ws2) return false;
	Ws1 += (i+1)*N[i].w;
	Ws2 += N[i].w;
    }
    G = Ws1;
    return true;
}
 
int main()
{
    while (scanf("%d", &n), n) {
	for (int i = 0; i < n; i++) {
	    scanf("%s %d %d", N[i].name, &N[i].w, &N[i].s);
	}
	sort(N, N+n);
 
	int G = 0,t;
 
	do {
	    if (check(t)) {
		if (G < t) {
		    make();
		    G = t;
		}
	    }
	} while (next_permutation(N, N+n));
 
	for (int i = n-1; i >= 0; i--) {
	    printf("%s\n", ans[i].name);
	}
    }
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector <pair <string, pair <int, int> > > sp(N);
  for (int i = 0; i < N; i++) {
	  string S;
	  int P;
	  cin >> S >> P;
	  sp[i] = make_pair(S, make_pair(-P, i));
	}
  sort(sp.begin(), sp.end());
  for (int i = 0; i < N; i++) {
	  cout << sp[i].second.second + 1 << endl;
	}
  return 0;
}


Measured memory_bytes: 256
def resolve():
    L, R = [int(i) for i in input().split()]
    ans = 2019
    end = min(R, (L + 2019)) + 1
    for i in range(L, end):
        for j in range(i + 1, end):
            ans = min(ans, i * j % 2019)
            if ans == 0:
                break
        else:
            continue
        break
    print(ans)


resolve()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

using namespace std;


int main() {

	int N, a, b;
	cin >> N >> a >> b;

	if (N * a < b) b = N * a;

	cout << b << endl;


	return 0;
}


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

ll f(ll b) {
    if (b == 0) return 0;
    int k;
    for (k = 60; k >= 0; k--) {
        if (b & (1LL << k)) break;
    }
    if (k > 0) b |= (1LL << k) - 1;
    return b;
}

ll fastsolve(ll a, ll b) {
    int k;
    for (k = 60; k >= 0; k--) {
        if ((a & (1LL << k)) == (b & (1LL << k))) {
            a &= ~(1LL << k);
            b &= ~(1LL << k);
        } else {
            break;
        }
    }
    if (a == b) {
        return 1;
    }
    ll c = 1LL << k;
    ll ans = 0;
    ans += c - a;
    b -= c;
    b = f(b);
    ans += b + 1;
    ans += c - max(a, b + 1);
    return ans;
}

ll slowsolve(ll a, ll b) {
    vector<ll> vct;
    for (ll i = a; i <= b; i++) vct.push_back(i);

    set<ll> st;
    for (int i = 1; i < 1 << (int)vct.size(); i++) {
        ll cur = 0;
        for (int j = 0; j < (int)vct.size(); j++) if (i & (1 << j)) cur |= vct[j];
        st.insert(cur);
    }
    //for (int x : st) cerr << x << " " ;
    //cerr << endl;
    return st.size();
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    //fastsolve(4, 10);
    //cerr << slowsolve(4, 10) << endl;
    //return 0;
    /*for (int i = 0; i < 1000; i++) {
        cout << i << endl;
        for (int dif = 0; dif <= 15; dif++) {
            ll ans1 = fastsolve(i, i + dif);
            ll ans2 = slowsolve(i, i + dif);
            if (ans1 != ans2) {
                cout << ans1 << " instead of " << ans2 << endl;
                cout << i << " " << i + dif << endl;
                return 0;
            }
        }
    }*/

    ll a, b;
    while (cin >> a >> b) {
        cout << fastsolve(a, b) << endl;
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ios::sync_with_stdio(false);cin.tie(false);cout.tie(false);
   /* int t;cin>>t;while(t--)
    {
        float n,r,a;cin>>n>>a>>r;
        cout<<fixed<<showpoint<<setprecision(6);
        if(r==1)cout<<a*n;
        else
        cout<<a*(1-pow(r,n))/(1-r);
        if(t)cout<<'\n';
    }*/
    string s1,s2;cin>>s1>>s2;
    int cnt=0;
    for(int i=0;i<3;i++)
    if(s1[i]==s2[i])cnt++;
    cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll gcd(ll a, ll b)
{
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}

inline ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


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

typedef long long ll;
const int N = 2e5 + 10;
int n, rpos, a[N]; ll k;
ll C(ll n) { return n * (n - 1) / 2; }
ll fl(ll a, ll b) {
    bool f = (a < 0) ^ (b < 0);
    if(a < 0) a = -a;
    if(b < 0) b = -b;
    return f ? - ( a / b + 1 ) : a / b;
}
ll cl(ll a, ll b) {
    bool f = (a < 0) ^ (b < 0);
    if(a < 0) a = -a;
    if(b < 0) b = -b;
    return f ? - ( a / b ) : (a + b - 1) / b;
}
int main() {
    scanf("%d%lld", &n, &k);
    for(int i = 1; i <= n; i ++) scanf("%d", a + i);
    sort(a + 1, a + n + 1);
    ll l = 0, r = 0, z = 0, L = 0, R = 0, Z = 0;
    for(int i = 1; i <= n; i ++) z += a[i] == 0;
    for(int i = 1; i <= n; i ++) l += a[i] < 0;
    for(int i = 1; i <= n; i ++) r += a[i] > 0;
    L = l * r; R = C(l) + C(r); Z = C(n) - L - R;
    rpos = n + 1;
    for(int i = 1; i <= n; i ++) if(a[i] > 0) {
        rpos = i; break ;
    }
    if(k <= L) {
        ll ql = -1e18, qr = -1, mid, ans = -233;
        while(ql <= qr) {
            mid = (ql + qr) >> 1;
            ll sum = 0, now = r, cur = rpos;
            for(int i = 1; i <= n && a[i] < 0; i ++) {
                ll up = mid % a[i] == 0 ? mid / a[i] + 1 : cl(mid, a[i]);
                while(now && a[cur] < up) cur ++, now --;
                sum += now;
            }
            if(sum < k) ql = (ans = mid) + 1;
            else qr = mid - 1;
        }
        printf("%lld\n", ans);
    } else if(k <= L + Z) {
        puts("0");
    } else {
        k -= L + Z;
        ll ql = 1, qr = 1e18, mid, ans = -233;
        while(ql <= qr) {
            mid = (ql + qr) >> 1;
            ll sum = 0, now = r, cur = n;
            for(int i = rpos; i <= n; i ++) {
                ll up = mid % a[i] == 0 ? mid / a[i] - 1 : fl(mid, a[i]);
                while(now && a[cur] > up) cur --, now --;
                sum += cur >= i ? now - 1 : now;
            }
            now = l; cur = 1;
            for(int i = n; i >= 1; i --) if(a[i] < 0) {
                ll up = mid % a[i] == 0 ? mid / a[i] + 1 : cl(mid, a[i]);
                while(now && a[cur] < up) cur ++, now --;
                sum += cur <= i ? now - 1 : now;
            }
            sum >>= 1;
            if(sum < k) ql = (ans = mid) + 1;
            else qr = mid - 1;
        }
        printf("%lld\n", ans);
    }
    return 0;
} 

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100005
#define ll long long
int n, m, f[N], cnt[3], num, flg;
int fir[N], nex[N << 1], tar[N << 1], len[N << 1], tot;
ll ans;
void Add(int a,int b,int c)
{
	tot++;
	tar[tot] = b;
	len[tot] = c;
	nex[tot] = fir[a];
	fir[a] = tot;
}
void Dfs(int u)
{
	cnt[f[u]]++;
	for (int i = fir[u]; i; i = nex[i])
	{
		num++;
		int v = tar[i];
		if (f[v] == -1)
		{
			f[v] = (f[u] + len[i]) % 3;
			Dfs(v);
		}
		else
			if ((f[u] + len[i]) % 3 != f[v])
				flg = 0;
	}
}
int main()
{
	scanf("%d%d", &n, &m);
	while (m--)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		Add(a, b, 1);
		Add(b, a, 2);
	}
	memset(f, -1, sizeof(f));
	for (int i = 1; i <= n; i++)
		if (f[i] == -1)
		{
			flg = 1;
			cnt[0] = cnt[1] = cnt[2] = 0;
			num = 0;
			f[i] = 0;
			Dfs(i);
			num >>= 1;
			if (!flg)
				ans += (ll)(cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
			else
				if (cnt[0] && cnt[1] && cnt[2])
					ans += (ll)cnt[0] * cnt[1] + (ll)cnt[1] * cnt[2] + (ll)cnt[2] * cnt[0];
				else
					ans += num;
		}
	printf("%lld\n", ans);
}


Measured memory_bytes: 6528
#include <iostream>
#include <set>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;

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

    int a;
    set<int> x;
    rep(i,N){
        cin >> a;
        x.insert(a);
    }
    
    if(x.size() == N){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    // O(N^2)となってTLE
    // for(int i=0; i<N; i++){
    //     cin >> A[i];
    //     for(int j=0; j<i; j++){
    //         if(A[j] == A[i]){
    //             cout << "NO" << endl;
    //             return 0;
    //         }
    //     }
    // }
    // cout << "YES" << endl;

    
    return 0;
}

Measured memory_bytes: 9600
import java.util.*;

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

		if(S.length() <= K){
			System.out.println(S);
		}else{
			System.out.println(S.substring(0, K) + "...");
		}
	}
}

Measured memory_bytes: 38616
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n; long w;
  cin>>n>>w;
  vector<long> we(n),va(n);
  rep(i,n) cin>>we[i]>>va[i];
  vector<long> vals[4];
  rep(i,n){
    vals[we[i]-we[0]].pb(va[i]);
  }
  rep(i,4) vals[i].pb(0);
  rep(i,4){
    sort(all(vals[i]));
    reverse(++begin(vals[i]), vals[i].end());
    repl(j,1,vals[i].size()) vals[i][j] += vals[i][j-1];
  }

  long ans = 0;
  rep(i,vals[0].size()) rep(j,vals[1].size()) rep(k,vals[2].size()){
    long cw = (i+j+k)*we[0] + j + 2*k;
    if(cw > w) continue;
    int p = (w-cw)/(we[0]+3);
    p = min<int>(vals[3].size()-1, p);
    ans = max(ans, vals[0][i]+vals[1][j]+vals[2][k]+vals[3][p]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	int n, d[101000];
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> d[i]; }
	sort(d, d + n);
	cout << d[n / 2] - d[n / 2 - 1] << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define inf (long long)1e16
using namespace std;

long long n, m, threepow;
vector<long long> a, w, b;
set<long long> st;

int solve();

int main() {
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    a.resize(n);
    w.resize(m);
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) cin >> w[i];
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  st.clear();
  b.erase(b.begin(), b.end());
  threepow = 1;
  for(int i = 0; i < m; ++i) threepow *= 3;
  for(long long i = 0; i < threepow; ++i) {
    long long x = i, sum = 0;
    for(int j = 0; j < m; ++j) {
      if(x % 3 == 1)
        sum += w[j];
      else if(x % 3 == 2)
        sum -= w[j];
      x /= 3;
    }
    st.insert(sum);
  }
  for(int i = 0; i < n; ++i)
    if(st.find(a[i]) == st.end()) b.push_back(a[i]);
  if(b.size() == 0) return 0;
  long long ans = inf, neww;
  for(auto now : st) {
    neww = abs(now - b[0]);
    bool ch = 1;
    for(int i = 0; i < b.size(); ++i) {
      if(st.find(b[i] + neww) != st.end()) continue;
      if(st.find(abs(b[i] - neww)) != st.end()) continue;
      ch = 0;
    }
    if(ch) ans = min(ans, neww);
  }
  if(ans == inf) return -1;
  return ans;
}


Measured memory_bytes: 5856
if __name__ == '__main__':

	n = int(input())
	s = input()
	A = []
	A.append(s)

	flg = True
	for _ in range(n-1):
		cmd = input()
		if s[-1] == cmd[0] and cmd not in A:
			A.append(cmd)
			s = cmd
		else:
			flg = False

	if flg :
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 9064
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return ((a*b)/gcd(a,b));}




int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
	
	
	ll k,a,b;
	cin>>k>>a>>b;
	bool f=false;
	for(ll i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			f=true;
			break;
		}
	}
	
	
	if(f)
	cout<<"OK";
	else
	cout<<"NG";
	
	
	
	
	
	
	
	

}return 0;}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  int y = 0;
  REP(i, N) {
    string S;
    cin >> S;
    if (S[0] == 'Y') y++;
  }
  if (0 < y)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    import collections
    S = input()

    cnt_S_dict = collections.Counter(S)

    num = len(S)
    if num == 1:
        res = 'YES'
    elif num == 2:
        if len(cnt_S_dict.keys()) == 2:
            res = 'YES'
        else:
            res = 'NO'
    else:
        if len(cnt_S_dict.keys()) <= 2:
            res = 'NO'
        else:
            num_a = cnt_S_dict['a']
            num_b = cnt_S_dict['b']
            num_c = cnt_S_dict['c']
            if abs(num_a - num_b) <= 1 and abs(num_a - num_c) <= 1 and abs(num_b - num_c) <= 1:
                res = 'YES'
            else:
                res = 'NO'
    
    print(res)




if __name__ == "__main__":
    resolve()


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

const ll Max = 1e18;


int main() {
    int n;
    cin >> n;
    ll num = 1;
    bool ng = false;

    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (ng || Max/num < a) ng = true;
        num *= a;
    }
    if (ng) cout << -1 << endl;
    else cout << num << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
#define ll long long
int Head[N],Next[N<<1],Adj[N<<1],tot=0;
void addedge(int u,int v){
	Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v;
	Next[++tot]=Head[v],Head[v]=tot,Adj[tot]=u;
}
int n,m,p1,p2;
int col[N],val[N],cnt;
bool vis[N];
int size[N],deep[N];
void dfs(int x,int fa){
	vis[x]=true;
	size[x]=(deep[x]&1)?1:-1;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=fa){
			if (!vis[Adj[e]]){
				deep[Adj[e]]=deep[x]+1;
				dfs(Adj[e],x);
				size[x]+=size[Adj[e]];
			}else p1=x,p2=Adj[e];
		}
}
void dfs2(int x,int fa){
	vis[x]=1;
	size[x]+=(deep[x]&1)?1:-1;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=fa&&(!vis[Adj[e]])){
			dfs2(Adj[e],x);
			size[x]+=size[Adj[e]];
			col[x]+=col[Adj[e]];
		}
}
#define ll long long
int main() {
	int T=1;
	while (T--){
		n=m=p1=p2=cnt=tot=0;
		memset (Head,0,sizeof(Head));
		memset (Next,0,sizeof(Next));
		memset (Adj,0,sizeof(Adj));
		memset (size,0,sizeof(size));
		memset (deep,0,sizeof(deep));
		memset (col,0,sizeof(col));
		memset (val,0,sizeof(val));
		memset (vis,0,sizeof(vis));
		scanf ("%d%d",&n,&m);
		for (int i=1;i<=m;i++){
			int u,v;scanf ("%d%d",&u,&v);
			addedge(u,v);
		}
		dfs(1,0);
		if (m==n-1) {
			if (size[1]) {puts("-1");continue;}
			ll ans=0;
			for (int i=1;i<=n;i++) ans+=abs(size[i]);
			printf ("%lld\n",ans);
		} else if((deep[p2]-deep[p1]+1)&1) {
			if (abs(size[1])&1) {
				puts("-1\n");
				continue;
			}
			ll ans=abs(size[1])/2;
			int t=size[1];
			memset (vis,0,sizeof(vis));
			memset (size,0,sizeof(size));
			size[p1]-=t/2,size[p2]-=t/2;
			dfs2(1,0);
			for (int i=1; i<=n; i++) ans+=abs(size[i]);
			printf ("%lld\n",ans);
		} else {
			if (size[1]) {
				puts("-1");
				continue;
			}
			memset (vis,0,sizeof(vis));
			memset (size,0,sizeof(size));
			col[p1]=1,col[p2]=-1;
			dfs2(1,0);val[++cnt]=0;
			ll ans=0;
			for (int i=1; i<=n; i++) {
				if (!col[i]) ans+=abs(size[i]);
				else if (col[i]==1) val[++cnt]=-size[i];
				else val[++cnt]=size[i];
			}
			sort(val+1,val+cnt+1);
			int v=val[(cnt+1)>>1];
			for (int i=1; i<=cnt; i++) ans+=abs(v-val[i]);
			printf ("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
//using P = pair<int,int>;
//int dy[4] = {-1,0,1,0};
//int dx[4] = {0,-1,0,1};


int main()
{
    int A,B,C,D;
    cin >> A>>B>>C>>D;
    
    int taka = A/D + min(1,A%D);
    int ao = C/B + min(1,C%B);
    
    
    if(taka >= ao) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}

/*
 if(ok) cout << "Yes" << endl;
 else cout << "No" << endl;
 */


/*
    int N;
    cin >> N;
    
    int ans;
    cout >> ans;
    */

Measured memory_bytes: 3620
#include <stdio.h>
int data[100];

void sort(int, int);
void change(int, int);


main(){
  int n, i;
  int sum[100], ans;

  while(1){
    if(scanf("%d", &n)==EOF) break;

    for(i=0;i<n;i++){
      scanf("%d", &data[i]);
    }

    sort(0, n-1);

    sum[0]=data[0];

    for(i=1;i<n;i++){
      sum[i]=sum[i-1]+data[i];
    }

    ans=0;
    for(i=0;i<n;i++){
      ans+=sum[i];
    }

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

void sort(int left, int right){
  int i, j, n;

  i=left;
  j=right;

  n=data[(left+right)/2];

  while(1){
    while(data[i]<n){
      i++;
    }
    while(data[j]>n){
      j--;
    }
    if(i>=j) break;
    change(i, j);

    i++;
    j--;
  }

  if(left<i-1) sort(left, i-1);
  if(right>j+1) sort(j+1, right);
}

void change(int a, int b){
  int temp;
  temp=data[a];
  data[a]=data[b];
  data[b]=temp;
}

Measured memory_bytes: 0
N, Q = map(int, input().split())
root = []
counter = [0] * N
ans = [0] * N

for i in range(N-1):
    a, b = map(int, input().split())
    root.append([a,b])

root.sort(key=lambda x:x[1])

for j in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans[0] = counter[0]

for k in range(1,N):
    ans[k] = counter[k] + ans[root[k-1][0]-1]

print(*list(ans))

Measured memory_bytes: 58632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.println(in.nextString().chars().filter(c -> c == '2').count());
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 27988
#include<iostream>
#include<limits>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int min = numeric_limits<int>::max();
	int max = numeric_limits<int>::min();
	long long sum = 0;
	for (int i = 0; i < n; ++i) {
		int temp;
		cin >> temp;
		if (temp < min) {
			min = temp;
		}
		if (temp > max) {
			max = temp;
		}
		sum += temp;
	}
	
	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1168
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    string S;
    cin >> S;
    sort(S.begin(),S.end());
    if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[2] && S[1]!=S[3]){
        cout << "Yes";
    }
    else{
    cout << "No";
    }
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <functional>
using namespace std;

typedef pair<int, pair<int, int> > piii;

int main()
{
  while(1){
    int n, m, a;
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0){
      break;
    }else{
      int h, p, q;
      vector<piii> yoko;
      for(int i = 0; i < m; i++){
        cin >> h >> p >> q;
        yoko.push_back(make_pair(h, make_pair(p, q)));
      }
      sort(yoko.begin(), yoko.end(), greater<piii>());
      int ans = a;
      for(int i = 0; i < yoko.size(); i++){
        if(ans == yoko[i].second.first){
          ans = yoko[i].second.second;
        }else if(ans == yoko[i].second.second){
          ans = yoko[i].second.first;
        }
      }
      cout << ans << endl;
    }
  }
}

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

int main()
{
    string s;
    int a,b,c,d;
    cin>>a>>b;

    cin>>s;
//    int ch='A'+32;
    s[b-1]=s[b-1]+32;
    cout<<s<<endl;
    return 0;
}


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

const long long MOD = 1000000007;
const long long MAX = 2000000;

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main()
{
    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    int ll=(c-a)*60+(d-b);
    cout<<ll-k<<endl;


    
    

}


Measured memory_bytes: 3636
#include<cstdio>

using namespace std;

int main(){
    char s[4];
    scanf("%s", s);
    if (s[0] == 'S' && s[1] == 'U') puts("7");
    else if (s[0] == 'M' && s[1] == 'O') puts("6");
    else if (s[0] == 'T' && s[1] == 'U') puts("5");
    else if (s[0] == 'W' && s[1] == 'E') puts("4");
    else if (s[0] == 'T' && s[1] == 'H') puts("3");
    else if (s[0] == 'F' && s[1] == 'R') puts("2");
    else if (s[0] == 'S' && s[1] == 'A') puts("1");
}

Measured memory_bytes: 128
#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;
}

int main(){

    string s;
    cin >> s;
    int k;
    cin >> k;
    bool all_one = true;
    char ans = '1';
    for(int i = 0; i < k; i++){
        if(s[i] != '1'){
            ans = s[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int n;
  vector<bool> b;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int d[2];
    cin >> d[0] >> d[1];
    b.push_back(d[0] == d[1]);
    if (i >= 2 && b[i] && b[i - 1] && b[i - 2])
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007


int main() {
  int N;
  cin >> N;
  vector<pii> T(N);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    T.at(i) = make_pair(b, a);
  }

  sort(all(T), greater<pii>());
  bool can = true;
  int timer = MOD;

  rep(i, N) {
    if (T.at(i).first < timer) {
      timer = T.at(i).first;
    }
    timer -= T.at(i).second;
    if (timer < 0) {
      can = false;
      break;
    }
  }

  cout << (can ? "Yes" : "No") << endl;

}


Measured memory_bytes: 1792
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,m;
  while(cin>>n>>m&&(n||m)){
    map<int,pair<int,int> > a;
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p>>q>>r;
      q--;
      r--;
      a[p]=make_pair(q,r);
    }
    bool b[20000];
    memset(b,0,n);
    b[0]=1;
    map<int,pair<int,int> >::iterator it;
    for(it=a.begin();it!=a.end();it++)
      b[(*it).second.second]|=b[(*it).second.first];
    int ct=0;
    for(i=0;i<n;i++)
      ct+=b[i];
    cout<<ct<<endl;
  }
  return 0;
}

Measured memory_bytes: 1556
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 2 == n % 2) cnt++;
	}
	cout << sp(9) << (double)cnt / n << endl;
	return 0;
}

Measured memory_bytes: 256
program main
implicit None
	character*10::s
	integer::i,k,a,b,c
	
	read *,s
	
	k = len_trim(s)
	
	do i  = 1,k-2
		read(s(i:i),*) a
		b = a * 100
		read(s(i+1:i+1),*) a
		b = b + a * 10
		read(s(i+2:i+2),*) a
		b = b + a
		a = abs(b - 753)
		
		if(i == 1) c = a
		if(c > a) c = a
	enddo
	
	print 101,c
	
101 format(i0)
end program main

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
    k *= 2;
		string s = Console.ReadLine();
    int answer = 0;
    int firstNum = 0;//L0,R1
    if(s[0] == 'R') firstNum = 1;
    int leftNum = firstNum;

    for(int i = 1; i < n; i++)
    {
      if(leftNum == 0 && s[i] == 'L' || leftNum == 1 && s[i] == 'R') answer++;
      else
      {
        if(k > 0)
        {
          k--;
          answer++;
        }
        leftNum = 1-leftNum;
      }
    }

		Console.WriteLine(answer);
	}
}

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

int a, b;
int main(){
	scanf("%d%d",&a,&b);
	if(a < 1 || a > 9) printf("-1");
	else if(b < 1 || b > 9) printf("-1");
	else printf("%d",a*b);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c,d;
	int n=1;
	scanf("%d %d", &a, &b);
	d = b;
	while (d >= 10) {
		n++;
		d /= 10;
	}
	while (n >= 1) {
		a *= 10;
		n--;
	}
	c = a + b;
	
	int t = 0;
	int i = 3;
	while (i*i <= c) {
		i++;
		if (c == i * i) {
			printf("Yes");
			t++;
			break;
		}
	}
	if (t == 0) printf("No");
return 0;
}

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

int main(){
    int n;
    cin >>n;
    int a[n];
    vector<bool> b(n, false);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int now = 0, ans=0;
    while(now!=1){
        ans++;
        now = a[now]-1;
        if(!b[now]) b[now]=true;
        else break;
    }
    if(now==1) cout << ans << endl;
    else cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 640
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();

    let mut ans = 1usize << 60;
    for i in 1..=h - 1 {
        let j = h - i;
        let s1 = w * i;
        if j > 1 {
            let s2 = j / 2 * w;
            let s3 = (j + 1) / 2 * w;
            ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
        }
        let s2 = w / 2 * j;
        let s3 = (w + 1) / 2 * j;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
    }
    for i in 1..=w - 1 {
        let j = w - i;
        let s1 = h * i;
        if j > 1 {
            let s2 = j / 2 * h;
            let s3 = (j + 1) / 2 * h;
            ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
        }
        let s2 = h / 2 * j;
        let s3 = (h + 1) / 2 * j;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
    }
    println!("{}", ans);
}


Measured memory_bytes: 2072
import java.util.*;

// import 
class Main {


    static int min(int a,int b)
    {
        return Math.min(a, b);
    }

    static int abs(int a)
    {
        return Math.abs(a);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        
        Integer arr[] = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
        
        int dp[] = new int[n+1];
        // int mod = 100000000+7;
        Arrays.fill(dp, Integer.MAX_VALUE); //fill large values in dp 
        dp[0] = 0;
        for (int i = 0; i < n; i++) 
        {
            if(i+1 < n )
                dp[i+1] =  min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
            if (i + 2 < n)
                dp[i + 2] = min(dp[i + 2], dp[i] + abs(arr[i] - arr[i+2]));

        }
        // System.out.println(Arrays.toString(dp));
        System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 50008
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
int binomialCoeff(int n, int k) 
{ 
	int C[n + 1][k + 1]; 
	int i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = C[i - 1][j - 1] + 
						C[i - 1][j]; 
		} 
	} 

	return C[n][k]; 
}
 
void solve()
{
	ll  n ; 
	cin>>n ;
// 	cout<<n<<endl;
	ll divi[10000001]={0} ;
	divi[0] = 0 ;
	for (int i = 1 ;  i<=10000000;i++){
		for(int j = i ; j<=10000000;j+=i){
			divi[j]++;
		}
	}
	ll ans= 0 ;
	for(ll i = 1 ; i<=n;i++){
		ans += i*divi[i];
	}
	cout<<ans<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  vector< int > V(5);
  cin >> V;
  for(int i = 0; i < 5; i++) {
    if(V[i] == 0) {
      cout << i + 1 << endl;
    }
  }
}




Measured memory_bytes: 3596
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		if(n>=2 && m>=2){
			System.out.println(n*m-(2*n+2*m-4));
		}else{
			if(n==1 && m==1){
				System.out.println(1);
			}else{
				int max=Math.max((int)n,(int)m);
				System.out.println(max-2);
			}
		}
	}
}



Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main()
{
    Hello
    int a, b;
    cin >> a >> b;
    if(a != 1 && b != 1)
        cout << 1;
    else if(a != 2 && b != 2)
        cout << 2;
    else
        cout << 3;
    return 0;
}

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

int a[5];
int k;
bool flag;

int main(){
	for (int i = 0; i < 5; i++){cin >> a[i];}
	cin >> k;
	
	flag = false;
	for (int i = 0; i < 5; i++){
		for (int j = 0; j < i; j++){
			if ((a[i] - a[j]) > k) {
				flag = true;
				i = 5; break;
			}
		}
	}
	if (flag) cout << ":(";
	else cout << "Yay!";
}

Measured memory_bytes: 256