akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int sum = 0;
        for(int i = 0; i < m; i++){
            sum += Integer.parseInt(sc.next());
        }
        
        if(n >= sum){
            System.out.println(n - sum);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 35192
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	while(cin>>n && n!=0){
		map<int,int> mp;
		rep(i,0,n){
			int a;
			cin>>a;
			mp[a]++;
		}
		int MAX=0,ans=-1;
		for(auto it=mp.begin();it!=mp.end();it++){
			if(it->second>MAX){
				MAX=it->second;
				ans=it->first;
			}
		}
		if(MAX>n/2) o(ans);
		else o("NO COLOR");
	}
}

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

int main(){
    long long n; cin >> n;
    cout << n << ":";
    for(int i = 2; i*i <= n; i++){
        while(n % i == 0){
            cout << " " << i;
            n /= i;
        }
    }
    if(n != 1) cout << " " << n; 
    cout << endl;
} 


Measured memory_bytes: 3096
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

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

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io

  int n;cin>>n;
  ll A[n];
  rep(i,n){
    cin>>A[i];
  }

  ll P[(int)1e6+3];
  rep(i,(int)1e6+1){
    P[i] = 0;
  }
  rep(i,n){
    ll a = A[i];
    ll memo = 0;
    ll count = 0;
    reps(p, sqrt(A[i]) + 3){
      if(p==1) continue;
      if(a%p == 0){
        a /= p;
        if(memo == p){
          count++;
        }else{
          chmax(P[memo], count);
          count = 1;
          memo = p;
        }
        p--;
      }
    }
    if(count > 0){
      chmax(P[memo], count);
    }
    if(a > 1){
      chmax(P[a], 1);
    }
  }

  ll lca = 1;
  ll sum = 0;
  reps(i,(ll)1e6){
    if(P[i] > 0){
      lca *= i;
      lca %= MOD;
      P[i]--;
      i--;
    }
  }
 
  rep(i,n){
    ll a = A[i];
    sum += lca * mpow(a, MOD-2) % MOD;
    sum %= MOD;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 100;
ll v[N];
int n,m;
ll gcd(ll a, ll b) {
    while(b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b) {
    if(a > b) swap(a, b);
    return a * (b / gcd(a, b));
}
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    ll l = v[0] / 2;
    bool ok = true;
    for(int i = 1; i < n; ++i) {
        l = lcm(l, v[i] / 2);
        if(l < 0) {
            ok = false;
        }
    }
    if(!ok or l > m) {
        puts("0");
        return 0;
    }
    for(int i = 0; i < n; ++i) {
        ll d = l / (v[i] / 2);
        if(d % 2 == 0) {
            ok = false;
            break;
        }
    }
    if(!ok) {
        puts("0");
    } else {
        ll tot = m / l;
        ll ans = (tot + 1) / 2;
        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
#define debug(x) cerr << #x << " = " << x << endl

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vi c(n, inf);
    c[n-1] = 0;
    for(int i = n-2; i >= 0; i--){
        for(int j = i+1; j <= i+k && j < n; j++)
        c[i] = min(c[i], c[j] + abs(a[i]-a[j]));
    }
    cout << c[0] << "\n";
}

Measured memory_bytes: 1024
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll sumrev[ohara], odd[ohara], even[ohara];

bool check(ll ind, ll x) {
  ll takahasi = n - 1 - ind, aoki;
  ll le = 0, ri = ind, mid;
  ll kage = x - (a[ind] - x);
  while (ri - le > 1) {
    mid = (le + ri) / 2;
    if (a[mid] < kage)
      le = mid;
    else
      ri = mid;
  }
  rrep(i, max(le - 2, 0LL), min(ri + 3, n)) {
    if (a[i] >= kage) {
      aoki = ind - i + 1;
      tmp = ind - takahasi + 1;
      break;
    }
  }
  // if (a[ind] == 11) Cout(aoki);
  // Cout(a[ind]);
  if (aoki > takahasi)
    return false;
  else
    return true;
}

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

  cin >> n >> q;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    sumrev[i] = a[i];
    if (i % 2 == 0)
      even[i] = a[i];
    else
      odd[i] = a[i];
  }
  rrrep(i, n - 2, 0) sumrev[i] += sumrev[i + 1];
  rrep(i, 1, n) even[i] += even[i - 1], odd[i] += odd[i - 1];
  rep(i, q) {
    cin >> x;
    ll le = 0, ri = n - 1, mid;
    while (ri - le > 1) {
      mid = (le + ri) / 2;
      if (a[mid] > x)
        ri = mid;
      else
        le = mid;
    }
    tmp = n - 1;
    rrep(j, max(le - 2, 0LL), min(ri + 3, n)) {
      if (a[j] > x) {
        tmp = j;
        break;
      }
    }

    if (tmp == n - 1) {
      if (tmp % 2 == 0)
        Cout(even[tmp]);
      else
        Cout(odd[tmp]);
    } else {
      le = tmp, ri = n - 1, mid;
      while (ri - le > 1) {
        mid = (le + ri) / 2;
        if (check(mid, x))
          le = mid;
        else
          ri = mid;
      }
      rrrep(j, min(ri + 2, n - 1), max(le - 2, 0LL)) {
        if (check(j, x)) {
          ans = sumrev[j + 1];
          // Cout(j);
          tmp--;
          if (tmp >= 0) {
            if (tmp % 2 == 0)
              ans += even[tmp];
            else
              ans += odd[tmp];
          }
          break;
        }
      }
      Cout(ans);
    }
  }
  return 0;
}

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

using namespace std;

#define min(a,b) ((a<b)?a:b)

int main(void){
    int n,m,i,j,from,to;
    long long int a,b,c,t[100001],ans=0LL,add;
    scanf("%d%d",&n,&m);
    fill(t,t+n,0LL);
    n--;
    scanf("%d",&from);
    t[0]=0;
    for(i=1; i<m; i++){
        scanf("%d",&to);
        if(from<to){
            t[from]++;
            t[to]--;
        }else{
            t[to]++;
            t[from]--;
        }
        from = to;
    }
    for(i=1; i<=n; i++){
        t[i]+=t[i-1];
        scanf("%lld%lld%lld",&a,&b,&c);
        add=min(a*t[i],b*t[i]+c);
        ans+=add;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1972
N, M = map(int, input().split())

H = [None] + list(map(int, input().split()))

good = [None] + [True for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    if H[a] == H[b]:
        good[a] = False
        good[b] = False
    elif H[a] < H[b]:
        good[a] = False
    else:
        good[b] = False


ans = 0
for i in range(1, N + 1):
    if good[i]:
        ans += 1
print(ans)


Measured memory_bytes: 20120
x = int(input())
y = 0
if x==1 or x==2 or x==3:
    print(1)
    exit()
else:
    for a in range(2,(x+1)):
        for b in range (2,10):
            if b==2 and a**b>x:
                print(y)
                exit()
            elif a**b<=x:
                y=max(a**b,y)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,M,cnt=1,r=1;
  cin>>N>>M;
  set<ll> s;
  s.insert(1);
  vector<ll> v(N,1);
  for(ll i=0;i<M;i++){
    int x,y;
    cin>>x>>y;
    if(s.count(x)) s.insert(y);
    v[x-1]--;
    v[y-1]++;
    if(v[x-1]==0) s.erase(x);
  }
  cout<<s.size()<<endl;
}


Measured memory_bytes: 5760
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
sys.setrecursionlimit(150000)

N, M, X = map(int, sys.stdin.readline().split())
a = []
for i in range(N):
    a.append(inpl())
b = [0] * M
res = float("INF")
def dfs(cost, start, tmp):
    global res
    if min(tmp) >= X:
        res = min(res, cost)
        return res
    for i in range(start, N):
        c = tmp.copy()
        d = [i + j for i, j in zip(c, a[i][1:])]
        dfs(cost + a[i][0], i + 1, d)
    return res

ans = dfs(0,0,b)
if ans != float("INF"):
    print(ans)
else:
    print(-1)

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int S = accumulate(L.begin(), L.end() - 1, 0);
    if (S > L[N - 1]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>

typedef long long ll;

using namespace std;
int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int> > a;
    for (int i=0; i<h; ++i){
        vector<int> ind(w);
        for (int j=0; j<w; ++j)cin >>ind[j];
        a.push_back(ind);
    }
    vector<vector<int> > ret;
    for (int i=0; i<h-1; ++i){
        for (int j=0; j<w; ++j){
            if(a[i][j]%2 != 0){
                a[i][j] -=1;
                a[i+1][j] +=1;
                ret.push_back({i,j,i+1,j});
            }
        }
    }
    int i=h-1;
    for (int j=0; j<w-1; ++j){
        if(a[i][j]%2 != 0){
            a[i][j] -=1;
            a[i][j+1] +=1;
            ret.push_back({i,j,i,j+1});
        }
    }
    cout << ret.size()<<endl;
    for(auto it = ret.begin(); it!=ret.end(); ++it){
        cout << (*it)[0]+1 <<" "<< (*it)[1]+1 <<" "<< (*it)[2]+1 <<" "<<(*it)[3]+1 <<endl;;
    }
    return 0;
}


Measured memory_bytes: 9904
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define mod1 1000000009
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll   mx=200009;
ll  ara[mx];
int  main()
{
    ll  n;
    cin>>n;
    for(ll  i=0;i<n;i++) cin>>ara[i];
    sort(ara,ara+n);
    if(n%2) cout<<"0"<<endl;
    else
    {
        ll  ind=n/2;
        if(ara[ind]==ara[ind-1]) cout<<0<<endl;
        else cout<<ara[ind]-ara[ind-1]<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+10;
long long memo[MAXN];

int main(){
	int n, vi;
	long long wi, W;
	scanf("%d %lld", &n, &W);
	for (int i = 0; i < MAXN; i++)
		memo[i] = 1e15+7;
	vector<pair<int, long long>> vet;
	for (int i = 0; i < n; i++){
		scanf("%lld %d", &wi, &vi);
		vet.push_back({vi, wi});
	}
	sort(vet.begin(), vet.end());

	memo[0] = 0;
	for (int k = 0; k < vet.size(); k++){
		for (int j = MAXN-1 - vet[k].first; j >= 0; j--){
			memo[j + vet[k].first] = min(memo[j + vet[k].first], vet[k].second + memo[j]);
		}
	}
	//cout << "--> " << memo[17] << endl;
	for (int j = MAXN-1; j >= 0; j--){
		if (memo[j] <= W){
			printf("%d\n", j);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 4548
#include <iostream>

using namespace std;
#define MAX 100000
#define DEGREE 20

class TreeNode
{
public:
	int Parent()
	{
		if (!parent) return -1;
		else return parent->id;
	}

	int Depth()
	{
		int depth = 0;
		TreeNode* current = parent;
		while (current)
		{
			++depth;
			current = current->parent;
		}

		return depth;
	}

	const char* NodeType()
	{
		if (!parent) return "root";
		else if (degree == 0) return "leaf";
		else return "internal node";
	}

public:
	int id;
	TreeNode* parent;
	int degree;
	TreeNode** nodes;
};

TreeNode Nodes[MAX];

int main()
{
	int n; cin >> n;
	
	int id;
	for (int i = 0; i < n; ++i)
	{
		cin >> id;
		Nodes[id].id = id;
		cin >> Nodes[id].degree;
		Nodes[id].nodes = new TreeNode*[Nodes[id].degree];

		int childid;
		for (int j = 0; j < Nodes[id].degree; ++j)
		{
			cin >> childid;
			Nodes[id].nodes[j] = &Nodes[childid];
			Nodes[childid].parent = &Nodes[id];
		}
	}

	for (int i = 0; i < n; ++i)
	{
		cout << "node " << Nodes[i].id;
		cout << ": parent = " << Nodes[i].Parent();
		cout << ", depth = " << Nodes[i].Depth();
		cout << ", " << Nodes[i].NodeType() << ", [";
		for (int j = 0; j < Nodes[i].degree; ++j)
			cout << Nodes[i].nodes[j]->id << (j != Nodes[i].degree - 1 ? ", " : "");
		cout << "]" << endl;
	}
	return 0;
}


Measured memory_bytes: 10088
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 n: usize = itr.next().unwrap().parse().unwrap();
    let _: usize = itr.next().unwrap().parse().unwrap();
    let mut s: Vec<&str> = (0..n).map(|_| itr.next().unwrap()).collect();
    s.sort();
    let mut ans: String = "".to_string();
    for i in 0..n {
        ans += s[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import itertools
import math

N = int(input())
pl = itertools.permutations([i for i in range(N)])
xy = [list(map(int, input().split())) for _ in range(N)]
s = 0
for l in pl:
    for i in range(N - 1):
        xi, yi = xy[l[i]]
        xj, yj = xy[l[i + 1]]
        s += ((xi - xj)**2 + (yi - yj)**2)**0.5
print(s / math.factorial(N))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int HashUpperCnt[27];
int HashLowerCnt[27];

int main()
{
    char str;
    char begin = 'a';
    
    while (cin >> str)
    {
        if (islower(str))
        {
            HashLowerCnt[str - 'a']++;
        }
        else if (isupper(str))
        {
            HashUpperCnt[str - 'A']++;
        }
    }
    
    for (int i = 0; i < 26; i++)
    {
        cout << begin << " : " << HashUpperCnt[i] + HashLowerCnt[i] << endl;
        begin++;
    }
    
    return 0;
}



Measured memory_bytes: 3080
N,M = map(int,input().split())
listH = list(map(int,input().split()))
LofS = [set() for i in range(N) ]
for i in range(M):
  a,b=map(int,input().split())
  LofS[a-1].add(b)
  LofS[b-1].add(a)
listMax = []
for i in range(N):
   listMax.append( max( [ listH[j-1] for j in LofS[i] ] , default=0) )
count = 0
for i in range(N):
  if listH[i] > listMax[i]:
    count += 1
print(count)


Measured memory_bytes: 45924
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int x; cin>>x;
  vector<int> dp(110010, 0);
  dp[0] = 1;
  rep(i, 100000) if (dp[i] == 1) {
    rep(j, 6) dp[i+100+j] = 1;
  }
  print(dp[x]);

  return 0;
}

Measured memory_bytes: 640
H, W, d = map(int, input().split())

if d % 2 != 0:
    unit = ['BY', 'YB']
    size = 2

else:
    colors = 'RYGB'
    temp = [['' for j in range(2 * d)] for i in range(2 * d)]

    d2 = d // 2
    origin = [(-d, -2 * d), (-d, -d), (-d2, -3 * d2), (-d2, -d2)]
    offset = [(0, 0), (d, d)]

    for color, (r, c) in zip(colors, origin):
        for dr, dc in offset:
            for j in range(d2):
                for i in range(-j, j + 1):
                    temp[r + dr + i][c + dc + j] = color
                    temp[r + dr + i][c + dc + d - 1 - j] = color

    unit = [''.join(temp[i]) for i in range(2 * d)]
    size = 2 * d

for i in range(H):
    print(unit[i % size] * (W // size) + unit[i % size][:(W % size)])


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

const int mxn = 21;
int dp[mxn + 1][1 << mxn], a[mxn][mxn];

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

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j];
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (a[i][j]) for (int mask = 0; mask < 1 << n; ++mask) if (!(mask & (1 << j))) {
        dp[i + 1][mask | (1 << j)] += dp[i][mask];
        dp[i + 1][mask | (1 << j)] %= 1000000007;
    }
    cout << dp[n][(1 << n) - 1] << endl;
}

Measured memory_bytes: 175676
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }

    bool ok = true;
    for(int i=0; i<n/2; i++){
        if(s[i] != s[i+n/2]) ok = false;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    int n;
    std::cin >> n;
    rep(i,50000){
        if(int(1.08*i)==n){
            std::cout << i << std::endl;
            exit(0);
        }
    }
    std::cout << ":(" << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const ll INF = 1001001001;
struct UnionFind
{
    vector<ll> par;
    vector<ll> siz;
    UnionFind(ll n) : par(n), siz(n, 1)
    {
        rep(i, n) par[i] = i;
    }
    void init(ll n)
    {
        par.resize(n);
        siz.assign(n, 1LL);
        for (ll i = 0; i < n; ++i)
            par[i] = i;
    }
    ll root(ll x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry)
            return;
        if (siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(ll x, ll y)
    {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
    ll size(ll x)
    {
        return siz[root(x)];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    UnionFind tree(n);
    rep(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
    }
    vector<bool> ex(n);
    rep(i, n)
    {
        ex[tree.root(i)] = true;
    }
    ll ans = 0;
    rep(i, n)
    {
        if (ex[i])
        {
            ans++;
        }
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 4792
from itertools import combinations
n,d = map(int,input().split())
l = []
ans = 0

for i in range(n):
    l.append(list(map(int,input().split())))
for a,b in combinations(l,2):
    if (sum((a[i]-b[i])**2 for i in range(d)))**(1/2) % 1 == 0:
        ans += 1

print(ans)




Measured memory_bytes: 3060
#include <cstdio>//untested
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 53

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool flag;
char ch,s[N],t[N];
int n,m,mx;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	scanf("%s\n%s",s+1,t+1);
	n=strlen(s+1),m=strlen(t+1);
	rrp(i,n,1)
	{
		flag=true;
		rep(j,1,m)
			if(s[i+j-1]!=t[j]&&s[i+j-1]!='?'){flag=false;break;}
		if(flag){mx=i;break;}
	}
	if(mx)
	{
		rsp(i,1,mx)if(s[i]=='?')putchar('a');else putchar(s[i]);
		printf("%s",t+1);
		rep(i,mx+m,n)if(s[i]=='?')putchar('a');else putchar(s[i]);
	}
	else printf("UNRESTORABLE");
	return 0;
}


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

using namespace std;
typedef long long ll;
int n,avail[100003];
ll fw[100003],fb[100003],mod=1e9+7;
vector<int>g[100003];

void DFS(int u)
{
    avail[u]=1;
    for(int i=0;i<g[u].size();++i)
    {
        int v=g[u][i];
        if(avail[v]==0)
        {
            DFS(v);
            fw[u]=(fw[u]*(fw[v]+fb[v]))%mod;
            fb[u]=(fb[u]*fw[v])%mod;
        }
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;++i)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v),g[v].push_back(u);
    }
    for(int i=1;i<=n;++i)
    {
        fw[i]=fb[i]=1;
    }
    DFS(1);
    cout<<((fw[1]+fb[1])%mod);
    return 0;
}


Measured memory_bytes: 11776
n=int(input())
a=sorted(list(map(int,input().split())))

r=0
l=0
ans=0
while r<n:
    if a[r]-a[l]<=2:
        if r-l+1>ans:
            ans=r-l+1
        r+=1
    else:
        l+=1
print(ans)

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll grid[1010][1010];

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll H, W;
  scanf("%lld %lld", &H, &W);

  for (ll y = 0; y < H; y++) {
    string s;
    cin >> s;
    for (ll x = 0; x < W; x++) {
      ll v;
      if (s[x] == '#') {
        v = -1;  // 壁
      } else {
        v = 0;
      }
      grid[y][x] = v;
    }
  }
  grid[0][0] = 1;

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      if (grid[y][x] == -1) {
        continue;
      }

      if (grid[y][x + 1] >= 0) {
        grid[y][x + 1] += grid[y][x];
        grid[y][x + 1] %= MOD;
      }
      if (grid[y + 1][x] >= 0) {
        grid[y + 1][x] += grid[y][x];
        grid[y + 1][x] %= MOD;
      }
    }
  }

  cout << (grid[H - 1][W - 1]) << endl;
}


Measured memory_bytes: 11536
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(ll base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	cout << fixed << setprecision(2);
}

int main(){
	//Qalbaz();	
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	int x, sum, ans = 0;
	for (int i = 1; i <= n; i++)
	{
		x = i;
		sum = 0;
		while (x)
		{
			sum += x % 10;
			x /= 10;
		}
		if (sum >= a && sum <= b)
			ans += i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var s = vals[0];
        var w = vals[1];

        if (w >= s)
        {
            Console.WriteLine("unsafe");
        }
        else
        {
            Console.WriteLine("safe");
        }
    }
}

Measured memory_bytes: 28300
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>

using std::sort;
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
const int N = 100010;
int _w;

int n, a[N];
ll s[N];

ll calc( ll x ) {
	x *= 2;
	int low = 1, high = n;
	while( low < high ) {
		int mid = (low + high + 1)/2;
		if( a[mid] <= x ) low = mid;
		else high = mid-1;
	}
	return s[low];
}

bool check( ll x ) {
	ll last = x;
	while( x != s[n] ) {
		x = calc(x);
		if( last == x ) return false;
		last = x;
	}
	return true;
}

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i )
		cin >> a[i];
	sort(a+1, a+n+1);
	for( int i = 1; i <= n; ++i )
		s[i] = s[i-1] + a[i];
	int ans = 0;
	for( int i = 1; i <= n; ++i )
		ans += check( a[i] );
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}

bool check(string s,string t,string full,int n){
	if(full.substr(0,n)!=s){
		return false;
	}
	for(int i=0;i<full.size()-n+1;i++){
		if(full.substr(i,i+n)==t){
			return true;
		}
	}
	return false;
}
int main(){
  fastIO();
  int n;
  string s,t;
  cin>>n>>s>>t;
  string ori = s+t;
  int deletion = n-1;
  int best = n*2;
  while(deletion>=0){
  	ori.erase(ori.begin()+deletion);
  	if(check(s,t,ori,n)){
  	   int x = ori.length();
  	   best=min(best,x);
  	}
  	deletion--;
  }
  cout<<best<<endl;
}  



Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
b = readInts()

d = deque()

def renzoku(arr):
	i = -1
	boo = 1
	for i in range(1,len(arr)+1):
		#print(arr[len(arr)-i],len(arr)-i+1)
		if arr[len(arr)-i] == len(arr)-i+1:
			boo = 0
			break
	if boo:
		print(-1)
		exit()
	#print("return :",len(arr)-i)
	return len(arr)-i


for i in range(len(b)):
	r = renzoku(b)
	#print(b)
	#print(b[r])
	d.append(r)
	del b[r]

for i in reversed(d):
	print(i+1)

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main()
{
  int n; cin >> n;
  vi a(n+1); rep(i,n) cin >> a[i+1];

  rep(i,n) a[i+1] += a[i];

  map<int,int> mp;
  rep(i,n+1) mp[a[i]]++;

  int ans = 0;
  for(x : mp){
    if(x.snd > 1) ans += x.snd * (x.snd - 1) / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 14336
S = input()
S_int = map(int, S)

if len(S) == 1:
    print(0)
else:
    s = list(S_int)
    def reverse_count(s, initial):
        count = 0
        c = initial
        for i in range(len(s)):
            if s[i] != c:
                count += 1
            c = (c + 1) % 2
        return count
        
    ### 0スタートと1スタートの場合両方で少ない方を出力
    print(min(reverse_count(s, 0), reverse_count(s, 1)))

Measured memory_bytes: 3956
import java.util.*;

public class Main {

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int[] A = new int[M];
        int[] B = new int[M];

        for (int i = 0 ; i < M ; i++) {
            A[i] = scanner.nextInt() - 1;
            B[i] = scanner.nextInt() - 1;
        }

        UnionFindTree uft = new UnionFindTree(N);

        for (int i = 0 ; i < M ; i++) {
            uft.union(A[i], B[i]);
        }

        Set<Integer> roots = new HashSet<>();
        for (int i = 0 ; i < N ; i++) {
            roots.add(uft.find(i));
        }

        System.out.println(roots.size() - 1);
    }

    static class UnionFindTree {
        int[] parent;

        public UnionFindTree(int n) {
            parent = new int[n];
            for (int i = 0 ; i < n ; i++) {
                parent[i] = i;
            }
        }

        public int find(int x) {
            if (parent[x] == x) {
                return x;
            } else {
                parent[x] = find(parent[x]);
                return parent[x];
            }
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

        public void union(int x, int y) {
            int rx = find(x);
            int ry = find(y);
            if (rx != ry) {
                parent[rx] = ry;
            }
        }
    }
}


Measured memory_bytes: 59784
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    char a,b;
    cin>>a>>b;
    if(a==b)cout<<"H"<<endl;
    else cout<<"D"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<cstdio>
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
/*
inline int read(){
	int res=0; char ch=getchar_unlocked();
	while(ch<'0'||ch>'9') ch=getchar_unlocked();
	while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch^48),ch=getchar_unlocked();
	return res;
}
*/
#define int long long
#define mp make_pair
#define pb push_back
#define S second
#define F first
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IOS ios::sync_with_stdio(false),cin.tie(0);
#define pii pair<int,int>
#define endl cout<<'\n';
#define LINE cout << "-----------------------\n";
using namespace std;
const int maxn = 1e6+5;

signed main(){
	IOS;
	int x , y; cin >> x >> y;
	for(int i=0 ; i<=x ; ++i){
		if(2*i + (x-i)*4 == y || 2*(x-i)+4*i == y) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
new_a = sorted(a)
max_a = max(new_a)
cheak = a.index(max_a)
for i in range(n):
    if i != cheak:
        print(max_a)
    else:
        print(new_a[n-2])

Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a,b,s2;
  cin >> a >> b;
  s2 = a * b;
  if((a * b) % 2 == 0){
      cout << "Even" << endl;
  }else{
      cout << "Odd" << endl;
  }
  
}

Measured memory_bytes: 256
while 1:
    H,W = map(int,raw_input().split())
    if H == 0: break
    A = [raw_input() for i in range(H)]
    S = [[[0,0] for j in range(W)] for i in range(H)]
    ans = 0
    for h in range(H):
    	L = 0
        for w in range(W):
            if A[h][w] == ".":
                L += 1
            else:
                L = 0
            S[h][w][0] = L
            try: S[h][w][1] = S[h-1][w][1] + 1 if L > 0 else 0
            except: S[h][w][1] = 1 if L > 0 else 0
            if L*S[h][w][1] > ans:
                a = L
                for hi in range(1,S[h][w][1]):
                    a = min(a,S[h-hi][w][0])
                    ans = max(ans,a*(hi+1))
                    if a*S[h][w][1] < ans:
                    	break
    print ans

Measured memory_bytes: 60480
s = ["+","-"]
t = input()
a = ""
from itertools import product
for v in product(s,repeat = 3):
    a = t[0] + v[0] + t[1] + v[1] + t[2] + v[2] + t[3]
    if eval(a) == 7:
        break
print(a + "=7")

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

int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int i=1,counter{0},flag = 0;
    while(n--)
    {
        i = arr[i-1];
        counter++;
        if(i == 2)
        {
            flag = 1;
            break;
        }
    }
    if(flag == 1)
        cout<<counter<<endl;
    else
    {
        cout<<"-1"<<endl;
    }
    
    return 0;
}

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

int main() {
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> d[i];
  
  int num[110] = {0};
  for (int i = 0; i< N; i++) {
  	num[d[i]]++;
  }
  
  int res = 0;
  for (int i = 1; i <= 100; i++){
  	if (num[i]) {
    	res++;
    }
  }
  cout << res << endl;
}

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


struct node {
    node* zero;
    node* one;
    bool flag;
};
node* get()
{
    node* n = (node*)malloc(sizeof(node));
    n->zero = nullptr;
    n->one = nullptr;
    n->flag = false;
    return n;
}

string s[100005];
void advance(node* r, int n, int idx)
{
    //cout << n << " " << idx << " " << s[n][idx] << endl;
    if (s[n].size() == idx) {
        r->flag = true;
        return;
    }
    if (s[n][idx] == '0') {
        if (r->zero == nullptr) {
            r->zero = get();
        }
        advance(r->zero, n, idx + 1);
    } else if (s[n][idx] == '1') {
        if (r->one == nullptr) {
            r->one = get();
        }
        advance(r->one, n, idx + 1);
    }
}

int x = 0;
lli l = 0;
int g[100005] = {};
int cnt = 0;
void dfs(node* r, lli depth)
{
    if (r->flag)
        return;
    if (!(r->flag) and ((r->zero) == nullptr or (r->one) == nullptr)) {
        lli tmp = l - depth;
        lli cnt = 0;
        while (tmp % 2 == 0) {
            cnt++;
            tmp /= 2;
        }
        x ^= (1 << cnt);
    }
    if (r->zero != nullptr) {
        dfs(r->zero, depth + 1);
    }
    if (r->one != nullptr) {
        dfs(r->one, depth + 1);
    }
}
int main()
{
    int n;
    cin >> n;
    cin >> l;
    int l;
    node* root = get();
    rep(i, n)
    {
        cin >> s[i];
        advance(root, i, 0);
    }

    dfs(root, 0);
    if (x == 0) {
        cout << "Bob" << endl;
    } else {
        cout << "Alice" << endl;
    }
}


Measured memory_bytes: 5888
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m2 == m1 + 1)
        cout << "1";
    else
        cout << "0";
    cout << endl;
    return 0;
};

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

using namespace std;

const int MOD = 998244353;

int main()
{
  int n;
  int sum = 0;
  
  cin >> n;
  int value[n];
  for (int i=0;i<n;++i) {
    cin >> value[i];
    sum += value[i];
  }
  
  // すべてのパターン数
  long long all = 1;
  for (int i=0;i<n;i++) {
    all = (all * 3) % MOD;
  }
  
  int dp1[sum+1];
  int dp2[sum+1];
  dp1[0] = 1;
  dp2[0] = 1;
  for (int i=1;i<=sum;++i) {
    dp1[i] = 0;
    dp2[i] = 0;
  }

  for (int i=0;i<n;++i) {
    int cur = value[i];
    for (int j=sum;j>=0;--j) {
      // 今回選ばれないパターン
      dp1[j] = (2*dp1[j]) % MOD; //3色塗り分け
      dp2[j] = dp2[j] % MOD; //2色塗り分け
      // 今回選ばれたパターン
      if (j >= cur) {
        dp1[j] = (dp1[j] + dp1[j-cur]) % MOD;
        dp2[j] = (dp2[j] + dp2[j-cur]) % MOD;
      }
    }
  }
  
  int m = (sum+1)/2;

  // R|G|B >= m のパターン
  long long p1 = 0;
  for (int i=m;i<=sum;++i) {
    p1 = (p1 + dp1[i]) % MOD;
  }
  p1 = (3 * p1) % MOD;
  
  // R|G|B のうち２つがm、残りが0のパターン
  long long p2 = 0;
  if (sum%2 == 0) // 奇数の時は該当パターン数0
    p2 = dp2[m] % MOD;
  p2 = (3 * p2) % MOD;
  
  // R&G&B がtotal/2のパターン（無い）
  long long p3 = 0;
  
  long long answer = all - p1 + p2 - p3;
  while (answer < 0) {
    answer += MOD;
  }
  answer %= MOD;
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int mod = 1e9 + 7;
int32_t main() {

    fast
    int x;
    cin >> x;

    if(x % 2 == 0)cout << -1 << endl;
    else {
        int ans = 1;
        int k = 7;
        while(k % x != 0 && ans <= x) {
            k = k * 10;
            k += 7;
            k %= x;
            ans++;
        }
        if(k % x != 0)cout << -1 << endl;
        else
            cout << ans << endl;

    }


    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll lft[200005] , rgt[200005] , n , a[200005];
ll dp[200005][32];
const ll inf = 1e15;
ll solve(ll id ,ll x)
{
        if(x >= 17) return inf;
        if(id == n + 1) {
                return 0;
        }
        if(dp[id][x] != -1) return dp[id][x];
        ll mup = 1LL;
        for(ll i=0;i<x;i++) mup = mup*4;
        mup = mup * a[id-1];
        ll cnt = 0;
        ll cur = a[id];
        while(mup > cur) {
                cur = cur * 4; cnt++;
                //if(cnt >= 16) return dp[id][x] = solve(id+1, 15) + cnt + (cnt-15)*(n-id);
        }
        if(cnt <= 15){
        return dp[id][x] = solve(id+1, cnt) + cnt;

        }else {
                return dp[id][x] = solve(id+1, 15) + cnt + (cnt-15)*(n-id);
        }
}
ll ans[200005];
ll ans2[200005];
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) cin >> a[i];
        for(ll i=2;i<=n;i++) {
                lft[i] = 0;
                ll cnt = 0;
                ll x = a[i];
                ll y = a[i-1];
                while(x < y) {
                        x = x*4;
                        cnt++;
                }
                lft[i] = cnt + cnt;
                //cout << i << " " << lft[i] << endl;
        }
        for(ll i = n-1; i>=1;i--) {

                rgt[i] =0;
                ll x = a[i] * 2;
                ll y = a[i+1];
                ll cnt = 0;
                while(x < y) {
                        x = x * 4;
                        cnt++;
                }
                rgt[i] = cnt + cnt + 1;
                //cout << i << " " << rgt[i] << endl;
        }
        memset(dp,-1,sizeof dp);
        for(ll i=2;i<=n;i++) {
                for(ll j=0;j<=15;j++) {
                        ll  y= solve(i, j);
                        if(j==0) ans[i] = y + y;
                }
        }
        //for(ll i=2;i<=n;i++) cout << i << " --- " << ans[i] << "\n";
        for(ll i=1;i<=n;i++) a[i] = a[i] * 2;
        memset(dp,-1,sizeof dp);
        reverse(a+1, a+n+1);
        //for(ll i=1;i<=n;i++) cout << a[i] << " "; cout << endl;
        for(ll i=2;i<=n;i++) {
                for(ll j=0;j<=15;j++) {
                        //ll xx = a[i] * 2;
                        //ll ct = 0;
                        //while
                        ll y = solve(i + 1,j);
                        if(j==0){
                                //cout << y + y << " ";
                                ans2[i] += y + y + (n-i+1);
                        }
                }
        }
        ll ret = 1e14;
        //for(ll i=2;i<=n;i++) cout << i << " ------- " << ans2[i] << endl;
        for(ll i=1;i<=n;i++) {
                ret = min(ret , ans[i + 1] + ans2[n+1-i + 1]);
        }
        cout << ret << endl;
        //for(ll i=1;i<=n;i++) cout << ans[i] << " ";
        return 0;
}


Measured memory_bytes: 67456
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var n=arr.shift()-0;
var a=arr.shift().split(" ").map(Number);
var q=arr.shift()-0;
var s="";
for(var i=0;i<q;i++){
   var [c,b,e]=arr[i].split(" ").map(Number);
   var m = a[b];
   if(c==0){
      for(var j=b;j<e;j++) m=Math.min(m,a[j]);
   }else{
      for(var j=b;j<e;j++) m=Math.max(m,a[j]);
   }
   s+=m+"\n";
}
console.log(s.trim());


Measured memory_bytes: 17404